blob: bcdc58b9d02ee2289fc769469aedd74c1cac2db5 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800661 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
2166 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2167
Tony Barbourf92621a2016-05-02 14:28:12 -06002168 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002169 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002170 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002171 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002172
Tony Barbourf92621a2016-05-02 14:28:12 -06002173 VkImageView dsv;
2174 VkImageViewCreateInfo dsvci = {};
2175 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2176 dsvci.image = image.handle();
2177 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002178 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002179 dsvci.subresourceRange.layerCount = 1;
2180 dsvci.subresourceRange.baseMipLevel = 0;
2181 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Create a view with depth / stencil aspect for image with different usage
2185 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002187 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002188
2189 // Initialize buffer with TRANSFER_DST usage
2190 vk_testing::Buffer buffer;
2191 VkMemoryPropertyFlags reqs = 0;
2192 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2193 VkBufferImageCopy region = {};
2194 region.bufferRowLength = 128;
2195 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002196 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002197 region.imageSubresource.layerCount = 1;
2198 region.imageExtent.height = 16;
2199 region.imageExtent.width = 16;
2200 region.imageExtent.depth = 1;
2201
Mark Lobodzinski80871462017-02-16 10:37:27 -07002202 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Mike Schuchardt17838902017-02-21 09:48:06 -07002392TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2393 TEST_DESCRIPTION(
2394 "Try to destroy a render pass object using a device other than the one it was created on. "
2395 "This should generate a distinct error from the invalid handle error.");
2396 // Create first device and renderpass
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2399
2400 // Create second device
2401 float priorities[] = {1.0f};
2402 VkDeviceQueueCreateInfo queue_info{};
2403 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2404 queue_info.pNext = NULL;
2405 queue_info.flags = 0;
2406 queue_info.queueFamilyIndex = 0;
2407 queue_info.queueCount = 1;
2408 queue_info.pQueuePriorities = &priorities[0];
2409
2410 VkDeviceCreateInfo device_create_info = {};
2411 auto features = m_device->phy().features();
2412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2413 device_create_info.pNext = NULL;
2414 device_create_info.queueCreateInfoCount = 1;
2415 device_create_info.pQueueCreateInfos = &queue_info;
2416 device_create_info.enabledLayerCount = 0;
2417 device_create_info.ppEnabledLayerNames = NULL;
2418 device_create_info.pEnabledFeatures = &features;
2419
2420 VkDevice second_device;
2421 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2422
2423 // Try to destroy the renderpass from the first device using the second device
2424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2425 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2426 m_errorMonitor->VerifyFound();
2427
2428 vkDestroyDevice(second_device, NULL);
2429}
2430
Karl Schultz6addd812016-02-02 17:17:23 -07002431TEST_F(VkLayerTest, PipelineNotBound) {
2432 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002437
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002440
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
2448 ds_pool_ci.maxSets = 1;
2449 ds_pool_ci.poolSizeCount = 1;
2450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451
2452 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454 ASSERT_VK_SUCCESS(err);
2455
2456 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002457 dsl_binding.binding = 0;
2458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2459 dsl_binding.descriptorCount = 1;
2460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002462
2463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2465 ds_layout_ci.pNext = NULL;
2466 ds_layout_ci.bindingCount = 1;
2467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468
2469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 ASSERT_VK_SUCCESS(err);
2472
2473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002477 alloc_info.descriptorPool = ds_pool;
2478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_VK_SUCCESS(err);
2481
2482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2484 pipeline_layout_ci.pNext = NULL;
2485 pipeline_layout_ci.setLayoutCount = 1;
2486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
Mark Youngad779052016-01-06 14:26:04 -07002492 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002493
Tony Barbour552f6c02016-12-21 14:34:07 -07002494 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002498
Chia-I Wuf7458c52015-10-26 21:10:41 +08002499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002502}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002503
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002504TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2505 VkResult err;
2506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002507 TEST_DESCRIPTION(
2508 "Test validation check for an invalid memory type index "
2509 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002510
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
2512
2513 // Create an image, allocate memory, set a bad typeIndex and then try to
2514 // bind it
2515 VkImage image;
2516 VkDeviceMemory mem;
2517 VkMemoryRequirements mem_reqs;
2518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2519 const int32_t tex_width = 32;
2520 const int32_t tex_height = 32;
2521
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = tex_format;
2527 image_create_info.extent.width = tex_width;
2528 image_create_info.extent.height = tex_height;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2535 image_create_info.flags = 0;
2536
2537 VkMemoryAllocateInfo mem_alloc = {};
2538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2539 mem_alloc.pNext = NULL;
2540 mem_alloc.allocationSize = 0;
2541 mem_alloc.memoryTypeIndex = 0;
2542
2543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2544 ASSERT_VK_SUCCESS(err);
2545
2546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2547 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002548
2549 // Introduce Failure, select invalid TypeIndex
2550 VkPhysicalDeviceMemoryProperties memory_info;
2551
2552 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2553 unsigned int i;
2554 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2555 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2556 mem_alloc.memoryTypeIndex = i;
2557 break;
2558 }
2559 }
2560 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002561 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562 vkDestroyImage(m_device->device(), image, NULL);
2563 return;
2564 }
2565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002567
2568 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2569 ASSERT_VK_SUCCESS(err);
2570
2571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2572 (void)err;
2573
2574 m_errorMonitor->VerifyFound();
2575
2576 vkDestroyImage(m_device->device(), image, NULL);
2577 vkFreeMemory(m_device->device(), mem, NULL);
2578}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002579
Karl Schultz6addd812016-02-02 17:17:23 -07002580TEST_F(VkLayerTest, BindInvalidMemory) {
2581 VkResult err;
2582 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
2584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002587 const int32_t tex_width = 256;
2588 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2592 image_create_info.pNext = NULL;
2593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2594 image_create_info.format = tex_format;
2595 image_create_info.extent.width = tex_width;
2596 image_create_info.extent.height = tex_height;
2597 image_create_info.extent.depth = 1;
2598 image_create_info.mipLevels = 1;
2599 image_create_info.arrayLayers = 1;
2600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2603 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 VkBufferCreateInfo buffer_create_info = {};
2606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2607 buffer_create_info.pNext = NULL;
2608 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002609 buffer_create_info.size = 4 * 1024 * 1024;
2610 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002611 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002612
Cortf801b982017-01-17 18:10:21 -08002613 // Create an image/buffer, allocate memory, free it, and then try to bind it
2614 {
2615 VkImage image = VK_NULL_HANDLE;
2616 VkBuffer buffer = VK_NULL_HANDLE;
2617 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2618 ASSERT_VK_SUCCESS(err);
2619 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2620 ASSERT_VK_SUCCESS(err);
2621 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2622 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2623 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Cortf801b982017-01-17 18:10:21 -08002625 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2626 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 image_mem_alloc.allocationSize = image_mem_reqs.size;
2628 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2629 ASSERT_TRUE(pass);
2630 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2636 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2639 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
Cortf801b982017-01-17 18:10:21 -08002641 vkFreeMemory(device(), image_mem, NULL);
2642 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 (void)err; // This may very well return an error.
2647 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2650 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2651 (void)err; // This may very well return an error.
2652 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 vkDestroyImage(m_device->device(), image, NULL);
2655 vkDestroyBuffer(m_device->device(), buffer, NULL);
2656 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002657
2658 // Try to bind memory to an object that already has a memory binding
2659 {
2660 VkImage image = VK_NULL_HANDLE;
2661 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2662 ASSERT_VK_SUCCESS(err);
2663 VkBuffer buffer = VK_NULL_HANDLE;
2664 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2665 ASSERT_VK_SUCCESS(err);
2666 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2667 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2668 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2669 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2670 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2671 image_alloc_info.allocationSize = image_mem_reqs.size;
2672 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2673 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2674 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2675 ASSERT_TRUE(pass);
2676 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2677 ASSERT_TRUE(pass);
2678 VkDeviceMemory image_mem, buffer_mem;
2679 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2680 ASSERT_VK_SUCCESS(err);
2681 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2682 ASSERT_VK_SUCCESS(err);
2683
2684 err = vkBindImageMemory(device(), image, image_mem, 0);
2685 ASSERT_VK_SUCCESS(err);
2686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2687 err = vkBindImageMemory(device(), image, image_mem, 0);
2688 (void)err; // This may very well return an error.
2689 m_errorMonitor->VerifyFound();
2690
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 ASSERT_VK_SUCCESS(err);
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2694 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 vkFreeMemory(device(), image_mem, NULL);
2699 vkFreeMemory(device(), buffer_mem, NULL);
2700 vkDestroyImage(device(), image, NULL);
2701 vkDestroyBuffer(device(), buffer, NULL);
2702 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002703
Cort Strattonde748202017-02-17 12:50:01 -08002704 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002705 {
2706 VkImage image = VK_NULL_HANDLE;
2707 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2708 ASSERT_VK_SUCCESS(err);
2709 VkBuffer buffer = VK_NULL_HANDLE;
2710 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2711 ASSERT_VK_SUCCESS(err);
2712 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2713 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2714 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2715 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2716 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002717 // Leave some extra space for alignment wiggle room
2718 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002719 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002720 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002721 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2722 ASSERT_TRUE(pass);
2723 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2724 ASSERT_TRUE(pass);
2725 VkDeviceMemory image_mem, buffer_mem;
2726 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2727 ASSERT_VK_SUCCESS(err);
2728 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2729 ASSERT_VK_SUCCESS(err);
2730
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Test unaligned memory offset
2732 {
2733 if (image_mem_reqs.alignment > 1) {
2734 VkDeviceSize image_offset = 1;
2735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2736 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2737 (void)err; // This may very well return an error.
2738 m_errorMonitor->VerifyFound();
2739 }
Cort6c7dff72017-01-27 18:34:50 -08002740
Cort Strattonde748202017-02-17 12:50:01 -08002741 if (buffer_mem_reqs.alignment > 1) {
2742 VkDeviceSize buffer_offset = 1;
2743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2744 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2745 (void)err; // This may very well return an error.
2746 m_errorMonitor->VerifyFound();
2747 }
2748 }
2749
2750 // Test memory offsets outside the memory allocation
2751 {
2752 VkDeviceSize image_offset =
2753 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2755 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2756 (void)err; // This may very well return an error.
2757 m_errorMonitor->VerifyFound();
2758
2759 VkDeviceSize buffer_offset =
2760 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2762 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2763 (void)err; // This may very well return an error.
2764 m_errorMonitor->VerifyFound();
2765 }
2766
2767 // Test memory offsets within the memory allocation, but which leave too little memory for
2768 // the resource.
2769 {
2770 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2771 if (image_offset > 0) {
2772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2773 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2774 (void)err; // This may very well return an error.
2775 m_errorMonitor->VerifyFound();
2776 }
2777
2778 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2779 if (buffer_offset > 0) {
2780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2781 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2782 (void)err; // This may very well return an error.
2783 m_errorMonitor->VerifyFound();
2784 }
2785 }
Cort6c7dff72017-01-27 18:34:50 -08002786
2787 vkFreeMemory(device(), image_mem, NULL);
2788 vkFreeMemory(device(), buffer_mem, NULL);
2789 vkDestroyImage(device(), image, NULL);
2790 vkDestroyBuffer(device(), buffer, NULL);
2791 }
2792
Cort Stratton4c38bb52017-01-28 13:33:10 -08002793 // Try to bind memory to an object with an invalid memory type
2794 {
2795 VkImage image = VK_NULL_HANDLE;
2796 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2797 ASSERT_VK_SUCCESS(err);
2798 VkBuffer buffer = VK_NULL_HANDLE;
2799 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2800 ASSERT_VK_SUCCESS(err);
2801 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2802 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2803 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2804 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2805 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2806 image_alloc_info.allocationSize = image_mem_reqs.size;
2807 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2808 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002809 // Create a mask of available memory types *not* supported by these resources,
2810 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002811 VkPhysicalDeviceMemoryProperties memory_properties = {};
2812 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002813 VkDeviceMemory image_mem, buffer_mem;
2814
Cort Stratton4c38bb52017-01-28 13:33:10 -08002815 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002816 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002817 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2818 ASSERT_TRUE(pass);
2819 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2820 ASSERT_VK_SUCCESS(err);
2821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2822 err = vkBindImageMemory(device(), image, image_mem, 0);
2823 (void)err; // This may very well return an error.
2824 m_errorMonitor->VerifyFound();
2825 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002826 }
2827
Cort Stratton4c38bb52017-01-28 13:33:10 -08002828 uint32_t buffer_unsupported_mem_type_bits =
2829 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2836 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 vkDestroyImage(device(), image, NULL);
2843 vkDestroyBuffer(device(), buffer, NULL);
2844 }
2845
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002846 // Try to bind memory to an image created with sparse memory flags
2847 {
2848 VkImageCreateInfo sparse_image_create_info = image_create_info;
2849 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2850 VkImageFormatProperties image_format_properties = {};
2851 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2852 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2853 sparse_image_create_info.usage, sparse_image_create_info.flags,
2854 &image_format_properties);
2855 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2856 // most likely means sparse formats aren't supported here; skip this test.
2857 } else {
2858 ASSERT_VK_SUCCESS(err);
2859 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002860 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002861 return;
2862 } else {
2863 VkImage sparse_image = VK_NULL_HANDLE;
2864 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2865 ASSERT_VK_SUCCESS(err);
2866 VkMemoryRequirements sparse_mem_reqs = {};
2867 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2868 if (sparse_mem_reqs.memoryTypeBits != 0) {
2869 VkMemoryAllocateInfo sparse_mem_alloc = {};
2870 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2871 sparse_mem_alloc.pNext = NULL;
2872 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2873 sparse_mem_alloc.memoryTypeIndex = 0;
2874 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2875 ASSERT_TRUE(pass);
2876 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2877 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2878 ASSERT_VK_SUCCESS(err);
2879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2880 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2881 // This may very well return an error.
2882 (void)err;
2883 m_errorMonitor->VerifyFound();
2884 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2885 }
2886 vkDestroyImage(m_device->device(), sparse_image, NULL);
2887 }
2888 }
2889 }
2890
2891 // Try to bind memory to a buffer created with sparse memory flags
2892 {
2893 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2894 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2895 if (!m_device->phy().features().sparseResidencyBuffer) {
2896 // most likely means sparse formats aren't supported here; skip this test.
2897 } else {
2898 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2899 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2900 ASSERT_VK_SUCCESS(err);
2901 VkMemoryRequirements sparse_mem_reqs = {};
2902 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2903 if (sparse_mem_reqs.memoryTypeBits != 0) {
2904 VkMemoryAllocateInfo sparse_mem_alloc = {};
2905 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2906 sparse_mem_alloc.pNext = NULL;
2907 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2908 sparse_mem_alloc.memoryTypeIndex = 0;
2909 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2910 ASSERT_TRUE(pass);
2911 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2912 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2913 ASSERT_VK_SUCCESS(err);
2914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2915 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2916 // This may very well return an error.
2917 (void)err;
2918 m_errorMonitor->VerifyFound();
2919 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2920 }
2921 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2922 }
2923 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002924}
2925
Karl Schultz6addd812016-02-02 17:17:23 -07002926TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2927 VkResult err;
2928 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002929
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002931
Tobin Ehlisec598302015-09-15 15:02:17 -06002932 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002933
Karl Schultz6addd812016-02-02 17:17:23 -07002934 // Create an image object, allocate memory, destroy the object and then try
2935 // to bind it
2936 VkImage image;
2937 VkDeviceMemory mem;
2938 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002939
Karl Schultz6addd812016-02-02 17:17:23 -07002940 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2941 const int32_t tex_width = 32;
2942 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
2944 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002945 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2946 image_create_info.pNext = NULL;
2947 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2948 image_create_info.format = tex_format;
2949 image_create_info.extent.width = tex_width;
2950 image_create_info.extent.height = tex_height;
2951 image_create_info.extent.depth = 1;
2952 image_create_info.mipLevels = 1;
2953 image_create_info.arrayLayers = 1;
2954 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2955 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2956 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2957 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002958
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002959 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002960 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2961 mem_alloc.pNext = NULL;
2962 mem_alloc.allocationSize = 0;
2963 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002964
Chia-I Wuf7458c52015-10-26 21:10:41 +08002965 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002966 ASSERT_VK_SUCCESS(err);
2967
Karl Schultz6addd812016-02-02 17:17:23 -07002968 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002969
2970 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002971 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002972 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002975 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002976 ASSERT_VK_SUCCESS(err);
2977
2978 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
2982 // Now Try to bind memory to this destroyed object
2983 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2984 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002985 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002987 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002988
Chia-I Wuf7458c52015-10-26 21:10:41 +08002989 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002990}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002991
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002992TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2993 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2994
2995 ASSERT_NO_FATAL_FAILURE(InitState());
2996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2997
2998 VkVertexInputBindingDescription input_binding;
2999 memset(&input_binding, 0, sizeof(input_binding));
3000
3001 VkVertexInputAttributeDescription input_attribs;
3002 memset(&input_attribs, 0, sizeof(input_attribs));
3003
3004 // Pick a really bad format for this purpose and make sure it should fail
3005 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3006 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3007 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003008 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003009 return;
3010 }
3011
3012 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003013 char const *vsSource =
3014 "#version 450\n"
3015 "\n"
3016 "out gl_PerVertex {\n"
3017 " vec4 gl_Position;\n"
3018 "};\n"
3019 "void main(){\n"
3020 " gl_Position = vec4(1);\n"
3021 "}\n";
3022 char const *fsSource =
3023 "#version 450\n"
3024 "\n"
3025 "layout(location=0) out vec4 color;\n"
3026 "void main(){\n"
3027 " color = vec4(1);\n"
3028 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003029
3030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3033
3034 VkPipelineObj pipe(m_device);
3035 pipe.AddColorAttachment();
3036 pipe.AddShader(&vs);
3037 pipe.AddShader(&fs);
3038
3039 pipe.AddVertexInputBindings(&input_binding, 1);
3040 pipe.AddVertexInputAttribs(&input_attribs, 1);
3041
3042 VkDescriptorSetObj descriptorSet(m_device);
3043 descriptorSet.AppendDummy();
3044 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3045
3046 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3047
3048 m_errorMonitor->VerifyFound();
3049}
3050
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003051TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003052 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3053 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003054
3055 VkMemoryPropertyFlags reqs = 0;
3056 VkImageCreateInfo image_create_info = {};
3057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3058 image_create_info.pNext = NULL;
3059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3060 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3061 image_create_info.extent.width = 256;
3062 image_create_info.extent.height = 256;
3063 image_create_info.extent.depth = 1;
3064 image_create_info.mipLevels = 1;
3065 image_create_info.arrayLayers = 1;
3066 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3067 image_create_info.flags = 0;
3068
3069 VkImageBlit blit_region = {};
3070 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3071 blit_region.srcSubresource.baseArrayLayer = 0;
3072 blit_region.srcSubresource.layerCount = 1;
3073 blit_region.srcSubresource.mipLevel = 0;
3074 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3075 blit_region.dstSubresource.baseArrayLayer = 0;
3076 blit_region.dstSubresource.layerCount = 1;
3077 blit_region.dstSubresource.mipLevel = 0;
3078
3079 // Create two images, the source with sampleCount = 2, and attempt to blit
3080 // between them
3081 {
3082 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003084 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003085 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003086 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003087 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003088 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003090 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003091 m_errorMonitor->SetDesiredFailureMsg(
3092 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3093 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003094 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3095 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003096 m_errorMonitor->VerifyFound();
3097 m_commandBuffer->EndCommandBuffer();
3098 }
3099
3100 // Create two images, the dest with sampleCount = 4, and attempt to blit
3101 // between them
3102 {
3103 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003105 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003107 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003109 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003112 m_errorMonitor->SetDesiredFailureMsg(
3113 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3114 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003115 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3116 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003117 m_errorMonitor->VerifyFound();
3118 m_commandBuffer->EndCommandBuffer();
3119 }
3120
3121 VkBufferImageCopy copy_region = {};
3122 copy_region.bufferRowLength = 128;
3123 copy_region.bufferImageHeight = 128;
3124 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3125 copy_region.imageSubresource.layerCount = 1;
3126 copy_region.imageExtent.height = 64;
3127 copy_region.imageExtent.width = 64;
3128 copy_region.imageExtent.depth = 1;
3129
3130 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3131 // buffer to image
3132 {
3133 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003134 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3135 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003137 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003139 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003140 m_errorMonitor->SetDesiredFailureMsg(
3141 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3142 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003143 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3144 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003145 m_errorMonitor->VerifyFound();
3146 m_commandBuffer->EndCommandBuffer();
3147 }
3148
3149 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3150 // image to buffer
3151 {
3152 vk_testing::Buffer dst_buffer;
3153 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3154 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003156 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003158 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003159 m_errorMonitor->SetDesiredFailureMsg(
3160 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3161 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003162 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003163 dst_buffer.handle(), 1, &copy_region);
3164 m_errorMonitor->VerifyFound();
3165 m_commandBuffer->EndCommandBuffer();
3166 }
3167}
3168
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003169TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003170 ASSERT_NO_FATAL_FAILURE(InitState());
3171
3172 VkImageObj src_image(m_device);
3173 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3174 VkImageObj dst_image(m_device);
3175 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3176 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003177 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003178
3179 VkImageBlit blitRegion = {};
3180 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3181 blitRegion.srcSubresource.baseArrayLayer = 0;
3182 blitRegion.srcSubresource.layerCount = 1;
3183 blitRegion.srcSubresource.mipLevel = 0;
3184 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3185 blitRegion.dstSubresource.baseArrayLayer = 0;
3186 blitRegion.dstSubresource.layerCount = 1;
3187 blitRegion.dstSubresource.mipLevel = 0;
3188
Dave Houlton34df4cb2016-12-01 16:43:06 -07003189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3190
3191 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3192 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003193
3194 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003195 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003196 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3197 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003198
3199 m_errorMonitor->VerifyFound();
3200
Dave Houlton34df4cb2016-12-01 16:43:06 -07003201 // Test should generate 2 VU failures
3202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003204
3205 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003206 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3207 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003208
Dave Houlton34df4cb2016-12-01 16:43:06 -07003209 // TODO: Note that this only verifies that at least one of the VU enums was found
3210 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003211 m_errorMonitor->VerifyFound();
3212
Tony Barbour552f6c02016-12-21 14:34:07 -07003213 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003214}
3215
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003216TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3217 VkResult err;
3218 bool pass;
3219
3220 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3221 ASSERT_NO_FATAL_FAILURE(InitState());
3222
3223 // If w/d/h granularity is 1, test is not meaningful
3224 // TODO: When virtual device limits are available, create a set of limits for this test that
3225 // will always have a granularity of > 1 for w, h, and d
3226 auto index = m_device->graphics_queue_node_index_;
3227 auto queue_family_properties = m_device->phy().queue_properties();
3228
3229 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3230 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3231 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3232 return;
3233 }
3234
3235 // Create two images of different types and try to copy between them
3236 VkImage srcImage;
3237 VkImage dstImage;
3238 VkDeviceMemory srcMem;
3239 VkDeviceMemory destMem;
3240 VkMemoryRequirements memReqs;
3241
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003242 VkImageCreateInfo image_create_info = {};
3243 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3244 image_create_info.pNext = NULL;
3245 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3246 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3247 image_create_info.extent.width = 32;
3248 image_create_info.extent.height = 32;
3249 image_create_info.extent.depth = 1;
3250 image_create_info.mipLevels = 1;
3251 image_create_info.arrayLayers = 4;
3252 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3253 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3254 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3255 image_create_info.flags = 0;
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003258 ASSERT_VK_SUCCESS(err);
3259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003260 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003261 ASSERT_VK_SUCCESS(err);
3262
3263 // Allocate memory
3264 VkMemoryAllocateInfo memAlloc = {};
3265 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3266 memAlloc.pNext = NULL;
3267 memAlloc.allocationSize = 0;
3268 memAlloc.memoryTypeIndex = 0;
3269
3270 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3271 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003272 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003273 ASSERT_TRUE(pass);
3274 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3275 ASSERT_VK_SUCCESS(err);
3276
3277 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3278 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 ASSERT_VK_SUCCESS(err);
3281 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3282 ASSERT_VK_SUCCESS(err);
3283
3284 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3285 ASSERT_VK_SUCCESS(err);
3286 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3287 ASSERT_VK_SUCCESS(err);
3288
Tony Barbour552f6c02016-12-21 14:34:07 -07003289 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003290 VkImageCopy copyRegion;
3291 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3292 copyRegion.srcSubresource.mipLevel = 0;
3293 copyRegion.srcSubresource.baseArrayLayer = 0;
3294 copyRegion.srcSubresource.layerCount = 1;
3295 copyRegion.srcOffset.x = 0;
3296 copyRegion.srcOffset.y = 0;
3297 copyRegion.srcOffset.z = 0;
3298 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3299 copyRegion.dstSubresource.mipLevel = 0;
3300 copyRegion.dstSubresource.baseArrayLayer = 0;
3301 copyRegion.dstSubresource.layerCount = 1;
3302 copyRegion.dstOffset.x = 0;
3303 copyRegion.dstOffset.y = 0;
3304 copyRegion.dstOffset.z = 0;
3305 copyRegion.extent.width = 1;
3306 copyRegion.extent.height = 1;
3307 copyRegion.extent.depth = 1;
3308
3309 // Introduce failure by setting srcOffset to a bad granularity value
3310 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3312 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003313 m_errorMonitor->VerifyFound();
3314
3315 // Introduce failure by setting extent to a bad granularity value
3316 copyRegion.srcOffset.y = 0;
3317 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3319 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003320 m_errorMonitor->VerifyFound();
3321
3322 // Now do some buffer/image copies
3323 vk_testing::Buffer buffer;
3324 VkMemoryPropertyFlags reqs = 0;
3325 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3326 VkBufferImageCopy region = {};
3327 region.bufferOffset = 0;
3328 region.bufferRowLength = 3;
3329 region.bufferImageHeight = 128;
3330 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3331 region.imageSubresource.layerCount = 1;
3332 region.imageExtent.height = 16;
3333 region.imageExtent.width = 16;
3334 region.imageExtent.depth = 1;
3335 region.imageOffset.x = 0;
3336 region.imageOffset.y = 0;
3337 region.imageOffset.z = 0;
3338
3339 // Introduce failure by setting bufferRowLength to a bad granularity value
3340 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3342 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3343 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003344 m_errorMonitor->VerifyFound();
3345 region.bufferRowLength = 128;
3346
3347 // Introduce failure by setting bufferOffset to a bad granularity value
3348 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3350 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3351 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003352 m_errorMonitor->VerifyFound();
3353 region.bufferOffset = 0;
3354
3355 // Introduce failure by setting bufferImageHeight to a bad granularity value
3356 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3358 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3359 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003360 m_errorMonitor->VerifyFound();
3361 region.bufferImageHeight = 128;
3362
3363 // Introduce failure by setting imageExtent to a bad granularity value
3364 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3366 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3367 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003368 m_errorMonitor->VerifyFound();
3369 region.imageExtent.width = 16;
3370
3371 // Introduce failure by setting imageOffset to a bad granularity value
3372 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3374 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3375 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003376 m_errorMonitor->VerifyFound();
3377
Tony Barbour552f6c02016-12-21 14:34:07 -07003378 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003379
3380 vkDestroyImage(m_device->device(), srcImage, NULL);
3381 vkDestroyImage(m_device->device(), dstImage, NULL);
3382 vkFreeMemory(m_device->device(), srcMem, NULL);
3383 vkFreeMemory(m_device->device(), destMem, NULL);
3384}
3385
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003386TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003387 TEST_DESCRIPTION(
3388 "Submit command buffer created using one queue family and "
3389 "attempt to submit them on a queue created in a different "
3390 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003391
Cody Northropc31a84f2016-08-22 10:41:47 -06003392 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003393
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003394 // This test is meaningless unless we have multiple queue families
3395 auto queue_family_properties = m_device->phy().queue_properties();
3396 if (queue_family_properties.size() < 2) {
3397 return;
3398 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400 // Get safe index of another queue family
3401 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3402 ASSERT_NO_FATAL_FAILURE(InitState());
3403 // Create a second queue using a different queue family
3404 VkQueue other_queue;
3405 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3406
3407 // Record an empty cmd buffer
3408 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3409 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3410 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3411 vkEndCommandBuffer(m_commandBuffer->handle());
3412
3413 // And submit on the wrong queue
3414 VkSubmitInfo submit_info = {};
3415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3416 submit_info.commandBufferCount = 1;
3417 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003418 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003419
3420 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003421}
3422
Chris Forbes4c24a922016-11-16 08:59:10 +13003423TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3424 ASSERT_NO_FATAL_FAILURE(InitState());
3425
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003426 // There are no attachments, but refer to attachment 0.
3427 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003428 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003429 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003430 };
3431
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003432 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003433 VkRenderPass rp;
3434
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003435 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003437 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3438 m_errorMonitor->VerifyFound();
3439}
3440
Chris Forbesa58c4522016-09-28 15:19:39 +13003441TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3442 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3443 ASSERT_NO_FATAL_FAILURE(InitState());
3444
3445 // A renderpass with two subpasses, both writing the same attachment.
3446 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003447 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3448 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3449 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003450 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003451 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003452 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3454 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003455 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003456 VkSubpassDependency dep = {0,
3457 1,
3458 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3459 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3460 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3461 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3462 VK_DEPENDENCY_BY_REGION_BIT};
3463 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 VkRenderPass rp;
3465 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3466 ASSERT_VK_SUCCESS(err);
3467
3468 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003469 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003470 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3471
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003472 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003473 VkFramebuffer fb;
3474 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3475 ASSERT_VK_SUCCESS(err);
3476
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003477 char const *vsSource =
3478 "#version 450\n"
3479 "void main() { gl_Position = vec4(1); }\n";
3480 char const *fsSource =
3481 "#version 450\n"
3482 "layout(location=0) out vec4 color;\n"
3483 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003484
3485 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3486 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3487 VkPipelineObj pipe(m_device);
3488 pipe.AddColorAttachment();
3489 pipe.AddShader(&vs);
3490 pipe.AddShader(&fs);
3491 VkViewport view_port = {};
3492 m_viewports.push_back(view_port);
3493 pipe.SetViewport(m_viewports);
3494 VkRect2D rect = {};
3495 m_scissors.push_back(rect);
3496 pipe.SetScissor(m_scissors);
3497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003498 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003499 VkPipelineLayout pl;
3500 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3501 ASSERT_VK_SUCCESS(err);
3502 pipe.CreateVKPipeline(pl, rp);
3503
Tony Barbour552f6c02016-12-21 14:34:07 -07003504 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003505
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003506 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3507 nullptr,
3508 rp,
3509 fb,
3510 {{
3511 0, 0,
3512 },
3513 {32, 32}},
3514 0,
3515 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003516
3517 // subtest 1: bind in the wrong subpass
3518 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3519 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003521 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3522 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3523 m_errorMonitor->VerifyFound();
3524
3525 vkCmdEndRenderPass(m_commandBuffer->handle());
3526
3527 // subtest 2: bind in correct subpass, then transition to next subpass
3528 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3529 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3530 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003532 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3533 m_errorMonitor->VerifyFound();
3534
3535 vkCmdEndRenderPass(m_commandBuffer->handle());
3536
Tony Barbour552f6c02016-12-21 14:34:07 -07003537 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003538
3539 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3540 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3541 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3542}
3543
Tony Barbour4e919972016-08-09 13:27:40 -06003544TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003545 TEST_DESCRIPTION(
3546 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3547 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003548 ASSERT_NO_FATAL_FAILURE(InitState());
3549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3550
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3552 "Cannot execute a render pass with renderArea "
3553 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003554
3555 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3556 m_renderPassBeginInfo.renderArea.extent.width = 257;
3557 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003558 m_commandBuffer->BeginCommandBuffer();
3559 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003560 m_errorMonitor->VerifyFound();
3561}
3562
3563TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003564 TEST_DESCRIPTION(
3565 "Generate INDEPENDENT_BLEND by disabling independent "
3566 "blend and then specifying different blend states for two "
3567 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003568 VkPhysicalDeviceFeatures features = {};
3569 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003570 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3573 "Invalid Pipeline CreateInfo: If independent blend feature not "
3574 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003575
Cody Northropc31a84f2016-08-22 10:41:47 -06003576 VkDescriptorSetObj descriptorSet(m_device);
3577 descriptorSet.AppendDummy();
3578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003579
Cody Northropc31a84f2016-08-22 10:41:47 -06003580 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003581 // Create a renderPass with two color attachments
3582 VkAttachmentReference attachments[2] = {};
3583 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3584 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3585
3586 VkSubpassDescription subpass = {};
3587 subpass.pColorAttachments = attachments;
3588 subpass.colorAttachmentCount = 2;
3589
3590 VkRenderPassCreateInfo rpci = {};
3591 rpci.subpassCount = 1;
3592 rpci.pSubpasses = &subpass;
3593 rpci.attachmentCount = 1;
3594
3595 VkAttachmentDescription attach_desc = {};
3596 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3597 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3598 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3599 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 rpci.pAttachments = &attach_desc;
3602 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3603
3604 VkRenderPass renderpass;
3605 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003607 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003608
Cody Northropc31a84f2016-08-22 10:41:47 -06003609 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3610 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3611 att_state1.blendEnable = VK_TRUE;
3612 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3613 att_state2.blendEnable = VK_FALSE;
3614 pipeline.AddColorAttachment(0, &att_state1);
3615 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003616 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003617 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003618 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003619}
3620
Mike Weiblen40b160e2017-02-06 19:21:52 -07003621// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3622TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3623 TEST_DESCRIPTION(
3624 "Create a graphics pipeline that is incompatible with the requirements "
3625 "of its contained Renderpass/subpasses.");
3626 ASSERT_NO_FATAL_FAILURE(InitState());
3627
3628 VkDescriptorSetObj ds_obj(m_device);
3629 ds_obj.AppendDummy();
3630 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3631
3632 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3633
3634 VkPipelineColorBlendAttachmentState att_state1 = {};
3635 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3636 att_state1.blendEnable = VK_TRUE;
3637
3638 VkRenderpassObj rp_obj(m_device);
3639
3640 {
3641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3642 VkPipelineObj pipeline(m_device);
3643 pipeline.AddShader(&vs_obj);
3644 pipeline.AddColorAttachment(0, &att_state1);
3645
3646 VkGraphicsPipelineCreateInfo info = {};
3647 pipeline.InitGraphicsPipelineCreateInfo(&info);
3648 info.pColorBlendState = nullptr;
3649
3650 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3651 m_errorMonitor->VerifyFound();
3652 }
3653}
3654
Chris Forbes26ec2122016-11-29 08:58:33 +13003655#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003656TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3657 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3658 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003659 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3662 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003663
3664 // Create a renderPass with a single color attachment
3665 VkAttachmentReference attach = {};
3666 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3667 VkSubpassDescription subpass = {};
3668 VkRenderPassCreateInfo rpci = {};
3669 rpci.subpassCount = 1;
3670 rpci.pSubpasses = &subpass;
3671 rpci.attachmentCount = 1;
3672 VkAttachmentDescription attach_desc = {};
3673 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3674 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3675 rpci.pAttachments = &attach_desc;
3676 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3677 VkRenderPass rp;
3678 subpass.pDepthStencilAttachment = &attach;
3679 subpass.pColorAttachments = NULL;
3680 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3681 m_errorMonitor->VerifyFound();
3682}
Chris Forbes26ec2122016-11-29 08:58:33 +13003683#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003684
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003685TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003686 TEST_DESCRIPTION(
3687 "Create a framebuffer where a subpass has a preserve "
3688 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003689
3690 ASSERT_NO_FATAL_FAILURE(InitState());
3691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003694
3695 VkAttachmentReference color_attach = {};
3696 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3697 color_attach.attachment = 0;
3698 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3699 VkSubpassDescription subpass = {};
3700 subpass.colorAttachmentCount = 1;
3701 subpass.pColorAttachments = &color_attach;
3702 subpass.preserveAttachmentCount = 1;
3703 subpass.pPreserveAttachments = &preserve_attachment;
3704
3705 VkRenderPassCreateInfo rpci = {};
3706 rpci.subpassCount = 1;
3707 rpci.pSubpasses = &subpass;
3708 rpci.attachmentCount = 1;
3709 VkAttachmentDescription attach_desc = {};
3710 attach_desc.format = VK_FORMAT_UNDEFINED;
3711 rpci.pAttachments = &attach_desc;
3712 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3713 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003714 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003715
3716 m_errorMonitor->VerifyFound();
3717
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003718 if (result == VK_SUCCESS) {
3719 vkDestroyRenderPass(m_device->device(), rp, NULL);
3720 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003721}
3722
Chris Forbesc5389742016-06-29 11:49:23 +12003723TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003724 TEST_DESCRIPTION(
3725 "Ensure that CreateRenderPass produces a validation error "
3726 "when the source of a subpass multisample resolve "
3727 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003728
Chris Forbesc5389742016-06-29 11:49:23 +12003729 ASSERT_NO_FATAL_FAILURE(InitState());
3730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3732 "Subpass 0 requests multisample resolve from attachment 0 which has "
3733 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003734
3735 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003736 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3737 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3738 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3739 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3740 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3741 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003742 };
3743
3744 VkAttachmentReference color = {
3745 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3746 };
3747
3748 VkAttachmentReference resolve = {
3749 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3750 };
3751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003752 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003754 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003755
3756 VkRenderPass rp;
3757 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3758
3759 m_errorMonitor->VerifyFound();
3760
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003761 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003762}
3763
3764TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003765 TEST_DESCRIPTION(
3766 "Ensure CreateRenderPass produces a validation error "
3767 "when a subpass multisample resolve operation is "
3768 "requested, and the destination of that resolve has "
3769 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003770
Chris Forbesc5389742016-06-29 11:49:23 +12003771 ASSERT_NO_FATAL_FAILURE(InitState());
3772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3774 "Subpass 0 requests multisample resolve into attachment 1, which "
3775 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003776
3777 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3779 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3780 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3781 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3782 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3783 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003784 };
3785
3786 VkAttachmentReference color = {
3787 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3788 };
3789
3790 VkAttachmentReference resolve = {
3791 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3792 };
3793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003796 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003797
3798 VkRenderPass rp;
3799 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3800
3801 m_errorMonitor->VerifyFound();
3802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003803 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003804}
3805
Chris Forbes3f128ef2016-06-29 14:58:53 +12003806TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003807 TEST_DESCRIPTION(
3808 "Ensure CreateRenderPass produces a validation error "
3809 "when the color and depth attachments used by a subpass "
3810 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003811
Chris Forbes3f128ef2016-06-29 14:58:53 +12003812 ASSERT_NO_FATAL_FAILURE(InitState());
3813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3815 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003816
3817 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003818 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3819 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3820 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3821 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3822 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3823 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003824 };
3825
3826 VkAttachmentReference color[] = {
3827 {
3828 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3829 },
3830 {
3831 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3832 },
3833 };
3834
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003835 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003836
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003838
3839 VkRenderPass rp;
3840 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3841
3842 m_errorMonitor->VerifyFound();
3843
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003844 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003845}
3846
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003847TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003848 TEST_DESCRIPTION(
3849 "Hit errors when attempting to create a framebuffer :\n"
3850 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3851 " 2. Use a color image as depthStencil attachment\n"
3852 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3853 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3854 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3855 " 6. Framebuffer attachment where dimensions don't match\n"
3856 " 7. Framebuffer attachment w/o identity swizzle\n"
3857 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003858
3859 ASSERT_NO_FATAL_FAILURE(InitState());
3860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3861
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003862 m_errorMonitor->SetDesiredFailureMsg(
3863 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3864 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003867 VkAttachmentReference attach = {};
3868 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3869 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003870 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003871 VkRenderPassCreateInfo rpci = {};
3872 rpci.subpassCount = 1;
3873 rpci.pSubpasses = &subpass;
3874 rpci.attachmentCount = 1;
3875 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003876 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003877 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003878 rpci.pAttachments = &attach_desc;
3879 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3880 VkRenderPass rp;
3881 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3882 ASSERT_VK_SUCCESS(err);
3883
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003884 VkImageView ivs[2];
3885 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3886 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003887 VkFramebufferCreateInfo fb_info = {};
3888 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3889 fb_info.pNext = NULL;
3890 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003891 // Set mis-matching attachmentCount
3892 fb_info.attachmentCount = 2;
3893 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003894 fb_info.width = 100;
3895 fb_info.height = 100;
3896 fb_info.layers = 1;
3897
3898 VkFramebuffer fb;
3899 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3900
3901 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003902 if (err == VK_SUCCESS) {
3903 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3904 }
3905 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003906
3907 // Create a renderPass with a depth-stencil attachment created with
3908 // IMAGE_USAGE_COLOR_ATTACHMENT
3909 // Add our color attachment to pDepthStencilAttachment
3910 subpass.pDepthStencilAttachment = &attach;
3911 subpass.pColorAttachments = NULL;
3912 VkRenderPass rp_ds;
3913 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3914 ASSERT_VK_SUCCESS(err);
3915 // Set correct attachment count, but attachment has COLOR usage bit set
3916 fb_info.attachmentCount = 1;
3917 fb_info.renderPass = rp_ds;
3918
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003920 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3921
3922 m_errorMonitor->VerifyFound();
3923 if (err == VK_SUCCESS) {
3924 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3925 }
3926 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003927
3928 // Create new renderpass with alternate attachment format from fb
3929 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3930 subpass.pDepthStencilAttachment = NULL;
3931 subpass.pColorAttachments = &attach;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3933 ASSERT_VK_SUCCESS(err);
3934
3935 // Cause error due to mis-matched formats between rp & fb
3936 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3937 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3939 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003940 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3941
3942 m_errorMonitor->VerifyFound();
3943 if (err == VK_SUCCESS) {
3944 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3945 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003946 vkDestroyRenderPass(m_device->device(), rp, NULL);
3947
3948 // Create new renderpass with alternate sample count from fb
3949 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3950 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched sample count between rp & fb
3955 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003957 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003958 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3959
3960 m_errorMonitor->VerifyFound();
3961 if (err == VK_SUCCESS) {
3962 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3963 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003964
3965 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003966
3967 // Create a custom imageView with non-1 mip levels
3968 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003969 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003970 ASSERT_TRUE(image.initialized());
3971
3972 VkImageView view;
3973 VkImageViewCreateInfo ivci = {};
3974 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3975 ivci.image = image.handle();
3976 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3977 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3978 ivci.subresourceRange.layerCount = 1;
3979 ivci.subresourceRange.baseMipLevel = 0;
3980 // Set level count 2 (only 1 is allowed for FB attachment)
3981 ivci.subresourceRange.levelCount = 2;
3982 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3983 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3984 ASSERT_VK_SUCCESS(err);
3985 // Re-create renderpass to have matching sample count
3986 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3987 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3988 ASSERT_VK_SUCCESS(err);
3989
3990 fb_info.renderPass = rp;
3991 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003993 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3994
3995 m_errorMonitor->VerifyFound();
3996 if (err == VK_SUCCESS) {
3997 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3998 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003999 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004000 // Update view to original color buffer and grow FB dimensions too big
4001 fb_info.pAttachments = ivs;
4002 fb_info.height = 1024;
4003 fb_info.width = 1024;
4004 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004006 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4007
4008 m_errorMonitor->VerifyFound();
4009 if (err == VK_SUCCESS) {
4010 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4011 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004012 // Create view attachment with non-identity swizzle
4013 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4014 ivci.image = image.handle();
4015 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4016 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4017 ivci.subresourceRange.layerCount = 1;
4018 ivci.subresourceRange.baseMipLevel = 0;
4019 ivci.subresourceRange.levelCount = 1;
4020 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4021 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4022 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4023 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4024 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4025 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4026 ASSERT_VK_SUCCESS(err);
4027
4028 fb_info.pAttachments = &view;
4029 fb_info.height = 100;
4030 fb_info.width = 100;
4031 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004032 m_errorMonitor->SetDesiredFailureMsg(
4033 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4034 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004035 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4036
4037 m_errorMonitor->VerifyFound();
4038 if (err == VK_SUCCESS) {
4039 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4040 }
4041 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004042 // reset attachment to color attachment
4043 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004044
4045 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004046 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004047 fb_info.height = 100;
4048 fb_info.layers = 1;
4049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004050 m_errorMonitor->SetDesiredFailureMsg(
4051 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004052 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4053 "Here are the respective dimensions for attachment");
4054
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004055 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4056
4057 m_errorMonitor->VerifyFound();
4058 if (err == VK_SUCCESS) {
4059 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4060 }
4061
4062 // Request fb that exceeds max height
4063 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004064 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004065 fb_info.layers = 1;
4066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004067 m_errorMonitor->SetDesiredFailureMsg(
4068 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004069 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4070 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004071 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4072
4073 m_errorMonitor->VerifyFound();
4074 if (err == VK_SUCCESS) {
4075 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4076 }
4077
4078 // Request fb that exceeds max layers
4079 fb_info.width = 100;
4080 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004081 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004083 m_errorMonitor->SetDesiredFailureMsg(
4084 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004085 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4086 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004087 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4088
4089 m_errorMonitor->VerifyFound();
4090 if (err == VK_SUCCESS) {
4091 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4092 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004093
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004094 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004095}
4096
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004097TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004098 TEST_DESCRIPTION(
4099 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4100 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004101
Cody Northropc31a84f2016-08-22 10:41:47 -06004102 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004103 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4105 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106 m_errorMonitor->VerifyFound();
4107}
4108
4109TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004110 TEST_DESCRIPTION(
4111 "Run a simple draw calls to validate failure when Line Width dynamic "
4112 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004113
Cody Northropc31a84f2016-08-22 10:41:47 -06004114 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004115 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4117 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004118 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004119}
4120
4121TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004122 TEST_DESCRIPTION(
4123 "Run a simple draw calls to validate failure when Viewport dynamic "
4124 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125
Cody Northropc31a84f2016-08-22 10:41:47 -06004126 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4129 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004131 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004132}
4133
4134TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004135 TEST_DESCRIPTION(
4136 "Run a simple draw calls to validate failure when Scissor dynamic "
4137 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138
Cody Northropc31a84f2016-08-22 10:41:47 -06004139 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004140 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4142 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004144 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004145}
4146
Cortd713fe82016-07-27 09:51:27 -07004147TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004148 TEST_DESCRIPTION(
4149 "Run a simple draw calls to validate failure when Blend Constants "
4150 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004151
4152 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004153 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4155 "Dynamic blend constants state not set for this command buffer");
4156 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004157 m_errorMonitor->VerifyFound();
4158}
4159
4160TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004161 TEST_DESCRIPTION(
4162 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4163 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004164
4165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004166 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004167 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004168 return;
4169 }
4170 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4172 "Dynamic depth bounds state not set for this command buffer");
4173 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004174 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004175}
4176
4177TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004178 TEST_DESCRIPTION(
4179 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4180 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004181
4182 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004183 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4185 "Dynamic stencil read mask state not set for this command buffer");
4186 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004187 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004188}
4189
4190TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004191 TEST_DESCRIPTION(
4192 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4193 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004194
4195 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004196 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4198 "Dynamic stencil write mask state not set for this command buffer");
4199 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004200 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004201}
4202
4203TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004204 TEST_DESCRIPTION(
4205 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4206 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004207
4208 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004209 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4211 "Dynamic stencil reference state not set for this command buffer");
4212 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004213 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004214}
4215
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004216TEST_F(VkLayerTest, IndexBufferNotBound) {
4217 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004218
4219 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4221 "Index buffer object not bound to this command buffer when Indexed ");
4222 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004223 m_errorMonitor->VerifyFound();
4224}
4225
Karl Schultz6addd812016-02-02 17:17:23 -07004226TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4228 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4229 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004230
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004231 ASSERT_NO_FATAL_FAILURE(InitState());
4232 ASSERT_NO_FATAL_FAILURE(InitViewport());
4233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4234
Karl Schultz6addd812016-02-02 17:17:23 -07004235 // We luck out b/c by default the framework creates CB w/ the
4236 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004237 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004238 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004239 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004240
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004241 // Bypass framework since it does the waits automatically
4242 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004243 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4245 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004246 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004247 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004248 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004249 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004250 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004251 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004252 submit_info.pSignalSemaphores = NULL;
4253
Chris Forbes40028e22016-06-13 09:59:34 +12004254 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004255 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004256 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004257
Karl Schultz6addd812016-02-02 17:17:23 -07004258 // Cause validation error by re-submitting cmd buffer that should only be
4259 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004260 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004261 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004263 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004264}
4265
Karl Schultz6addd812016-02-02 17:17:23 -07004266TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004267 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004268 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004269
4270 ASSERT_NO_FATAL_FAILURE(InitState());
4271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004272
Karl Schultz6addd812016-02-02 17:17:23 -07004273 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4274 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004276 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004277 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278
4279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4281 ds_pool_ci.pNext = NULL;
4282 ds_pool_ci.flags = 0;
4283 ds_pool_ci.maxSets = 1;
4284 ds_pool_ci.poolSizeCount = 1;
4285 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
4287 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004289 ASSERT_VK_SUCCESS(err);
4290
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4292 dsl_binding_samp.binding = 0;
4293 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4294 dsl_binding_samp.descriptorCount = 1;
4295 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4296 dsl_binding_samp.pImmutableSamplers = NULL;
4297
4298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4300 ds_layout_ci.pNext = NULL;
4301 ds_layout_ci.bindingCount = 1;
4302 ds_layout_ci.pBindings = &dsl_binding_samp;
4303
4304 VkDescriptorSetLayout ds_layout_samp;
4305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4306 ASSERT_VK_SUCCESS(err);
4307
4308 // Try to allocate 2 sets when pool only has 1 set
4309 VkDescriptorSet descriptor_sets[2];
4310 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4311 VkDescriptorSetAllocateInfo alloc_info = {};
4312 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4313 alloc_info.descriptorSetCount = 2;
4314 alloc_info.descriptorPool = ds_pool;
4315 alloc_info.pSetLayouts = set_layouts;
4316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4317 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4318 m_errorMonitor->VerifyFound();
4319
4320 alloc_info.descriptorSetCount = 1;
4321 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004322 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004323 dsl_binding.binding = 0;
4324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4325 dsl_binding.descriptorCount = 1;
4326 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4327 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004328
Karl Schultz6addd812016-02-02 17:17:23 -07004329 ds_layout_ci.bindingCount = 1;
4330 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004331
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004332 VkDescriptorSetLayout ds_layout_ub;
4333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004334 ASSERT_VK_SUCCESS(err);
4335
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004336 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004337 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004338 alloc_info.pSetLayouts = &ds_layout_ub;
4339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4340 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004342 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343
Karl Schultz2825ab92016-12-02 08:23:14 -07004344 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347}
4348
Karl Schultz6addd812016-02-02 17:17:23 -07004349TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4350 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004351
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004353
Tobin Ehlise735c692015-10-08 13:13:50 -06004354 ASSERT_NO_FATAL_FAILURE(InitState());
4355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004356
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004357 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004358 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4359 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004360
4361 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004362 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4363 ds_pool_ci.pNext = NULL;
4364 ds_pool_ci.maxSets = 1;
4365 ds_pool_ci.poolSizeCount = 1;
4366 ds_pool_ci.flags = 0;
4367 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4368 // app can only call vkResetDescriptorPool on this pool.;
4369 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
4371 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004372 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_VK_SUCCESS(err);
4374
4375 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004376 dsl_binding.binding = 0;
4377 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 dsl_binding.descriptorCount = 1;
4379 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4380 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004381
4382 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004383 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4384 ds_layout_ci.pNext = NULL;
4385 ds_layout_ci.bindingCount = 1;
4386 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004387
4388 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004390 ASSERT_VK_SUCCESS(err);
4391
4392 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004393 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004395 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004396 alloc_info.descriptorPool = ds_pool;
4397 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004399 ASSERT_VK_SUCCESS(err);
4400
4401 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004402 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004403
Chia-I Wuf7458c52015-10-26 21:10:41 +08004404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4405 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004406}
4407
Karl Schultz6addd812016-02-02 17:17:23 -07004408TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004409 // Attempt to clear Descriptor Pool with bad object.
4410 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004411
4412 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004414 uint64_t fake_pool_handle = 0xbaad6001;
4415 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4416 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004417 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004418}
4419
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004420TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004421 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4422 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004423 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004424 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004425
4426 uint64_t fake_set_handle = 0xbaad6001;
4427 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
4432
4433 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4434 layout_bindings[0].binding = 0;
4435 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4436 layout_bindings[0].descriptorCount = 1;
4437 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4438 layout_bindings[0].pImmutableSamplers = NULL;
4439
4440 VkDescriptorSetLayout descriptor_set_layout;
4441 VkDescriptorSetLayoutCreateInfo dslci = {};
4442 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4443 dslci.pNext = NULL;
4444 dslci.bindingCount = 1;
4445 dslci.pBindings = layout_bindings;
4446 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004447 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004448
4449 VkPipelineLayout pipeline_layout;
4450 VkPipelineLayoutCreateInfo plci = {};
4451 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4452 plci.pNext = NULL;
4453 plci.setLayoutCount = 1;
4454 plci.pSetLayouts = &descriptor_set_layout;
4455 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004456 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004457
Tony Barbour552f6c02016-12-21 14:34:07 -07004458 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004459 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4460 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004461 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004462 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004463 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4464 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004465}
4466
Karl Schultz6addd812016-02-02 17:17:23 -07004467TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004468 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4469 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004470 uint64_t fake_layout_handle = 0xbaad6001;
4471 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004473 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004474 VkPipelineLayout pipeline_layout;
4475 VkPipelineLayoutCreateInfo plci = {};
4476 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4477 plci.pNext = NULL;
4478 plci.setLayoutCount = 1;
4479 plci.pSetLayouts = &bad_layout;
4480 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4481
4482 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004483}
4484
Mark Muellerd4914412016-06-13 17:52:06 -06004485TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004486 TEST_DESCRIPTION(
4487 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4488 "1) A uniform buffer update must have a valid buffer index."
4489 "2) When using an array of descriptors in a single WriteDescriptor,"
4490 " the descriptor types and stageflags must all be the same."
4491 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004492
Mike Weiblena6666382017-01-05 15:16:11 -07004493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004494
4495 ASSERT_NO_FATAL_FAILURE(InitState());
4496 VkDescriptorPoolSize ds_type_count[4] = {};
4497 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4498 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004499 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004500 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004501 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004502 ds_type_count[2].descriptorCount = 1;
4503 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4504 ds_type_count[3].descriptorCount = 1;
4505
4506 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4507 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4508 ds_pool_ci.maxSets = 1;
4509 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4510 ds_pool_ci.pPoolSizes = ds_type_count;
4511
4512 VkDescriptorPool ds_pool;
4513 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4514 ASSERT_VK_SUCCESS(err);
4515
Mark Muellerb9896722016-06-16 09:54:29 -06004516 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004517 layout_binding[0].binding = 0;
4518 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4519 layout_binding[0].descriptorCount = 1;
4520 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4521 layout_binding[0].pImmutableSamplers = NULL;
4522
4523 layout_binding[1].binding = 1;
4524 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4525 layout_binding[1].descriptorCount = 1;
4526 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4527 layout_binding[1].pImmutableSamplers = NULL;
4528
4529 VkSamplerCreateInfo sampler_ci = {};
4530 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4531 sampler_ci.pNext = NULL;
4532 sampler_ci.magFilter = VK_FILTER_NEAREST;
4533 sampler_ci.minFilter = VK_FILTER_NEAREST;
4534 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4535 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4536 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4537 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4538 sampler_ci.mipLodBias = 1.0;
4539 sampler_ci.anisotropyEnable = VK_FALSE;
4540 sampler_ci.maxAnisotropy = 1;
4541 sampler_ci.compareEnable = VK_FALSE;
4542 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4543 sampler_ci.minLod = 1.0;
4544 sampler_ci.maxLod = 1.0;
4545 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4546 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4547 VkSampler sampler;
4548
4549 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4550 ASSERT_VK_SUCCESS(err);
4551
4552 layout_binding[2].binding = 2;
4553 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4554 layout_binding[2].descriptorCount = 1;
4555 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4556 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4557
Mark Muellerd4914412016-06-13 17:52:06 -06004558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4559 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4560 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4561 ds_layout_ci.pBindings = layout_binding;
4562 VkDescriptorSetLayout ds_layout;
4563 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4564 ASSERT_VK_SUCCESS(err);
4565
4566 VkDescriptorSetAllocateInfo alloc_info = {};
4567 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4568 alloc_info.descriptorSetCount = 1;
4569 alloc_info.descriptorPool = ds_pool;
4570 alloc_info.pSetLayouts = &ds_layout;
4571 VkDescriptorSet descriptorSet;
4572 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4573 ASSERT_VK_SUCCESS(err);
4574
4575 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4576 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4577 pipeline_layout_ci.pNext = NULL;
4578 pipeline_layout_ci.setLayoutCount = 1;
4579 pipeline_layout_ci.pSetLayouts = &ds_layout;
4580
4581 VkPipelineLayout pipeline_layout;
4582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
Mark Mueller5c838ce2016-06-16 09:54:29 -06004585 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004586 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4587 descriptor_write.dstSet = descriptorSet;
4588 descriptor_write.dstBinding = 0;
4589 descriptor_write.descriptorCount = 1;
4590 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4591
Mark Mueller5c838ce2016-06-16 09:54:29 -06004592 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004593 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4594 m_errorMonitor->VerifyFound();
4595
4596 // Create a buffer to update the descriptor with
4597 uint32_t qfi = 0;
4598 VkBufferCreateInfo buffCI = {};
4599 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4600 buffCI.size = 1024;
4601 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4602 buffCI.queueFamilyIndexCount = 1;
4603 buffCI.pQueueFamilyIndices = &qfi;
4604
4605 VkBuffer dyub;
4606 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4607 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004608
Tony Barboure132c5f2016-12-12 11:50:20 -07004609 VkDeviceMemory mem;
4610 VkMemoryRequirements mem_reqs;
4611 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4612
4613 VkMemoryAllocateInfo mem_alloc_info = {};
4614 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4615 mem_alloc_info.allocationSize = mem_reqs.size;
4616 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4617 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4618 ASSERT_VK_SUCCESS(err);
4619
4620 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4621 ASSERT_VK_SUCCESS(err);
4622
4623 VkDescriptorBufferInfo buffInfo[2] = {};
4624 buffInfo[0].buffer = dyub;
4625 buffInfo[0].offset = 0;
4626 buffInfo[0].range = 1024;
4627 buffInfo[1].buffer = dyub;
4628 buffInfo[1].offset = 0;
4629 buffInfo[1].range = 1024;
4630 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004631 descriptor_write.descriptorCount = 2;
4632
Mark Mueller5c838ce2016-06-16 09:54:29 -06004633 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004635 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4636 m_errorMonitor->VerifyFound();
4637
Mark Mueller5c838ce2016-06-16 09:54:29 -06004638 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4639 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004640 descriptor_write.dstBinding = 1;
4641 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004642
Mark Mueller5c838ce2016-06-16 09:54:29 -06004643 // Make pImageInfo index non-null to avoid complaints of it missing
4644 VkDescriptorImageInfo imageInfo = {};
4645 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4646 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4649 m_errorMonitor->VerifyFound();
4650
Mark Muellerd4914412016-06-13 17:52:06 -06004651 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004652 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004653 vkDestroySampler(m_device->device(), sampler, NULL);
4654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4657}
4658
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004659TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004660 TEST_DESCRIPTION(
4661 "Attempt to draw with a command buffer that is invalid "
4662 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004663 ASSERT_NO_FATAL_FAILURE(InitState());
4664
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004665 VkBuffer buffer;
4666 VkDeviceMemory mem;
4667 VkMemoryRequirements mem_reqs;
4668
4669 VkBufferCreateInfo buf_info = {};
4670 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004671 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004672 buf_info.size = 256;
4673 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4674 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4675 ASSERT_VK_SUCCESS(err);
4676
4677 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4678
4679 VkMemoryAllocateInfo alloc_info = {};
4680 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4681 alloc_info.allocationSize = 256;
4682 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004683 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004684 if (!pass) {
4685 vkDestroyBuffer(m_device->device(), buffer, NULL);
4686 return;
4687 }
4688 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4692 ASSERT_VK_SUCCESS(err);
4693
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004694 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004695 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004696 m_commandBuffer->EndCommandBuffer();
4697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004699 // Destroy buffer dependency prior to submit to cause ERROR
4700 vkDestroyBuffer(m_device->device(), buffer, NULL);
4701
4702 VkSubmitInfo submit_info = {};
4703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4704 submit_info.commandBufferCount = 1;
4705 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4707
4708 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004709 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004710 vkFreeMemory(m_device->handle(), mem, NULL);
4711}
4712
Tobin Ehlisea413442016-09-28 10:23:59 -06004713TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4714 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4715
4716 ASSERT_NO_FATAL_FAILURE(InitState());
4717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4718
4719 VkDescriptorPoolSize ds_type_count;
4720 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4721 ds_type_count.descriptorCount = 1;
4722
4723 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4724 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4725 ds_pool_ci.maxSets = 1;
4726 ds_pool_ci.poolSizeCount = 1;
4727 ds_pool_ci.pPoolSizes = &ds_type_count;
4728
4729 VkDescriptorPool ds_pool;
4730 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4731 ASSERT_VK_SUCCESS(err);
4732
4733 VkDescriptorSetLayoutBinding layout_binding;
4734 layout_binding.binding = 0;
4735 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4736 layout_binding.descriptorCount = 1;
4737 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4738 layout_binding.pImmutableSamplers = NULL;
4739
4740 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4741 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4742 ds_layout_ci.bindingCount = 1;
4743 ds_layout_ci.pBindings = &layout_binding;
4744 VkDescriptorSetLayout ds_layout;
4745 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4746 ASSERT_VK_SUCCESS(err);
4747
4748 VkDescriptorSetAllocateInfo alloc_info = {};
4749 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4750 alloc_info.descriptorSetCount = 1;
4751 alloc_info.descriptorPool = ds_pool;
4752 alloc_info.pSetLayouts = &ds_layout;
4753 VkDescriptorSet descriptor_set;
4754 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4755 ASSERT_VK_SUCCESS(err);
4756
4757 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4758 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4759 pipeline_layout_ci.pNext = NULL;
4760 pipeline_layout_ci.setLayoutCount = 1;
4761 pipeline_layout_ci.pSetLayouts = &ds_layout;
4762
4763 VkPipelineLayout pipeline_layout;
4764 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkBuffer buffer;
4768 uint32_t queue_family_index = 0;
4769 VkBufferCreateInfo buffer_create_info = {};
4770 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4771 buffer_create_info.size = 1024;
4772 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4773 buffer_create_info.queueFamilyIndexCount = 1;
4774 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4775
4776 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4777 ASSERT_VK_SUCCESS(err);
4778
4779 VkMemoryRequirements memory_reqs;
4780 VkDeviceMemory buffer_memory;
4781
4782 VkMemoryAllocateInfo memory_info = {};
4783 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4784 memory_info.allocationSize = 0;
4785 memory_info.memoryTypeIndex = 0;
4786
4787 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4788 memory_info.allocationSize = memory_reqs.size;
4789 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4790 ASSERT_TRUE(pass);
4791
4792 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4793 ASSERT_VK_SUCCESS(err);
4794 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4795 ASSERT_VK_SUCCESS(err);
4796
4797 VkBufferView view;
4798 VkBufferViewCreateInfo bvci = {};
4799 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4800 bvci.buffer = buffer;
4801 bvci.format = VK_FORMAT_R8_UNORM;
4802 bvci.range = VK_WHOLE_SIZE;
4803
4804 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4805 ASSERT_VK_SUCCESS(err);
4806
4807 VkWriteDescriptorSet descriptor_write = {};
4808 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4809 descriptor_write.dstSet = descriptor_set;
4810 descriptor_write.dstBinding = 0;
4811 descriptor_write.descriptorCount = 1;
4812 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4813 descriptor_write.pTexelBufferView = &view;
4814
4815 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4816
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004817 char const *vsSource =
4818 "#version 450\n"
4819 "\n"
4820 "out gl_PerVertex { \n"
4821 " vec4 gl_Position;\n"
4822 "};\n"
4823 "void main(){\n"
4824 " gl_Position = vec4(1);\n"
4825 "}\n";
4826 char const *fsSource =
4827 "#version 450\n"
4828 "\n"
4829 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4830 "layout(location=0) out vec4 x;\n"
4831 "void main(){\n"
4832 " x = imageLoad(s, 0);\n"
4833 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4836 VkPipelineObj pipe(m_device);
4837 pipe.AddShader(&vs);
4838 pipe.AddShader(&fs);
4839 pipe.AddColorAttachment();
4840 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4841
Tobin Ehlisea413442016-09-28 10:23:59 -06004842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4843
Tony Barbour552f6c02016-12-21 14:34:07 -07004844 m_commandBuffer->BeginCommandBuffer();
4845 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4846
Tobin Ehlisea413442016-09-28 10:23:59 -06004847 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4848 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4849 VkRect2D scissor = {{0, 0}, {16, 16}};
4850 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4851 // Bind pipeline to cmd buffer
4852 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4853 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4854 &descriptor_set, 0, nullptr);
4855 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004856 m_commandBuffer->EndRenderPass();
4857 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004858
4859 // Delete BufferView in order to invalidate cmd buffer
4860 vkDestroyBufferView(m_device->device(), view, NULL);
4861 // Now attempt submit of cmd buffer
4862 VkSubmitInfo submit_info = {};
4863 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4864 submit_info.commandBufferCount = 1;
4865 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4867 m_errorMonitor->VerifyFound();
4868
4869 // Clean-up
4870 vkDestroyBuffer(m_device->device(), buffer, NULL);
4871 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4872 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4873 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4874 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4875}
4876
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004877TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004878 TEST_DESCRIPTION(
4879 "Attempt to draw with a command buffer that is invalid "
4880 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004881 ASSERT_NO_FATAL_FAILURE(InitState());
4882
4883 VkImage image;
4884 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4885 VkImageCreateInfo image_create_info = {};
4886 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4887 image_create_info.pNext = NULL;
4888 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4889 image_create_info.format = tex_format;
4890 image_create_info.extent.width = 32;
4891 image_create_info.extent.height = 32;
4892 image_create_info.extent.depth = 1;
4893 image_create_info.mipLevels = 1;
4894 image_create_info.arrayLayers = 1;
4895 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4896 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004897 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004898 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004901 // Have to bind memory to image before recording cmd in cmd buffer using it
4902 VkMemoryRequirements mem_reqs;
4903 VkDeviceMemory image_mem;
4904 bool pass;
4905 VkMemoryAllocateInfo mem_alloc = {};
4906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4907 mem_alloc.pNext = NULL;
4908 mem_alloc.memoryTypeIndex = 0;
4909 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4910 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004912 ASSERT_TRUE(pass);
4913 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4914 ASSERT_VK_SUCCESS(err);
4915 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004918 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004919 VkClearColorValue ccv;
4920 ccv.float32[0] = 1.0f;
4921 ccv.float32[1] = 1.0f;
4922 ccv.float32[2] = 1.0f;
4923 ccv.float32[3] = 1.0f;
4924 VkImageSubresourceRange isr = {};
4925 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004926 isr.baseArrayLayer = 0;
4927 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004928 isr.layerCount = 1;
4929 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004931 m_commandBuffer->EndCommandBuffer();
4932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004934 // Destroy image dependency prior to submit to cause ERROR
4935 vkDestroyImage(m_device->device(), image, NULL);
4936
4937 VkSubmitInfo submit_info = {};
4938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4939 submit_info.commandBufferCount = 1;
4940 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4941 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4942
4943 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004944 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004945}
4946
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004947TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004948 TEST_DESCRIPTION(
4949 "Attempt to draw with a command buffer that is invalid "
4950 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004951 VkFormatProperties format_properties;
4952 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4954 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004955 return;
4956 }
4957
4958 ASSERT_NO_FATAL_FAILURE(InitState());
4959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4960
4961 VkImageCreateInfo image_ci = {};
4962 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4963 image_ci.pNext = NULL;
4964 image_ci.imageType = VK_IMAGE_TYPE_2D;
4965 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4966 image_ci.extent.width = 32;
4967 image_ci.extent.height = 32;
4968 image_ci.extent.depth = 1;
4969 image_ci.mipLevels = 1;
4970 image_ci.arrayLayers = 1;
4971 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4972 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004973 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4975 image_ci.flags = 0;
4976 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004977 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004978
4979 VkMemoryRequirements memory_reqs;
4980 VkDeviceMemory image_memory;
4981 bool pass;
4982 VkMemoryAllocateInfo memory_info = {};
4983 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4984 memory_info.pNext = NULL;
4985 memory_info.allocationSize = 0;
4986 memory_info.memoryTypeIndex = 0;
4987 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4988 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004989 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004990 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004991 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004992 ASSERT_VK_SUCCESS(err);
4993 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4994 ASSERT_VK_SUCCESS(err);
4995
4996 VkImageViewCreateInfo ivci = {
4997 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4998 nullptr,
4999 0,
5000 image,
5001 VK_IMAGE_VIEW_TYPE_2D,
5002 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005004 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5005 };
5006 VkImageView view;
5007 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5008 ASSERT_VK_SUCCESS(err);
5009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 VkFramebuffer fb;
5012 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 // Just use default renderpass with our framebuffer
5016 m_renderPassBeginInfo.framebuffer = fb;
5017 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005018 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005019 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07005020 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5021 m_commandBuffer->EndRenderPass();
5022 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 // Destroy image attached to framebuffer to invalidate cmd buffer
5024 vkDestroyImage(m_device->device(), image, NULL);
5025 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005027 QueueCommandBuffer(false);
5028 m_errorMonitor->VerifyFound();
5029
5030 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5031 vkDestroyImageView(m_device->device(), view, nullptr);
5032 vkFreeMemory(m_device->device(), image_memory, nullptr);
5033}
5034
Tobin Ehlisb329f992016-10-12 13:20:29 -06005035TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5036 TEST_DESCRIPTION("Delete in-use framebuffer.");
5037 VkFormatProperties format_properties;
5038 VkResult err = VK_SUCCESS;
5039 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5040
5041 ASSERT_NO_FATAL_FAILURE(InitState());
5042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5043
5044 VkImageObj image(m_device);
5045 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5046 ASSERT_TRUE(image.initialized());
5047 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5048
5049 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5050 VkFramebuffer fb;
5051 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5052 ASSERT_VK_SUCCESS(err);
5053
5054 // Just use default renderpass with our framebuffer
5055 m_renderPassBeginInfo.framebuffer = fb;
5056 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005057 m_commandBuffer->BeginCommandBuffer();
5058 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5059 m_commandBuffer->EndRenderPass();
5060 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005061 // Submit cmd buffer to put it in-flight
5062 VkSubmitInfo submit_info = {};
5063 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5064 submit_info.commandBufferCount = 1;
5065 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5067 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005069 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5070 m_errorMonitor->VerifyFound();
5071 // Wait for queue to complete so we can safely destroy everything
5072 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005073 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5074 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005075 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5076}
5077
Tobin Ehlis88becd72016-09-21 14:33:41 -06005078TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5079 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5080 VkFormatProperties format_properties;
5081 VkResult err = VK_SUCCESS;
5082 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005083
5084 ASSERT_NO_FATAL_FAILURE(InitState());
5085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5086
5087 VkImageCreateInfo image_ci = {};
5088 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5089 image_ci.pNext = NULL;
5090 image_ci.imageType = VK_IMAGE_TYPE_2D;
5091 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5092 image_ci.extent.width = 256;
5093 image_ci.extent.height = 256;
5094 image_ci.extent.depth = 1;
5095 image_ci.mipLevels = 1;
5096 image_ci.arrayLayers = 1;
5097 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5098 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005099 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005100 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5101 image_ci.flags = 0;
5102 VkImage image;
5103 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5104
5105 VkMemoryRequirements memory_reqs;
5106 VkDeviceMemory image_memory;
5107 bool pass;
5108 VkMemoryAllocateInfo memory_info = {};
5109 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5110 memory_info.pNext = NULL;
5111 memory_info.allocationSize = 0;
5112 memory_info.memoryTypeIndex = 0;
5113 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5114 memory_info.allocationSize = memory_reqs.size;
5115 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5116 ASSERT_TRUE(pass);
5117 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5118 ASSERT_VK_SUCCESS(err);
5119 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5120 ASSERT_VK_SUCCESS(err);
5121
5122 VkImageViewCreateInfo ivci = {
5123 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5124 nullptr,
5125 0,
5126 image,
5127 VK_IMAGE_VIEW_TYPE_2D,
5128 VK_FORMAT_B8G8R8A8_UNORM,
5129 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5130 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5131 };
5132 VkImageView view;
5133 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5134 ASSERT_VK_SUCCESS(err);
5135
5136 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5137 VkFramebuffer fb;
5138 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5139 ASSERT_VK_SUCCESS(err);
5140
5141 // Just use default renderpass with our framebuffer
5142 m_renderPassBeginInfo.framebuffer = fb;
5143 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005144 m_commandBuffer->BeginCommandBuffer();
5145 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5146 m_commandBuffer->EndRenderPass();
5147 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005148 // Submit cmd buffer to put it (and attached imageView) in-flight
5149 VkSubmitInfo submit_info = {};
5150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5151 submit_info.commandBufferCount = 1;
5152 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5153 // Submit cmd buffer to put framebuffer and children in-flight
5154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5155 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005157 vkDestroyImage(m_device->device(), image, NULL);
5158 m_errorMonitor->VerifyFound();
5159 // Wait for queue to complete so we can safely destroy image and other objects
5160 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005161 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5162 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005163 vkDestroyImage(m_device->device(), image, NULL);
5164 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5165 vkDestroyImageView(m_device->device(), view, nullptr);
5166 vkFreeMemory(m_device->device(), image_memory, nullptr);
5167}
5168
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005169TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5170 TEST_DESCRIPTION("Delete in-use renderPass.");
5171
5172 ASSERT_NO_FATAL_FAILURE(InitState());
5173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5174
5175 // Create simple renderpass
5176 VkAttachmentReference attach = {};
5177 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5178 VkSubpassDescription subpass = {};
5179 subpass.pColorAttachments = &attach;
5180 VkRenderPassCreateInfo rpci = {};
5181 rpci.subpassCount = 1;
5182 rpci.pSubpasses = &subpass;
5183 rpci.attachmentCount = 1;
5184 VkAttachmentDescription attach_desc = {};
5185 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5186 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5187 rpci.pAttachments = &attach_desc;
5188 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5189 VkRenderPass rp;
5190 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5191 ASSERT_VK_SUCCESS(err);
5192
5193 // Create a pipeline that uses the given renderpass
5194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5196
5197 VkPipelineLayout pipeline_layout;
5198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5199 ASSERT_VK_SUCCESS(err);
5200
5201 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5202 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5203 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005204 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005205 vp_state_ci.pViewports = &vp;
5206 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005207 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005208 vp_state_ci.pScissors = &scissors;
5209
5210 VkPipelineShaderStageCreateInfo shaderStages[2];
5211 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5212
5213 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005214 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005215 // but add it to be able to run on more devices
5216 shaderStages[0] = vs.GetStageCreateInfo();
5217 shaderStages[1] = fs.GetStageCreateInfo();
5218
5219 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5220 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5221
5222 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5223 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5224 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5225
5226 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5227 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5228 rs_ci.rasterizerDiscardEnable = true;
5229 rs_ci.lineWidth = 1.0f;
5230
5231 VkPipelineColorBlendAttachmentState att = {};
5232 att.blendEnable = VK_FALSE;
5233 att.colorWriteMask = 0xf;
5234
5235 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5236 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5237 cb_ci.attachmentCount = 1;
5238 cb_ci.pAttachments = &att;
5239
5240 VkGraphicsPipelineCreateInfo gp_ci = {};
5241 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5242 gp_ci.stageCount = 2;
5243 gp_ci.pStages = shaderStages;
5244 gp_ci.pVertexInputState = &vi_ci;
5245 gp_ci.pInputAssemblyState = &ia_ci;
5246 gp_ci.pViewportState = &vp_state_ci;
5247 gp_ci.pRasterizationState = &rs_ci;
5248 gp_ci.pColorBlendState = &cb_ci;
5249 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5250 gp_ci.layout = pipeline_layout;
5251 gp_ci.renderPass = rp;
5252
5253 VkPipelineCacheCreateInfo pc_ci = {};
5254 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5255
5256 VkPipeline pipeline;
5257 VkPipelineCache pipe_cache;
5258 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5259 ASSERT_VK_SUCCESS(err);
5260
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005261 m_errorMonitor->SetUnexpectedError(
5262 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5263 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005264 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5265 ASSERT_VK_SUCCESS(err);
5266 // Bind pipeline to cmd buffer, will also bind renderpass
5267 m_commandBuffer->BeginCommandBuffer();
5268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5269 m_commandBuffer->EndCommandBuffer();
5270
5271 VkSubmitInfo submit_info = {};
5272 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5273 submit_info.commandBufferCount = 1;
5274 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5275 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5276
5277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5278 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5279 m_errorMonitor->VerifyFound();
5280
5281 // Wait for queue to complete so we can safely destroy everything
5282 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005283 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5284 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005285 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5286 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5287 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5289}
5290
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005291TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005293 ASSERT_NO_FATAL_FAILURE(InitState());
5294
5295 VkImage image;
5296 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5297 VkImageCreateInfo image_create_info = {};
5298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5299 image_create_info.pNext = NULL;
5300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5301 image_create_info.format = tex_format;
5302 image_create_info.extent.width = 32;
5303 image_create_info.extent.height = 32;
5304 image_create_info.extent.depth = 1;
5305 image_create_info.mipLevels = 1;
5306 image_create_info.arrayLayers = 1;
5307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5308 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005310 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005311 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005312 ASSERT_VK_SUCCESS(err);
5313 // Have to bind memory to image before recording cmd in cmd buffer using it
5314 VkMemoryRequirements mem_reqs;
5315 VkDeviceMemory image_mem;
5316 bool pass;
5317 VkMemoryAllocateInfo mem_alloc = {};
5318 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5319 mem_alloc.pNext = NULL;
5320 mem_alloc.memoryTypeIndex = 0;
5321 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5322 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005324 ASSERT_TRUE(pass);
5325 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5326 ASSERT_VK_SUCCESS(err);
5327
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005328 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005330 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005331
5332 m_commandBuffer->BeginCommandBuffer();
5333 VkClearColorValue ccv;
5334 ccv.float32[0] = 1.0f;
5335 ccv.float32[1] = 1.0f;
5336 ccv.float32[2] = 1.0f;
5337 ccv.float32[3] = 1.0f;
5338 VkImageSubresourceRange isr = {};
5339 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5340 isr.baseArrayLayer = 0;
5341 isr.baseMipLevel = 0;
5342 isr.layerCount = 1;
5343 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005344 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005345 m_commandBuffer->EndCommandBuffer();
5346
5347 m_errorMonitor->VerifyFound();
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 vkFreeMemory(m_device->device(), image_mem, nullptr);
5350}
5351
5352TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005353 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005354 ASSERT_NO_FATAL_FAILURE(InitState());
5355
5356 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005357 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005358 VK_IMAGE_TILING_OPTIMAL, 0);
5359 ASSERT_TRUE(image.initialized());
5360
5361 VkBuffer buffer;
5362 VkDeviceMemory mem;
5363 VkMemoryRequirements mem_reqs;
5364
5365 VkBufferCreateInfo buf_info = {};
5366 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005367 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005368 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005369 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5370 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5371 ASSERT_VK_SUCCESS(err);
5372
5373 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5374
5375 VkMemoryAllocateInfo alloc_info = {};
5376 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005377 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005378 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005379 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005380 if (!pass) {
5381 vkDestroyBuffer(m_device->device(), buffer, NULL);
5382 return;
5383 }
5384 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5385 ASSERT_VK_SUCCESS(err);
5386
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005387 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005389 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005390 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005391 region.bufferRowLength = 16;
5392 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005393 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5394
5395 region.imageSubresource.layerCount = 1;
5396 region.imageExtent.height = 4;
5397 region.imageExtent.width = 4;
5398 region.imageExtent.depth = 1;
5399 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5401 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005402 m_commandBuffer->EndCommandBuffer();
5403
5404 m_errorMonitor->VerifyFound();
5405
5406 vkDestroyBuffer(m_device->device(), buffer, NULL);
5407 vkFreeMemory(m_device->handle(), mem, NULL);
5408}
5409
Tobin Ehlis85940f52016-07-07 16:57:21 -06005410TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005411 TEST_DESCRIPTION(
5412 "Attempt to draw with a command buffer that is invalid "
5413 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005414 ASSERT_NO_FATAL_FAILURE(InitState());
5415
5416 VkEvent event;
5417 VkEventCreateInfo evci = {};
5418 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5419 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5420 ASSERT_VK_SUCCESS(result);
5421
5422 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005423 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005424 m_commandBuffer->EndCommandBuffer();
5425
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005427 // Destroy event dependency prior to submit to cause ERROR
5428 vkDestroyEvent(m_device->device(), event, NULL);
5429
5430 VkSubmitInfo submit_info = {};
5431 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5432 submit_info.commandBufferCount = 1;
5433 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5434 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5435
5436 m_errorMonitor->VerifyFound();
5437}
5438
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005439TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005440 TEST_DESCRIPTION(
5441 "Attempt to draw with a command buffer that is invalid "
5442 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005443 ASSERT_NO_FATAL_FAILURE(InitState());
5444
5445 VkQueryPool query_pool;
5446 VkQueryPoolCreateInfo qpci{};
5447 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5448 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5449 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005450 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005451 ASSERT_VK_SUCCESS(result);
5452
5453 m_commandBuffer->BeginCommandBuffer();
5454 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5455 m_commandBuffer->EndCommandBuffer();
5456
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005458 // Destroy query pool dependency prior to submit to cause ERROR
5459 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5460
5461 VkSubmitInfo submit_info = {};
5462 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5463 submit_info.commandBufferCount = 1;
5464 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5465 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5466
5467 m_errorMonitor->VerifyFound();
5468}
5469
Tobin Ehlis24130d92016-07-08 15:50:53 -06005470TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005471 TEST_DESCRIPTION(
5472 "Attempt to draw with a command buffer that is invalid "
5473 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005474 ASSERT_NO_FATAL_FAILURE(InitState());
5475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5476
5477 VkResult err;
5478
5479 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5480 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5481
5482 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005483 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005484 ASSERT_VK_SUCCESS(err);
5485
5486 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5487 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5488 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005489 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005490 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005491 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005492 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005493 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494
5495 VkPipelineShaderStageCreateInfo shaderStages[2];
5496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005500 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005501 shaderStages[0] = vs.GetStageCreateInfo();
5502 shaderStages[1] = fs.GetStageCreateInfo();
5503
5504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5506
5507 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5508 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5509 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5510
5511 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5512 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005513 rs_ci.rasterizerDiscardEnable = true;
5514 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005515
5516 VkPipelineColorBlendAttachmentState att = {};
5517 att.blendEnable = VK_FALSE;
5518 att.colorWriteMask = 0xf;
5519
5520 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5521 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5522 cb_ci.attachmentCount = 1;
5523 cb_ci.pAttachments = &att;
5524
5525 VkGraphicsPipelineCreateInfo gp_ci = {};
5526 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5527 gp_ci.stageCount = 2;
5528 gp_ci.pStages = shaderStages;
5529 gp_ci.pVertexInputState = &vi_ci;
5530 gp_ci.pInputAssemblyState = &ia_ci;
5531 gp_ci.pViewportState = &vp_state_ci;
5532 gp_ci.pRasterizationState = &rs_ci;
5533 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005534 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5535 gp_ci.layout = pipeline_layout;
5536 gp_ci.renderPass = renderPass();
5537
5538 VkPipelineCacheCreateInfo pc_ci = {};
5539 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5540
5541 VkPipeline pipeline;
5542 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005543 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005544 ASSERT_VK_SUCCESS(err);
5545
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005546 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005547 ASSERT_VK_SUCCESS(err);
5548
5549 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005550 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005551 m_commandBuffer->EndCommandBuffer();
5552 // Now destroy pipeline in order to cause error when submitting
5553 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005556
5557 VkSubmitInfo submit_info = {};
5558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5559 submit_info.commandBufferCount = 1;
5560 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5561 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5562
5563 m_errorMonitor->VerifyFound();
5564 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5566}
5567
Tobin Ehlis31289162016-08-17 14:57:58 -06005568TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005569 TEST_DESCRIPTION(
5570 "Attempt to draw with a command buffer that is invalid "
5571 "due to a bound descriptor set with a buffer dependency "
5572 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005573 ASSERT_NO_FATAL_FAILURE(InitState());
5574 ASSERT_NO_FATAL_FAILURE(InitViewport());
5575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5576
5577 VkDescriptorPoolSize ds_type_count = {};
5578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5579 ds_type_count.descriptorCount = 1;
5580
5581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5583 ds_pool_ci.pNext = NULL;
5584 ds_pool_ci.maxSets = 1;
5585 ds_pool_ci.poolSizeCount = 1;
5586 ds_pool_ci.pPoolSizes = &ds_type_count;
5587
5588 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005589 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005590 ASSERT_VK_SUCCESS(err);
5591
5592 VkDescriptorSetLayoutBinding dsl_binding = {};
5593 dsl_binding.binding = 0;
5594 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5595 dsl_binding.descriptorCount = 1;
5596 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5597 dsl_binding.pImmutableSamplers = NULL;
5598
5599 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5600 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5601 ds_layout_ci.pNext = NULL;
5602 ds_layout_ci.bindingCount = 1;
5603 ds_layout_ci.pBindings = &dsl_binding;
5604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005606 ASSERT_VK_SUCCESS(err);
5607
5608 VkDescriptorSet descriptorSet;
5609 VkDescriptorSetAllocateInfo alloc_info = {};
5610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5611 alloc_info.descriptorSetCount = 1;
5612 alloc_info.descriptorPool = ds_pool;
5613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005615 ASSERT_VK_SUCCESS(err);
5616
5617 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5618 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5619 pipeline_layout_ci.pNext = NULL;
5620 pipeline_layout_ci.setLayoutCount = 1;
5621 pipeline_layout_ci.pSetLayouts = &ds_layout;
5622
5623 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005625 ASSERT_VK_SUCCESS(err);
5626
5627 // Create a buffer to update the descriptor with
5628 uint32_t qfi = 0;
5629 VkBufferCreateInfo buffCI = {};
5630 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5631 buffCI.size = 1024;
5632 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5633 buffCI.queueFamilyIndexCount = 1;
5634 buffCI.pQueueFamilyIndices = &qfi;
5635
5636 VkBuffer buffer;
5637 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5638 ASSERT_VK_SUCCESS(err);
5639 // Allocate memory and bind to buffer so we can make it to the appropriate
5640 // error
5641 VkMemoryAllocateInfo mem_alloc = {};
5642 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5643 mem_alloc.pNext = NULL;
5644 mem_alloc.allocationSize = 1024;
5645 mem_alloc.memoryTypeIndex = 0;
5646
5647 VkMemoryRequirements memReqs;
5648 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 if (!pass) {
5651 vkDestroyBuffer(m_device->device(), buffer, NULL);
5652 return;
5653 }
5654
5655 VkDeviceMemory mem;
5656 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5657 ASSERT_VK_SUCCESS(err);
5658 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5659 ASSERT_VK_SUCCESS(err);
5660 // Correctly update descriptor to avoid "NOT_UPDATED" error
5661 VkDescriptorBufferInfo buffInfo = {};
5662 buffInfo.buffer = buffer;
5663 buffInfo.offset = 0;
5664 buffInfo.range = 1024;
5665
5666 VkWriteDescriptorSet descriptor_write;
5667 memset(&descriptor_write, 0, sizeof(descriptor_write));
5668 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5669 descriptor_write.dstSet = descriptorSet;
5670 descriptor_write.dstBinding = 0;
5671 descriptor_write.descriptorCount = 1;
5672 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5673 descriptor_write.pBufferInfo = &buffInfo;
5674
5675 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5676
5677 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005678 char const *vsSource =
5679 "#version 450\n"
5680 "\n"
5681 "out gl_PerVertex { \n"
5682 " vec4 gl_Position;\n"
5683 "};\n"
5684 "void main(){\n"
5685 " gl_Position = vec4(1);\n"
5686 "}\n";
5687 char const *fsSource =
5688 "#version 450\n"
5689 "\n"
5690 "layout(location=0) out vec4 x;\n"
5691 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5692 "void main(){\n"
5693 " x = vec4(bar.y);\n"
5694 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005695 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5696 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
5699 pipe.AddShader(&fs);
5700 pipe.AddColorAttachment();
5701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5702
Tony Barbour552f6c02016-12-21 14:34:07 -07005703 m_commandBuffer->BeginCommandBuffer();
5704 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005705 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5707 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005708
5709 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5710 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5711
Tobin Ehlis31289162016-08-17 14:57:58 -06005712 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005713 m_commandBuffer->EndRenderPass();
5714 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005716 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5717 vkDestroyBuffer(m_device->device(), buffer, NULL);
5718 // Attempt to submit cmd buffer
5719 VkSubmitInfo submit_info = {};
5720 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5721 submit_info.commandBufferCount = 1;
5722 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5723 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5724 m_errorMonitor->VerifyFound();
5725 // Cleanup
5726 vkFreeMemory(m_device->device(), mem, NULL);
5727
5728 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5731}
5732
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005733TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005734 TEST_DESCRIPTION(
5735 "Attempt to draw with a command buffer that is invalid "
5736 "due to a bound descriptor sets with a combined image "
5737 "sampler having their image, sampler, and descriptor set "
5738 "each respectively destroyed and then attempting to "
5739 "submit associated cmd buffers. Attempt to destroy a "
5740 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005741 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005742 ASSERT_NO_FATAL_FAILURE(InitViewport());
5743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5744
5745 VkDescriptorPoolSize ds_type_count = {};
5746 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5747 ds_type_count.descriptorCount = 1;
5748
5749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5751 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005752 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753 ds_pool_ci.maxSets = 1;
5754 ds_pool_ci.poolSizeCount = 1;
5755 ds_pool_ci.pPoolSizes = &ds_type_count;
5756
5757 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005758 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005759 ASSERT_VK_SUCCESS(err);
5760
5761 VkDescriptorSetLayoutBinding dsl_binding = {};
5762 dsl_binding.binding = 0;
5763 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5764 dsl_binding.descriptorCount = 1;
5765 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5766 dsl_binding.pImmutableSamplers = NULL;
5767
5768 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5769 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5770 ds_layout_ci.pNext = NULL;
5771 ds_layout_ci.bindingCount = 1;
5772 ds_layout_ci.pBindings = &dsl_binding;
5773 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005775 ASSERT_VK_SUCCESS(err);
5776
5777 VkDescriptorSet descriptorSet;
5778 VkDescriptorSetAllocateInfo alloc_info = {};
5779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5780 alloc_info.descriptorSetCount = 1;
5781 alloc_info.descriptorPool = ds_pool;
5782 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005784 ASSERT_VK_SUCCESS(err);
5785
5786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5788 pipeline_layout_ci.pNext = NULL;
5789 pipeline_layout_ci.setLayoutCount = 1;
5790 pipeline_layout_ci.pSetLayouts = &ds_layout;
5791
5792 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005794 ASSERT_VK_SUCCESS(err);
5795
5796 // Create images to update the descriptor with
5797 VkImage image;
5798 VkImage image2;
5799 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5800 const int32_t tex_width = 32;
5801 const int32_t tex_height = 32;
5802 VkImageCreateInfo image_create_info = {};
5803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5804 image_create_info.pNext = NULL;
5805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5806 image_create_info.format = tex_format;
5807 image_create_info.extent.width = tex_width;
5808 image_create_info.extent.height = tex_height;
5809 image_create_info.extent.depth = 1;
5810 image_create_info.mipLevels = 1;
5811 image_create_info.arrayLayers = 1;
5812 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5813 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5814 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5815 image_create_info.flags = 0;
5816 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5817 ASSERT_VK_SUCCESS(err);
5818 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5819 ASSERT_VK_SUCCESS(err);
5820
5821 VkMemoryRequirements memory_reqs;
5822 VkDeviceMemory image_memory;
5823 bool pass;
5824 VkMemoryAllocateInfo memory_info = {};
5825 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5826 memory_info.pNext = NULL;
5827 memory_info.allocationSize = 0;
5828 memory_info.memoryTypeIndex = 0;
5829 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5830 // Allocate enough memory for both images
5831 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005832 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005833 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005835 ASSERT_VK_SUCCESS(err);
5836 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5837 ASSERT_VK_SUCCESS(err);
5838 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005839 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005840 ASSERT_VK_SUCCESS(err);
5841
5842 VkImageViewCreateInfo image_view_create_info = {};
5843 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5844 image_view_create_info.image = image;
5845 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5846 image_view_create_info.format = tex_format;
5847 image_view_create_info.subresourceRange.layerCount = 1;
5848 image_view_create_info.subresourceRange.baseMipLevel = 0;
5849 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005851
5852 VkImageView view;
5853 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005857 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005858 ASSERT_VK_SUCCESS(err);
5859 // Create Samplers
5860 VkSamplerCreateInfo sampler_ci = {};
5861 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5862 sampler_ci.pNext = NULL;
5863 sampler_ci.magFilter = VK_FILTER_NEAREST;
5864 sampler_ci.minFilter = VK_FILTER_NEAREST;
5865 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5866 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5867 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5868 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5869 sampler_ci.mipLodBias = 1.0;
5870 sampler_ci.anisotropyEnable = VK_FALSE;
5871 sampler_ci.maxAnisotropy = 1;
5872 sampler_ci.compareEnable = VK_FALSE;
5873 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5874 sampler_ci.minLod = 1.0;
5875 sampler_ci.maxLod = 1.0;
5876 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5877 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5878 VkSampler sampler;
5879 VkSampler sampler2;
5880 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5881 ASSERT_VK_SUCCESS(err);
5882 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5883 ASSERT_VK_SUCCESS(err);
5884 // Update descriptor with image and sampler
5885 VkDescriptorImageInfo img_info = {};
5886 img_info.sampler = sampler;
5887 img_info.imageView = view;
5888 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5889
5890 VkWriteDescriptorSet descriptor_write;
5891 memset(&descriptor_write, 0, sizeof(descriptor_write));
5892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5893 descriptor_write.dstSet = descriptorSet;
5894 descriptor_write.dstBinding = 0;
5895 descriptor_write.descriptorCount = 1;
5896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5897 descriptor_write.pImageInfo = &img_info;
5898
5899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5900
5901 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005902 char const *vsSource =
5903 "#version 450\n"
5904 "\n"
5905 "out gl_PerVertex { \n"
5906 " vec4 gl_Position;\n"
5907 "};\n"
5908 "void main(){\n"
5909 " gl_Position = vec4(1);\n"
5910 "}\n";
5911 char const *fsSource =
5912 "#version 450\n"
5913 "\n"
5914 "layout(set=0, binding=0) uniform sampler2D s;\n"
5915 "layout(location=0) out vec4 x;\n"
5916 "void main(){\n"
5917 " x = texture(s, vec2(1));\n"
5918 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5921 VkPipelineObj pipe(m_device);
5922 pipe.AddShader(&vs);
5923 pipe.AddShader(&fs);
5924 pipe.AddColorAttachment();
5925 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5926
5927 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005929 m_commandBuffer->BeginCommandBuffer();
5930 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005931 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5932 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5933 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005934 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5935 VkRect2D scissor = {{0, 0}, {16, 16}};
5936 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5937 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005938 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005939 m_commandBuffer->EndRenderPass();
5940 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005941 // Destroy sampler invalidates the cmd buffer, causing error on submit
5942 vkDestroySampler(m_device->device(), sampler, NULL);
5943 // Attempt to submit cmd buffer
5944 VkSubmitInfo submit_info = {};
5945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5946 submit_info.commandBufferCount = 1;
5947 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5948 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5949 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005950
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005951 // Now re-update descriptor with valid sampler and delete image
5952 img_info.sampler = sampler2;
5953 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005954
5955 VkCommandBufferBeginInfo info = {};
5956 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5957 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005960 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005961 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005962 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5963 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5964 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005965 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5966 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005967 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005968 m_commandBuffer->EndRenderPass();
5969 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005970 // Destroy image invalidates the cmd buffer, causing error on submit
5971 vkDestroyImage(m_device->device(), image, NULL);
5972 // Attempt to submit cmd buffer
5973 submit_info = {};
5974 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5975 submit_info.commandBufferCount = 1;
5976 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5978 m_errorMonitor->VerifyFound();
5979 // Now update descriptor to be valid, but then free descriptor
5980 img_info.imageView = view2;
5981 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005982 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005983 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005984 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5985 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5986 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005987 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5988 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005989 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005990 m_commandBuffer->EndRenderPass();
5991 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005993
5994 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005996 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005997 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005998
5999 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006000 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07006001 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006002 m_errorMonitor->SetUnexpectedError(
6003 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6004 "either be a valid handle or VK_NULL_HANDLE");
6005 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006006 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6007
6008 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 submit_info = {};
6010 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6011 submit_info.commandBufferCount = 1;
6012 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6015 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006016
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006017 // Cleanup
6018 vkFreeMemory(m_device->device(), image_memory, NULL);
6019 vkDestroySampler(m_device->device(), sampler2, NULL);
6020 vkDestroyImage(m_device->device(), image2, NULL);
6021 vkDestroyImageView(m_device->device(), view, NULL);
6022 vkDestroyImageView(m_device->device(), view2, NULL);
6023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6026}
6027
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006028TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6029 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6030 ASSERT_NO_FATAL_FAILURE(InitState());
6031 ASSERT_NO_FATAL_FAILURE(InitViewport());
6032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6033
6034 VkDescriptorPoolSize ds_type_count = {};
6035 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6036 ds_type_count.descriptorCount = 1;
6037
6038 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6039 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6040 ds_pool_ci.pNext = NULL;
6041 ds_pool_ci.maxSets = 1;
6042 ds_pool_ci.poolSizeCount = 1;
6043 ds_pool_ci.pPoolSizes = &ds_type_count;
6044
6045 VkDescriptorPool ds_pool;
6046 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6047 ASSERT_VK_SUCCESS(err);
6048
6049 VkDescriptorSetLayoutBinding dsl_binding = {};
6050 dsl_binding.binding = 0;
6051 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6052 dsl_binding.descriptorCount = 1;
6053 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6054 dsl_binding.pImmutableSamplers = NULL;
6055
6056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6058 ds_layout_ci.pNext = NULL;
6059 ds_layout_ci.bindingCount = 1;
6060 ds_layout_ci.pBindings = &dsl_binding;
6061 VkDescriptorSetLayout ds_layout;
6062 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6063 ASSERT_VK_SUCCESS(err);
6064
6065 VkDescriptorSet descriptor_set;
6066 VkDescriptorSetAllocateInfo alloc_info = {};
6067 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6068 alloc_info.descriptorSetCount = 1;
6069 alloc_info.descriptorPool = ds_pool;
6070 alloc_info.pSetLayouts = &ds_layout;
6071 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6072 ASSERT_VK_SUCCESS(err);
6073
6074 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6075 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6076 pipeline_layout_ci.pNext = NULL;
6077 pipeline_layout_ci.setLayoutCount = 1;
6078 pipeline_layout_ci.pSetLayouts = &ds_layout;
6079
6080 VkPipelineLayout pipeline_layout;
6081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6082 ASSERT_VK_SUCCESS(err);
6083
6084 // Create image to update the descriptor with
6085 VkImageObj image(m_device);
6086 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6087 ASSERT_TRUE(image.initialized());
6088
6089 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6090 // Create Sampler
6091 VkSamplerCreateInfo sampler_ci = {};
6092 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6093 sampler_ci.pNext = NULL;
6094 sampler_ci.magFilter = VK_FILTER_NEAREST;
6095 sampler_ci.minFilter = VK_FILTER_NEAREST;
6096 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6097 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6098 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6099 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6100 sampler_ci.mipLodBias = 1.0;
6101 sampler_ci.anisotropyEnable = VK_FALSE;
6102 sampler_ci.maxAnisotropy = 1;
6103 sampler_ci.compareEnable = VK_FALSE;
6104 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6105 sampler_ci.minLod = 1.0;
6106 sampler_ci.maxLod = 1.0;
6107 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6108 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6109 VkSampler sampler;
6110 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6111 ASSERT_VK_SUCCESS(err);
6112 // Update descriptor with image and sampler
6113 VkDescriptorImageInfo img_info = {};
6114 img_info.sampler = sampler;
6115 img_info.imageView = view;
6116 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6117
6118 VkWriteDescriptorSet descriptor_write;
6119 memset(&descriptor_write, 0, sizeof(descriptor_write));
6120 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6121 descriptor_write.dstSet = descriptor_set;
6122 descriptor_write.dstBinding = 0;
6123 descriptor_write.descriptorCount = 1;
6124 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6125 descriptor_write.pImageInfo = &img_info;
6126
6127 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6128
6129 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006130 char const *vsSource =
6131 "#version 450\n"
6132 "\n"
6133 "out gl_PerVertex { \n"
6134 " vec4 gl_Position;\n"
6135 "};\n"
6136 "void main(){\n"
6137 " gl_Position = vec4(1);\n"
6138 "}\n";
6139 char const *fsSource =
6140 "#version 450\n"
6141 "\n"
6142 "layout(set=0, binding=0) uniform sampler2D s;\n"
6143 "layout(location=0) out vec4 x;\n"
6144 "void main(){\n"
6145 " x = texture(s, vec2(1));\n"
6146 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006147 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6148 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6149 VkPipelineObj pipe(m_device);
6150 pipe.AddShader(&vs);
6151 pipe.AddShader(&fs);
6152 pipe.AddColorAttachment();
6153 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6154
Tony Barbour552f6c02016-12-21 14:34:07 -07006155 m_commandBuffer->BeginCommandBuffer();
6156 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006157 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6158 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6159 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006160
6161 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6162 VkRect2D scissor = {{0, 0}, {16, 16}};
6163 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6164 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6165
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006166 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006167 m_commandBuffer->EndRenderPass();
6168 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006169 // Submit cmd buffer to put pool in-flight
6170 VkSubmitInfo submit_info = {};
6171 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6172 submit_info.commandBufferCount = 1;
6173 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6175 // Destroy pool while in-flight, causing error
6176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6177 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6178 m_errorMonitor->VerifyFound();
6179 vkQueueWaitIdle(m_device->m_queue);
6180 // Cleanup
6181 vkDestroySampler(m_device->device(), sampler, NULL);
6182 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6183 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006184 m_errorMonitor->SetUnexpectedError(
6185 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6186 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006187 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006188 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189}
6190
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006191TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6192 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6193 ASSERT_NO_FATAL_FAILURE(InitState());
6194 ASSERT_NO_FATAL_FAILURE(InitViewport());
6195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6196
6197 VkDescriptorPoolSize ds_type_count = {};
6198 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6199 ds_type_count.descriptorCount = 1;
6200
6201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6203 ds_pool_ci.pNext = NULL;
6204 ds_pool_ci.maxSets = 1;
6205 ds_pool_ci.poolSizeCount = 1;
6206 ds_pool_ci.pPoolSizes = &ds_type_count;
6207
6208 VkDescriptorPool ds_pool;
6209 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6210 ASSERT_VK_SUCCESS(err);
6211
6212 VkDescriptorSetLayoutBinding dsl_binding = {};
6213 dsl_binding.binding = 0;
6214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6215 dsl_binding.descriptorCount = 1;
6216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6217 dsl_binding.pImmutableSamplers = NULL;
6218
6219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6221 ds_layout_ci.pNext = NULL;
6222 ds_layout_ci.bindingCount = 1;
6223 ds_layout_ci.pBindings = &dsl_binding;
6224 VkDescriptorSetLayout ds_layout;
6225 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6226 ASSERT_VK_SUCCESS(err);
6227
6228 VkDescriptorSet descriptorSet;
6229 VkDescriptorSetAllocateInfo alloc_info = {};
6230 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6231 alloc_info.descriptorSetCount = 1;
6232 alloc_info.descriptorPool = ds_pool;
6233 alloc_info.pSetLayouts = &ds_layout;
6234 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6235 ASSERT_VK_SUCCESS(err);
6236
6237 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6238 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6239 pipeline_layout_ci.pNext = NULL;
6240 pipeline_layout_ci.setLayoutCount = 1;
6241 pipeline_layout_ci.pSetLayouts = &ds_layout;
6242
6243 VkPipelineLayout pipeline_layout;
6244 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6245 ASSERT_VK_SUCCESS(err);
6246
6247 // Create images to update the descriptor with
6248 VkImage image;
6249 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6250 const int32_t tex_width = 32;
6251 const int32_t tex_height = 32;
6252 VkImageCreateInfo image_create_info = {};
6253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6254 image_create_info.pNext = NULL;
6255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6256 image_create_info.format = tex_format;
6257 image_create_info.extent.width = tex_width;
6258 image_create_info.extent.height = tex_height;
6259 image_create_info.extent.depth = 1;
6260 image_create_info.mipLevels = 1;
6261 image_create_info.arrayLayers = 1;
6262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6264 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6265 image_create_info.flags = 0;
6266 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6267 ASSERT_VK_SUCCESS(err);
6268 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6269 VkMemoryRequirements memory_reqs;
6270 VkDeviceMemory image_memory;
6271 bool pass;
6272 VkMemoryAllocateInfo memory_info = {};
6273 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6274 memory_info.pNext = NULL;
6275 memory_info.allocationSize = 0;
6276 memory_info.memoryTypeIndex = 0;
6277 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6278 // Allocate enough memory for image
6279 memory_info.allocationSize = memory_reqs.size;
6280 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6281 ASSERT_TRUE(pass);
6282 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6283 ASSERT_VK_SUCCESS(err);
6284 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6285 ASSERT_VK_SUCCESS(err);
6286
6287 VkImageViewCreateInfo image_view_create_info = {};
6288 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6289 image_view_create_info.image = image;
6290 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6291 image_view_create_info.format = tex_format;
6292 image_view_create_info.subresourceRange.layerCount = 1;
6293 image_view_create_info.subresourceRange.baseMipLevel = 0;
6294 image_view_create_info.subresourceRange.levelCount = 1;
6295 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6296
6297 VkImageView view;
6298 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6299 ASSERT_VK_SUCCESS(err);
6300 // Create Samplers
6301 VkSamplerCreateInfo sampler_ci = {};
6302 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6303 sampler_ci.pNext = NULL;
6304 sampler_ci.magFilter = VK_FILTER_NEAREST;
6305 sampler_ci.minFilter = VK_FILTER_NEAREST;
6306 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6307 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6308 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6309 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6310 sampler_ci.mipLodBias = 1.0;
6311 sampler_ci.anisotropyEnable = VK_FALSE;
6312 sampler_ci.maxAnisotropy = 1;
6313 sampler_ci.compareEnable = VK_FALSE;
6314 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6315 sampler_ci.minLod = 1.0;
6316 sampler_ci.maxLod = 1.0;
6317 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6318 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6319 VkSampler sampler;
6320 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6321 ASSERT_VK_SUCCESS(err);
6322 // Update descriptor with image and sampler
6323 VkDescriptorImageInfo img_info = {};
6324 img_info.sampler = sampler;
6325 img_info.imageView = view;
6326 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6327
6328 VkWriteDescriptorSet descriptor_write;
6329 memset(&descriptor_write, 0, sizeof(descriptor_write));
6330 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6331 descriptor_write.dstSet = descriptorSet;
6332 descriptor_write.dstBinding = 0;
6333 descriptor_write.descriptorCount = 1;
6334 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6335 descriptor_write.pImageInfo = &img_info;
6336 // Break memory binding and attempt update
6337 vkFreeMemory(m_device->device(), image_memory, nullptr);
6338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006339 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6341 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6342 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6343 m_errorMonitor->VerifyFound();
6344 // Cleanup
6345 vkDestroyImage(m_device->device(), image, NULL);
6346 vkDestroySampler(m_device->device(), sampler, NULL);
6347 vkDestroyImageView(m_device->device(), view, NULL);
6348 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6349 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6350 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6351}
6352
Karl Schultz6addd812016-02-02 17:17:23 -07006353TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006354 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6355 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006356 // Create a valid cmd buffer
6357 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006358 uint64_t fake_pipeline_handle = 0xbaad6001;
6359 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006360 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6362
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006364 m_commandBuffer->BeginCommandBuffer();
6365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006367 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006368
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006369 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006371 Draw(1, 0, 0, 0);
6372 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006373
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006374 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006376 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006377 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6378 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006379}
6380
Karl Schultz6addd812016-02-02 17:17:23 -07006381TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006382 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006383 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006386
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006387 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006388 ASSERT_NO_FATAL_FAILURE(InitViewport());
6389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006390 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006391 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6392 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006393
6394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6396 ds_pool_ci.pNext = NULL;
6397 ds_pool_ci.maxSets = 1;
6398 ds_pool_ci.poolSizeCount = 1;
6399 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006400
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006401 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006403 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Tony Barboureb254902015-07-15 12:50:33 -06006405 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006406 dsl_binding.binding = 0;
6407 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6408 dsl_binding.descriptorCount = 1;
6409 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6410 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006411
Tony Barboureb254902015-07-15 12:50:33 -06006412 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006413 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6414 ds_layout_ci.pNext = NULL;
6415 ds_layout_ci.bindingCount = 1;
6416 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006417 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006419 ASSERT_VK_SUCCESS(err);
6420
6421 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006422 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006423 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006424 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006425 alloc_info.descriptorPool = ds_pool;
6426 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006427 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006428 ASSERT_VK_SUCCESS(err);
6429
Tony Barboureb254902015-07-15 12:50:33 -06006430 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006431 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6432 pipeline_layout_ci.pNext = NULL;
6433 pipeline_layout_ci.setLayoutCount = 1;
6434 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006435
6436 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006438 ASSERT_VK_SUCCESS(err);
6439
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006441 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006442 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006444
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006445 VkPipelineObj pipe(m_device);
6446 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006447 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006448 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006449 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006450
Tony Barbour552f6c02016-12-21 14:34:07 -07006451 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6453 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6454 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006456 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006457
Chia-I Wuf7458c52015-10-26 21:10:41 +08006458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006461}
6462
Karl Schultz6addd812016-02-02 17:17:23 -07006463TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006464 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006465 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006466
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006468
6469 ASSERT_NO_FATAL_FAILURE(InitState());
6470 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006471 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6472 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006473
6474 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6476 ds_pool_ci.pNext = NULL;
6477 ds_pool_ci.maxSets = 1;
6478 ds_pool_ci.poolSizeCount = 1;
6479 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006480
6481 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006483 ASSERT_VK_SUCCESS(err);
6484
6485 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006486 dsl_binding.binding = 0;
6487 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6488 dsl_binding.descriptorCount = 1;
6489 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6490 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006491
6492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6494 ds_layout_ci.pNext = NULL;
6495 ds_layout_ci.bindingCount = 1;
6496 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006497 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006498 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006499 ASSERT_VK_SUCCESS(err);
6500
6501 VkDescriptorSet descriptorSet;
6502 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006503 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006504 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006505 alloc_info.descriptorPool = ds_pool;
6506 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006508 ASSERT_VK_SUCCESS(err);
6509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006510 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511 VkWriteDescriptorSet descriptor_write;
6512 memset(&descriptor_write, 0, sizeof(descriptor_write));
6513 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6514 descriptor_write.dstSet = descriptorSet;
6515 descriptor_write.dstBinding = 0;
6516 descriptor_write.descriptorCount = 1;
6517 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6518 descriptor_write.pTexelBufferView = &view;
6519
6520 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6521
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006522 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006523
6524 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6525 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6526}
6527
Mark Youngd339ba32016-05-30 13:28:35 -06006528TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006529 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06006530
6531 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006533 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006534
6535 ASSERT_NO_FATAL_FAILURE(InitState());
6536
6537 // Create a buffer with no bound memory and then attempt to create
6538 // a buffer view.
6539 VkBufferCreateInfo buff_ci = {};
6540 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006541 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006542 buff_ci.size = 256;
6543 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6544 VkBuffer buffer;
6545 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6546 ASSERT_VK_SUCCESS(err);
6547
6548 VkBufferViewCreateInfo buff_view_ci = {};
6549 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6550 buff_view_ci.buffer = buffer;
6551 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6552 buff_view_ci.range = VK_WHOLE_SIZE;
6553 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006555
6556 m_errorMonitor->VerifyFound();
6557 vkDestroyBuffer(m_device->device(), buffer, NULL);
6558 // If last error is success, it still created the view, so delete it.
6559 if (err == VK_SUCCESS) {
6560 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6561 }
6562}
6563
Karl Schultz6addd812016-02-02 17:17:23 -07006564TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6565 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6566 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006567 // 1. No dynamicOffset supplied
6568 // 2. Too many dynamicOffsets supplied
6569 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006570 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6572 " requires 1 dynamicOffsets, but only "
6573 "0 dynamicOffsets are left in "
6574 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006575
6576 ASSERT_NO_FATAL_FAILURE(InitState());
6577 ASSERT_NO_FATAL_FAILURE(InitViewport());
6578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6579
6580 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006581 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6582 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006583
6584 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006585 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6586 ds_pool_ci.pNext = NULL;
6587 ds_pool_ci.maxSets = 1;
6588 ds_pool_ci.poolSizeCount = 1;
6589 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006590
6591 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006592 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006593 ASSERT_VK_SUCCESS(err);
6594
6595 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006596 dsl_binding.binding = 0;
6597 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6598 dsl_binding.descriptorCount = 1;
6599 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6600 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006601
6602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6604 ds_layout_ci.pNext = NULL;
6605 ds_layout_ci.bindingCount = 1;
6606 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006607 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006609 ASSERT_VK_SUCCESS(err);
6610
6611 VkDescriptorSet descriptorSet;
6612 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006614 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006615 alloc_info.descriptorPool = ds_pool;
6616 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006618 ASSERT_VK_SUCCESS(err);
6619
6620 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006621 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6622 pipeline_layout_ci.pNext = NULL;
6623 pipeline_layout_ci.setLayoutCount = 1;
6624 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006625
6626 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006627 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006628 ASSERT_VK_SUCCESS(err);
6629
6630 // Create a buffer to update the descriptor with
6631 uint32_t qfi = 0;
6632 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006633 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6634 buffCI.size = 1024;
6635 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6636 buffCI.queueFamilyIndexCount = 1;
6637 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638
6639 VkBuffer dyub;
6640 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6641 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006642 // Allocate memory and bind to buffer so we can make it to the appropriate
6643 // error
6644 VkMemoryAllocateInfo mem_alloc = {};
6645 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6646 mem_alloc.pNext = NULL;
6647 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006648 mem_alloc.memoryTypeIndex = 0;
6649
6650 VkMemoryRequirements memReqs;
6651 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006652 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006653 if (!pass) {
6654 vkDestroyBuffer(m_device->device(), dyub, NULL);
6655 return;
6656 }
6657
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006658 VkDeviceMemory mem;
6659 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6660 ASSERT_VK_SUCCESS(err);
6661 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6662 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006663 // Correctly update descriptor to avoid "NOT_UPDATED" error
6664 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006665 buffInfo.buffer = dyub;
6666 buffInfo.offset = 0;
6667 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006668
6669 VkWriteDescriptorSet descriptor_write;
6670 memset(&descriptor_write, 0, sizeof(descriptor_write));
6671 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6672 descriptor_write.dstSet = descriptorSet;
6673 descriptor_write.dstBinding = 0;
6674 descriptor_write.descriptorCount = 1;
6675 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6676 descriptor_write.pBufferInfo = &buffInfo;
6677
6678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6679
Tony Barbour552f6c02016-12-21 14:34:07 -07006680 m_commandBuffer->BeginCommandBuffer();
6681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006682 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6683 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006684 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006685 uint32_t pDynOff[2] = {512, 756};
6686 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6688 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6689 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6690 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006691 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006692 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6694 " dynamic offset 512 combined with "
6695 "offset 0 and range 1024 that "
6696 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006698 char const *vsSource =
6699 "#version 450\n"
6700 "\n"
6701 "out gl_PerVertex { \n"
6702 " vec4 gl_Position;\n"
6703 "};\n"
6704 "void main(){\n"
6705 " gl_Position = vec4(1);\n"
6706 "}\n";
6707 char const *fsSource =
6708 "#version 450\n"
6709 "\n"
6710 "layout(location=0) out vec4 x;\n"
6711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6712 "void main(){\n"
6713 " x = vec4(bar.y);\n"
6714 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6717 VkPipelineObj pipe(m_device);
6718 pipe.AddShader(&vs);
6719 pipe.AddShader(&fs);
6720 pipe.AddColorAttachment();
6721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6722
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006723 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6724 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6725 VkRect2D scissor = {{0, 0}, {16, 16}};
6726 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006728 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006729 // This update should succeed, but offset size of 512 will overstep buffer
6730 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006731 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6732 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006733 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006734 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006735
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006736 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006737 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006738
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006739 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006740 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6742}
6743
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006744TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006745 TEST_DESCRIPTION(
6746 "Attempt to update a descriptor with a non-sparse buffer "
6747 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006748 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006750 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6752 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006753
6754 ASSERT_NO_FATAL_FAILURE(InitState());
6755 ASSERT_NO_FATAL_FAILURE(InitViewport());
6756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6757
6758 VkDescriptorPoolSize ds_type_count = {};
6759 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6760 ds_type_count.descriptorCount = 1;
6761
6762 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6763 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6764 ds_pool_ci.pNext = NULL;
6765 ds_pool_ci.maxSets = 1;
6766 ds_pool_ci.poolSizeCount = 1;
6767 ds_pool_ci.pPoolSizes = &ds_type_count;
6768
6769 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006770 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006771 ASSERT_VK_SUCCESS(err);
6772
6773 VkDescriptorSetLayoutBinding dsl_binding = {};
6774 dsl_binding.binding = 0;
6775 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6776 dsl_binding.descriptorCount = 1;
6777 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6778 dsl_binding.pImmutableSamplers = NULL;
6779
6780 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6781 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6782 ds_layout_ci.pNext = NULL;
6783 ds_layout_ci.bindingCount = 1;
6784 ds_layout_ci.pBindings = &dsl_binding;
6785 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006787 ASSERT_VK_SUCCESS(err);
6788
6789 VkDescriptorSet descriptorSet;
6790 VkDescriptorSetAllocateInfo alloc_info = {};
6791 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6792 alloc_info.descriptorSetCount = 1;
6793 alloc_info.descriptorPool = ds_pool;
6794 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006795 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006796 ASSERT_VK_SUCCESS(err);
6797
6798 // Create a buffer to update the descriptor with
6799 uint32_t qfi = 0;
6800 VkBufferCreateInfo buffCI = {};
6801 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6802 buffCI.size = 1024;
6803 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6804 buffCI.queueFamilyIndexCount = 1;
6805 buffCI.pQueueFamilyIndices = &qfi;
6806
6807 VkBuffer dyub;
6808 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6809 ASSERT_VK_SUCCESS(err);
6810
6811 // Attempt to update descriptor without binding memory to it
6812 VkDescriptorBufferInfo buffInfo = {};
6813 buffInfo.buffer = dyub;
6814 buffInfo.offset = 0;
6815 buffInfo.range = 1024;
6816
6817 VkWriteDescriptorSet descriptor_write;
6818 memset(&descriptor_write, 0, sizeof(descriptor_write));
6819 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6820 descriptor_write.dstSet = descriptorSet;
6821 descriptor_write.dstBinding = 0;
6822 descriptor_write.descriptorCount = 1;
6823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6824 descriptor_write.pBufferInfo = &buffInfo;
6825
6826 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6827 m_errorMonitor->VerifyFound();
6828
6829 vkDestroyBuffer(m_device->device(), dyub, NULL);
6830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6832}
6833
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006834TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006835 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006836 ASSERT_NO_FATAL_FAILURE(InitState());
6837 ASSERT_NO_FATAL_FAILURE(InitViewport());
6838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6839
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006840 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006841 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6844 pipeline_layout_ci.pushConstantRangeCount = 1;
6845 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6846
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006847 //
6848 // Check for invalid push constant ranges in pipeline layouts.
6849 //
6850 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006851 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006852 char const *msg;
6853 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854
Karl Schultzc81037d2016-05-12 08:11:23 -06006855 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6856 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6857 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6858 "vkCreatePipelineLayout() call has push constants index 0 with "
6859 "size 0."},
6860 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6861 "vkCreatePipelineLayout() call has push constants index 0 with "
6862 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006863 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006864 "vkCreatePipelineLayout() call has push constants index 0 with "
6865 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006866 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006867 "vkCreatePipelineLayout() call has push constants index 0 with "
6868 "size 0."},
6869 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6870 "vkCreatePipelineLayout() call has push constants index 0 with "
6871 "offset 1. Offset must"},
6872 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6873 "vkCreatePipelineLayout() call has push constants index 0 "
6874 "with offset "},
6875 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6876 "vkCreatePipelineLayout() call has push constants "
6877 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006878 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006879 "vkCreatePipelineLayout() call has push constants index 0 "
6880 "with offset "},
6881 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6882 "vkCreatePipelineLayout() call has push "
6883 "constants index 0 with offset "},
6884 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6885 "vkCreatePipelineLayout() call has push "
6886 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006887 }};
6888
6889 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006890 for (const auto &iter : range_tests) {
6891 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006894 m_errorMonitor->VerifyFound();
6895 if (VK_SUCCESS == err) {
6896 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6897 }
6898 }
6899
6900 // Check for invalid stage flag
6901 pc_range.offset = 0;
6902 pc_range.size = 16;
6903 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006904 m_errorMonitor->SetDesiredFailureMsg(
6905 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6906 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006908 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006909 if (VK_SUCCESS == err) {
6910 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6911 }
6912
Karl Schultzc59b72d2017-02-24 15:45:05 -07006913 // Check for duplicate stage flags in a list of push constant ranges.
6914 // A shader can only have one push constant block and that block is mapped
6915 // to the push constant range that has that shader's stage flag set.
6916 // The shader's stage flag can only appear once in all the ranges, so the
6917 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006918 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006919 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006920 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006921 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006922 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006923 // Overlapping ranges are OK, but a stage flag can appear only once.
6924 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6925 {
6926 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6927 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6928 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6929 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006930 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006931 {
6932 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6933 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6934 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6935 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6936 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6937 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6938 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6939 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6940 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6941 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6942 }},
6943 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6944 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6945 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6946 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6947 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6948 {
6949 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6950 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6951 }},
6952 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6953 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6954 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6955 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6956 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6957 {
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6959 }},
6960 },
6961 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006962
Karl Schultzc59b72d2017-02-24 15:45:05 -07006963 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006964 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006965 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006967 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006968 m_errorMonitor->VerifyFound();
6969 if (VK_SUCCESS == err) {
6970 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6971 }
6972 }
6973
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006974 //
6975 // CmdPushConstants tests
6976 //
6977
Karl Schultzc59b72d2017-02-24 15:45:05 -07006978 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006979 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07006980 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006981 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006983 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006985 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07006986
6987 const uint8_t dummy_values[100] = {};
6988
6989 m_commandBuffer->BeginCommandBuffer();
6990 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006991
6992 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07006993 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006995 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006996 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006997
Karl Schultzc59b72d2017-02-24 15:45:05 -07006998 m_errorMonitor->ExpectSuccess();
6999 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7000 m_errorMonitor->VerifyNotFound();
7001 m_errorMonitor->ExpectSuccess();
7002 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7003 m_errorMonitor->VerifyNotFound();
7004 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7005 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7006 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7007 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7008 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7009 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7010 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007011 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007012 for (const auto &iter : cmd_range_tests) {
7013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7014 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7015 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007016 m_errorMonitor->VerifyFound();
7017 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007018
Tony Barbour552f6c02016-12-21 14:34:07 -07007019 m_commandBuffer->EndRenderPass();
7020 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007021 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007022}
7023
Karl Schultz6addd812016-02-02 17:17:23 -07007024TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007025 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007026 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007027
7028 ASSERT_NO_FATAL_FAILURE(InitState());
7029 ASSERT_NO_FATAL_FAILURE(InitViewport());
7030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7031
7032 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7033 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007034 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7035 ds_type_count[0].descriptorCount = 10;
7036 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7037 ds_type_count[1].descriptorCount = 2;
7038 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7039 ds_type_count[2].descriptorCount = 2;
7040 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7041 ds_type_count[3].descriptorCount = 5;
7042 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7043 // type
7044 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7045 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7046 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047
7048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7050 ds_pool_ci.pNext = NULL;
7051 ds_pool_ci.maxSets = 5;
7052 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7053 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007054
7055 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007057 ASSERT_VK_SUCCESS(err);
7058
7059 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7060 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007061 dsl_binding[0].binding = 0;
7062 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7063 dsl_binding[0].descriptorCount = 5;
7064 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7065 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007066
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007067 // Create layout identical to set0 layout but w/ different stageFlags
7068 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 dsl_fs_stage_only.binding = 0;
7070 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7071 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007072 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7073 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007074 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007075 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007076 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7077 ds_layout_ci.pNext = NULL;
7078 ds_layout_ci.bindingCount = 1;
7079 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007080 static const uint32_t NUM_LAYOUTS = 4;
7081 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007082 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007083 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7084 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007085 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007087 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007089 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007090 dsl_binding[0].binding = 0;
7091 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007092 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007093 dsl_binding[1].binding = 1;
7094 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7095 dsl_binding[1].descriptorCount = 2;
7096 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7097 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007098 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007099 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007101 ASSERT_VK_SUCCESS(err);
7102 dsl_binding[0].binding = 0;
7103 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007104 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007105 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007106 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007107 ASSERT_VK_SUCCESS(err);
7108 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007109 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007111 ASSERT_VK_SUCCESS(err);
7112
7113 static const uint32_t NUM_SETS = 4;
7114 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7115 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007116 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007117 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007118 alloc_info.descriptorPool = ds_pool;
7119 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007122 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007123 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007125 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007126 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127
7128 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007129 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7130 pipeline_layout_ci.pNext = NULL;
7131 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7132 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007133
7134 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007137 // Create pipelineLayout with only one setLayout
7138 pipeline_layout_ci.setLayoutCount = 1;
7139 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007141 ASSERT_VK_SUCCESS(err);
7142 // Create pipelineLayout with 2 descriptor setLayout at index 0
7143 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7144 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 ASSERT_VK_SUCCESS(err);
7147 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7148 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7149 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007151 ASSERT_VK_SUCCESS(err);
7152 // Create pipelineLayout with UB type, but stageFlags for FS only
7153 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7154 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007156 ASSERT_VK_SUCCESS(err);
7157 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7158 VkDescriptorSetLayout pl_bad_s0[2] = {};
7159 pl_bad_s0[0] = ds_layout_fs_only;
7160 pl_bad_s0[1] = ds_layout[1];
7161 pipeline_layout_ci.setLayoutCount = 2;
7162 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7163 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007164 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007165 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007166
Tobin Ehlis88452832015-12-03 09:40:56 -07007167 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007168 char const *vsSource =
7169 "#version 450\n"
7170 "\n"
7171 "out gl_PerVertex {\n"
7172 " vec4 gl_Position;\n"
7173 "};\n"
7174 "void main(){\n"
7175 " gl_Position = vec4(1);\n"
7176 "}\n";
7177 char const *fsSource =
7178 "#version 450\n"
7179 "\n"
7180 "layout(location=0) out vec4 x;\n"
7181 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7182 "void main(){\n"
7183 " x = vec4(bar.y);\n"
7184 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007185 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7186 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007187 VkPipelineObj pipe(m_device);
7188 pipe.AddShader(&vs);
7189 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007190 pipe.AddColorAttachment();
7191 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007192
Tony Barbour552f6c02016-12-21 14:34:07 -07007193 m_commandBuffer->BeginCommandBuffer();
7194 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007195
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007197 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7198 // of PSO
7199 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7200 // cmd_pipeline.c
7201 // due to the fact that cmd_alloc_dset_data() has not been called in
7202 // cmd_bind_graphics_pipeline()
7203 // TODO : Want to cause various binding incompatibility issues here to test
7204 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007205 // First cause various verify_layout_compatibility() fails
7206 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007207 // verify_set_layout_compatibility fail cases:
7208 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007210 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7211 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007212 m_errorMonitor->VerifyFound();
7213
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007214 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7216 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7217 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007218 m_errorMonitor->VerifyFound();
7219
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007220 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007221 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7222 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7224 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7225 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007226 m_errorMonitor->VerifyFound();
7227
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007228 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7229 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7232 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007233 m_errorMonitor->VerifyFound();
7234
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007235 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7236 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7238 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7239 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7240 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007241 m_errorMonitor->VerifyFound();
7242
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007243 // Cause INFO messages due to disturbing previously bound Sets
7244 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007245 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7246 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007247 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7250 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007251 m_errorMonitor->VerifyFound();
7252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7254 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007255 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7257 " newly bound as set #0 so set #1 and "
7258 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7260 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Tobin Ehlis10fad692016-07-07 12:00:36 -06007263 // Now that we're done actively using the pipelineLayout that gfx pipeline
7264 // was created with, we should be able to delete it. Do that now to verify
7265 // that validation obeys pipelineLayout lifetime
7266 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7267
Tobin Ehlis88452832015-12-03 09:40:56 -07007268 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007269 // 1. Error due to not binding required set (we actually use same code as
7270 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7272 &descriptorSet[0], 0, NULL);
7273 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7274 &descriptorSet[1], 0, NULL);
7275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07007276
7277 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7278 VkRect2D scissor = {{0, 0}, {16, 16}};
7279 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7280 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7281
Tobin Ehlis88452832015-12-03 09:40:56 -07007282 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007283 m_errorMonitor->VerifyFound();
7284
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007285 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007286 // 2. Error due to bound set not being compatible with PSO's
7287 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007288 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7289 &descriptorSet[0], 0, NULL);
7290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007291 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007292 m_errorMonitor->VerifyFound();
7293
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007294 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007295 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7297 }
7298 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7301}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007302
Karl Schultz6addd812016-02-02 17:17:23 -07007303TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7305 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007306
7307 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007308 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007309 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007310 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007312 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007313}
7314
Karl Schultz6addd812016-02-02 17:17:23 -07007315TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7316 VkResult err;
7317 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007318
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007320
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007321 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007322
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007323 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007324 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007325 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007326 cmd.commandPool = m_commandPool;
7327 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007328 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007329
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007331 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007332
7333 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007334 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007335 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7336
7337 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007338 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007339 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007340 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007341 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
7343 // The error should be caught by validation of the BeginCommandBuffer call
7344 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7345
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007346 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007347 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007348}
7349
Karl Schultz6addd812016-02-02 17:17:23 -07007350TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007351 // Cause error due to Begin while recording CB
7352 // Then cause 2 errors for attempting to reset CB w/o having
7353 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7354 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007356
7357 ASSERT_NO_FATAL_FAILURE(InitState());
7358
7359 // Calls AllocateCommandBuffers
7360 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7361
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007362 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007363 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007364 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7365 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007366 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7367 cmd_buf_info.pNext = NULL;
7368 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007369 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007370
7371 // Begin CB to transition to recording state
7372 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7373 // Can't re-begin. This should trigger error
7374 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007375 m_errorMonitor->VerifyFound();
7376
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007378 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007379 // Reset attempt will trigger error due to incorrect CommandPool state
7380 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007381 m_errorMonitor->VerifyFound();
7382
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007384 // Transition CB to RECORDED state
7385 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7386 // Now attempting to Begin will implicitly reset, which triggers error
7387 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007388 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007389}
7390
Karl Schultz6addd812016-02-02 17:17:23 -07007391TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007392 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007393 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007394
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7396 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007397
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007398 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007400
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007401 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007402 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7403 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007404
7405 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007406 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7407 ds_pool_ci.pNext = NULL;
7408 ds_pool_ci.maxSets = 1;
7409 ds_pool_ci.poolSizeCount = 1;
7410 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007411
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007413 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414 ASSERT_VK_SUCCESS(err);
7415
Tony Barboureb254902015-07-15 12:50:33 -06007416 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007417 dsl_binding.binding = 0;
7418 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7419 dsl_binding.descriptorCount = 1;
7420 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7421 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007422
Tony Barboureb254902015-07-15 12:50:33 -06007423 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007424 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7425 ds_layout_ci.pNext = NULL;
7426 ds_layout_ci.bindingCount = 1;
7427 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007428
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007429 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007431 ASSERT_VK_SUCCESS(err);
7432
7433 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007434 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007436 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007437 alloc_info.descriptorPool = ds_pool;
7438 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007440 ASSERT_VK_SUCCESS(err);
7441
Tony Barboureb254902015-07-15 12:50:33 -06007442 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007443 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7444 pipeline_layout_ci.setLayoutCount = 1;
7445 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007446
7447 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 ASSERT_VK_SUCCESS(err);
7450
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007451 VkViewport vp = {}; // Just need dummy vp to point to
7452 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007453
7454 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007455 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7456 vp_state_ci.scissorCount = 1;
7457 vp_state_ci.pScissors = &sc;
7458 vp_state_ci.viewportCount = 1;
7459 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007460
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007461 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7462 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7463 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7464 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7465 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7466 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007467 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007468 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007469 rs_state_ci.lineWidth = 1.0f;
7470
7471 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7472 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7473 vi_ci.pNext = nullptr;
7474 vi_ci.vertexBindingDescriptionCount = 0;
7475 vi_ci.pVertexBindingDescriptions = nullptr;
7476 vi_ci.vertexAttributeDescriptionCount = 0;
7477 vi_ci.pVertexAttributeDescriptions = nullptr;
7478
7479 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7480 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7481 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7482
7483 VkPipelineShaderStageCreateInfo shaderStages[2];
7484 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7485
7486 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7487 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007488 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007490
Tony Barboureb254902015-07-15 12:50:33 -06007491 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007492 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7493 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007494 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007495 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7496 gp_ci.layout = pipeline_layout;
7497 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007498 gp_ci.pVertexInputState = &vi_ci;
7499 gp_ci.pInputAssemblyState = &ia_ci;
7500
7501 gp_ci.stageCount = 1;
7502 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007503
7504 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007505 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7506 pc_ci.initialDataSize = 0;
7507 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007508
7509 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007510 VkPipelineCache pipelineCache;
7511
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007513 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007514 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007515 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007516
Chia-I Wuf7458c52015-10-26 21:10:41 +08007517 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7518 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7519 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7520 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007521}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007522
Tobin Ehlis912df022015-09-17 08:46:18 -06007523/*// TODO : This test should be good, but needs Tess support in compiler to run
7524TEST_F(VkLayerTest, InvalidPatchControlPoints)
7525{
7526 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007527 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007530 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7531primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007532
Tobin Ehlis912df022015-09-17 08:46:18 -06007533 ASSERT_NO_FATAL_FAILURE(InitState());
7534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007535
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007536 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007537 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007538 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007539
7540 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7541 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7542 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007543 ds_pool_ci.poolSizeCount = 1;
7544 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007545
7546 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007547 err = vkCreateDescriptorPool(m_device->device(),
7548VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007549 ASSERT_VK_SUCCESS(err);
7550
7551 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007552 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007554 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007555 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7556 dsl_binding.pImmutableSamplers = NULL;
7557
7558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007559 ds_layout_ci.sType =
7560VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007561 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007562 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007563 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007564
7565 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7567&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007568 ASSERT_VK_SUCCESS(err);
7569
7570 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007571 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7572VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007573 ASSERT_VK_SUCCESS(err);
7574
7575 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007576 pipeline_layout_ci.sType =
7577VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007579 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007580 pipeline_layout_ci.pSetLayouts = &ds_layout;
7581
7582 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007583 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7584&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007585 ASSERT_VK_SUCCESS(err);
7586
7587 VkPipelineShaderStageCreateInfo shaderStages[3];
7588 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7589
Karl Schultz6addd812016-02-02 17:17:23 -07007590 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7591this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007592 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007593 VkShaderObj
7594tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7595this);
7596 VkShaderObj
7597te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7598this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007599
Karl Schultz6addd812016-02-02 17:17:23 -07007600 shaderStages[0].sType =
7601VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007602 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007603 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007604 shaderStages[1].sType =
7605VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007606 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007607 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007608 shaderStages[2].sType =
7609VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007610 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007611 shaderStages[2].shader = te.handle();
7612
7613 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007614 iaCI.sType =
7615VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007616 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007617
7618 VkPipelineTessellationStateCreateInfo tsCI = {};
7619 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7620 tsCI.patchControlPoints = 0; // This will cause an error
7621
7622 VkGraphicsPipelineCreateInfo gp_ci = {};
7623 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7624 gp_ci.pNext = NULL;
7625 gp_ci.stageCount = 3;
7626 gp_ci.pStages = shaderStages;
7627 gp_ci.pVertexInputState = NULL;
7628 gp_ci.pInputAssemblyState = &iaCI;
7629 gp_ci.pTessellationState = &tsCI;
7630 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007631 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007632 gp_ci.pMultisampleState = NULL;
7633 gp_ci.pDepthStencilState = NULL;
7634 gp_ci.pColorBlendState = NULL;
7635 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7636 gp_ci.layout = pipeline_layout;
7637 gp_ci.renderPass = renderPass();
7638
7639 VkPipelineCacheCreateInfo pc_ci = {};
7640 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7641 pc_ci.pNext = NULL;
7642 pc_ci.initialSize = 0;
7643 pc_ci.initialData = 0;
7644 pc_ci.maxSize = 0;
7645
7646 VkPipeline pipeline;
7647 VkPipelineCache pipelineCache;
7648
Karl Schultz6addd812016-02-02 17:17:23 -07007649 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7650&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007651 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7653&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007655 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007656
Chia-I Wuf7458c52015-10-26 21:10:41 +08007657 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7660 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007661}
7662*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007663
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007664TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007665 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007666
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007667 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007668
Tobin Ehlise68360f2015-10-01 11:15:13 -06007669 ASSERT_NO_FATAL_FAILURE(InitState());
7670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007671
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007672 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007673 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7674 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007675
7676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7678 ds_pool_ci.maxSets = 1;
7679 ds_pool_ci.poolSizeCount = 1;
7680 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007681
7682 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007683 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007684 ASSERT_VK_SUCCESS(err);
7685
7686 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007687 dsl_binding.binding = 0;
7688 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7689 dsl_binding.descriptorCount = 1;
7690 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
7692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7694 ds_layout_ci.bindingCount = 1;
7695 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007696
7697 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007699 ASSERT_VK_SUCCESS(err);
7700
7701 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007704 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007705 alloc_info.descriptorPool = ds_pool;
7706 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007708 ASSERT_VK_SUCCESS(err);
7709
7710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7712 pipeline_layout_ci.setLayoutCount = 1;
7713 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007714
7715 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007717 ASSERT_VK_SUCCESS(err);
7718
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007719 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007720 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007721 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007722 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007723 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007724 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007725
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007726 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7727 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7728 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7729 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7730 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7731 rs_state_ci.depthClampEnable = VK_FALSE;
7732 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7733 rs_state_ci.depthBiasEnable = VK_FALSE;
7734
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007735 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7736 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7737 vi_ci.pNext = nullptr;
7738 vi_ci.vertexBindingDescriptionCount = 0;
7739 vi_ci.pVertexBindingDescriptions = nullptr;
7740 vi_ci.vertexAttributeDescriptionCount = 0;
7741 vi_ci.pVertexAttributeDescriptions = nullptr;
7742
7743 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7744 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7745 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7746
7747 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7748 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7749 pipe_ms_state_ci.pNext = NULL;
7750 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7751 pipe_ms_state_ci.sampleShadingEnable = 0;
7752 pipe_ms_state_ci.minSampleShading = 1.0;
7753 pipe_ms_state_ci.pSampleMask = NULL;
7754
Cody Northropeb3a6c12015-10-05 14:44:45 -06007755 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007756 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007757
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007759 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007760 shaderStages[0] = vs.GetStageCreateInfo();
7761 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007762
7763 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007764 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7765 gp_ci.stageCount = 2;
7766 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007767 gp_ci.pVertexInputState = &vi_ci;
7768 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007769 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007770 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007771 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007772 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7773 gp_ci.layout = pipeline_layout;
7774 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007775
7776 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007777 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007778
7779 VkPipeline pipeline;
7780 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007781 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007783
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007784 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007785 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007786
7787 // Check case where multiViewport is disabled and viewport count is not 1
7788 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7791 vp_state_ci.scissorCount = 0;
7792 vp_state_ci.viewportCount = 0;
7793 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7794 m_errorMonitor->VerifyFound();
7795 } else {
7796 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007797 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007798 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007799 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007800
7801 // Check is that viewportcount and scissorcount match
7802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7803 vp_state_ci.scissorCount = 1;
7804 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7805 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7806 m_errorMonitor->VerifyFound();
7807
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007808 // Check case where multiViewport is enabled and viewport count is greater than max
7809 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7812 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7813 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7814 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7815 m_errorMonitor->VerifyFound();
7816 }
7817 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007818
Chia-I Wuf7458c52015-10-26 21:10:41 +08007819 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7821 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7822 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007823}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007824
7825// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7826// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007827TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007828 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007829
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007830 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7831
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007833
Tobin Ehlise68360f2015-10-01 11:15:13 -06007834 ASSERT_NO_FATAL_FAILURE(InitState());
7835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007836
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007837 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007838 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7839 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007840
7841 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007842 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7843 ds_pool_ci.maxSets = 1;
7844 ds_pool_ci.poolSizeCount = 1;
7845 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007846
7847 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007848 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849 ASSERT_VK_SUCCESS(err);
7850
7851 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007852 dsl_binding.binding = 0;
7853 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7854 dsl_binding.descriptorCount = 1;
7855 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
7857 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7859 ds_layout_ci.bindingCount = 1;
7860 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007861
7862 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007863 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007864 ASSERT_VK_SUCCESS(err);
7865
7866 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007867 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007868 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007869 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007870 alloc_info.descriptorPool = ds_pool;
7871 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007872 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007873 ASSERT_VK_SUCCESS(err);
7874
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007875 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7876 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7877 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7878
7879 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7880 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7881 vi_ci.pNext = nullptr;
7882 vi_ci.vertexBindingDescriptionCount = 0;
7883 vi_ci.pVertexBindingDescriptions = nullptr;
7884 vi_ci.vertexAttributeDescriptionCount = 0;
7885 vi_ci.pVertexAttributeDescriptions = nullptr;
7886
7887 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7888 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7889 pipe_ms_state_ci.pNext = NULL;
7890 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7891 pipe_ms_state_ci.sampleShadingEnable = 0;
7892 pipe_ms_state_ci.minSampleShading = 1.0;
7893 pipe_ms_state_ci.pSampleMask = NULL;
7894
Tobin Ehlise68360f2015-10-01 11:15:13 -06007895 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007896 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7897 pipeline_layout_ci.setLayoutCount = 1;
7898 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007899
7900 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007902 ASSERT_VK_SUCCESS(err);
7903
7904 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7905 // Set scissor as dynamic to avoid second error
7906 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007907 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7908 dyn_state_ci.dynamicStateCount = 1;
7909 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007910
Cody Northropeb3a6c12015-10-05 14:44:45 -06007911 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007912 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007914 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007915 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7916 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007917 shaderStages[0] = vs.GetStageCreateInfo();
7918 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007920 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7921 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7922 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7923 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7924 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7925 rs_state_ci.depthClampEnable = VK_FALSE;
7926 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7927 rs_state_ci.depthBiasEnable = VK_FALSE;
7928
Tobin Ehlise68360f2015-10-01 11:15:13 -06007929 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007930 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7931 gp_ci.stageCount = 2;
7932 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007933 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007934 // Not setting VP state w/o dynamic vp state should cause validation error
7935 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007936 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007937 gp_ci.pVertexInputState = &vi_ci;
7938 gp_ci.pInputAssemblyState = &ia_ci;
7939 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007940 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7941 gp_ci.layout = pipeline_layout;
7942 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007943
7944 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007945 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007946
7947 VkPipeline pipeline;
7948 VkPipelineCache pipelineCache;
7949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007953
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007954 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007955
Chia-I Wuf7458c52015-10-26 21:10:41 +08007956 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7957 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7958 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7959 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007960}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007961
7962// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7963// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007964TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7965 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007968
Tobin Ehlise68360f2015-10-01 11:15:13 -06007969 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007970
7971 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007972 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007973 return;
7974 }
7975
Tobin Ehlise68360f2015-10-01 11:15:13 -06007976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007977
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007978 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007979 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7980 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007981
7982 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007983 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7984 ds_pool_ci.maxSets = 1;
7985 ds_pool_ci.poolSizeCount = 1;
7986 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007987
7988 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007990 ASSERT_VK_SUCCESS(err);
7991
7992 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007993 dsl_binding.binding = 0;
7994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7995 dsl_binding.descriptorCount = 1;
7996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
7998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8000 ds_layout_ci.bindingCount = 1;
8001 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008002
8003 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008005 ASSERT_VK_SUCCESS(err);
8006
8007 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008008 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008010 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008011 alloc_info.descriptorPool = ds_pool;
8012 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008014 ASSERT_VK_SUCCESS(err);
8015
8016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8018 pipeline_layout_ci.setLayoutCount = 1;
8019 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008020
8021 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008023 ASSERT_VK_SUCCESS(err);
8024
8025 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008026 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8027 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008028 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008029 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008030 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008031
8032 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8033 // Set scissor as dynamic to avoid that error
8034 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008035 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8036 dyn_state_ci.dynamicStateCount = 1;
8037 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008038
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008039 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8040 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8041 pipe_ms_state_ci.pNext = NULL;
8042 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8043 pipe_ms_state_ci.sampleShadingEnable = 0;
8044 pipe_ms_state_ci.minSampleShading = 1.0;
8045 pipe_ms_state_ci.pSampleMask = NULL;
8046
Cody Northropeb3a6c12015-10-05 14:44:45 -06008047 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008048 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008051 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8052 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08008053 shaderStages[0] = vs.GetStageCreateInfo();
8054 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008055
Cody Northropf6622dc2015-10-06 10:33:21 -06008056 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8057 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8058 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008059 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008060 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008061 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008062 vi_ci.pVertexAttributeDescriptions = nullptr;
8063
8064 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8065 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8066 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8067
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008068 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008069 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008070 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008071 rs_ci.pNext = nullptr;
8072
Mark Youngc89c6312016-03-31 16:03:20 -06008073 VkPipelineColorBlendAttachmentState att = {};
8074 att.blendEnable = VK_FALSE;
8075 att.colorWriteMask = 0xf;
8076
Cody Northropf6622dc2015-10-06 10:33:21 -06008077 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8078 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8079 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008080 cb_ci.attachmentCount = 1;
8081 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082
Tobin Ehlise68360f2015-10-01 11:15:13 -06008083 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008084 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8085 gp_ci.stageCount = 2;
8086 gp_ci.pStages = shaderStages;
8087 gp_ci.pVertexInputState = &vi_ci;
8088 gp_ci.pInputAssemblyState = &ia_ci;
8089 gp_ci.pViewportState = &vp_state_ci;
8090 gp_ci.pRasterizationState = &rs_ci;
8091 gp_ci.pColorBlendState = &cb_ci;
8092 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008093 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008094 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8095 gp_ci.layout = pipeline_layout;
8096 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008097
8098 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008099 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008100
8101 VkPipeline pipeline;
8102 VkPipelineCache pipelineCache;
8103
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008105 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008106 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008107
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008108 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008109
Tobin Ehlisd332f282015-10-02 11:00:56 -06008110 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008111 // First need to successfully create the PSO from above by setting
8112 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07008114
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008115 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008116 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008118 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008119 m_commandBuffer->BeginCommandBuffer();
8120 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008122 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008123 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008124 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008125 Draw(1, 0, 0, 0);
8126
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008127 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008128
8129 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8130 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008133 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008134}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008135
8136// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008137// viewportCount
8138TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8139 VkResult err;
8140
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008142
8143 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008144
8145 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008146 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008147 return;
8148 }
8149
Karl Schultz6addd812016-02-02 17:17:23 -07008150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8151
8152 VkDescriptorPoolSize ds_type_count = {};
8153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8154 ds_type_count.descriptorCount = 1;
8155
8156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8158 ds_pool_ci.maxSets = 1;
8159 ds_pool_ci.poolSizeCount = 1;
8160 ds_pool_ci.pPoolSizes = &ds_type_count;
8161
8162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008164 ASSERT_VK_SUCCESS(err);
8165
8166 VkDescriptorSetLayoutBinding dsl_binding = {};
8167 dsl_binding.binding = 0;
8168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8169 dsl_binding.descriptorCount = 1;
8170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8171
8172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8174 ds_layout_ci.bindingCount = 1;
8175 ds_layout_ci.pBindings = &dsl_binding;
8176
8177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008179 ASSERT_VK_SUCCESS(err);
8180
8181 VkDescriptorSet descriptorSet;
8182 VkDescriptorSetAllocateInfo alloc_info = {};
8183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8184 alloc_info.descriptorSetCount = 1;
8185 alloc_info.descriptorPool = ds_pool;
8186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008188 ASSERT_VK_SUCCESS(err);
8189
8190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8192 pipeline_layout_ci.setLayoutCount = 1;
8193 pipeline_layout_ci.pSetLayouts = &ds_layout;
8194
8195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008197 ASSERT_VK_SUCCESS(err);
8198
8199 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8200 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8201 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008202 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008203 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008204 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008205
8206 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8207 // Set scissor as dynamic to avoid that error
8208 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8209 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8210 dyn_state_ci.dynamicStateCount = 1;
8211 dyn_state_ci.pDynamicStates = &vp_state;
8212
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008213 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8214 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8215 pipe_ms_state_ci.pNext = NULL;
8216 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8217 pipe_ms_state_ci.sampleShadingEnable = 0;
8218 pipe_ms_state_ci.minSampleShading = 1.0;
8219 pipe_ms_state_ci.pSampleMask = NULL;
8220
Karl Schultz6addd812016-02-02 17:17:23 -07008221 VkPipelineShaderStageCreateInfo shaderStages[2];
8222 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8226 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07008227 shaderStages[0] = vs.GetStageCreateInfo();
8228 shaderStages[1] = fs.GetStageCreateInfo();
8229
8230 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8231 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8232 vi_ci.pNext = nullptr;
8233 vi_ci.vertexBindingDescriptionCount = 0;
8234 vi_ci.pVertexBindingDescriptions = nullptr;
8235 vi_ci.vertexAttributeDescriptionCount = 0;
8236 vi_ci.pVertexAttributeDescriptions = nullptr;
8237
8238 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8239 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8240 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8241
8242 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8243 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008244 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008245 rs_ci.pNext = nullptr;
8246
Mark Youngc89c6312016-03-31 16:03:20 -06008247 VkPipelineColorBlendAttachmentState att = {};
8248 att.blendEnable = VK_FALSE;
8249 att.colorWriteMask = 0xf;
8250
Karl Schultz6addd812016-02-02 17:17:23 -07008251 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8252 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8253 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008254 cb_ci.attachmentCount = 1;
8255 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008256
8257 VkGraphicsPipelineCreateInfo gp_ci = {};
8258 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8259 gp_ci.stageCount = 2;
8260 gp_ci.pStages = shaderStages;
8261 gp_ci.pVertexInputState = &vi_ci;
8262 gp_ci.pInputAssemblyState = &ia_ci;
8263 gp_ci.pViewportState = &vp_state_ci;
8264 gp_ci.pRasterizationState = &rs_ci;
8265 gp_ci.pColorBlendState = &cb_ci;
8266 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008267 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008268 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8269 gp_ci.layout = pipeline_layout;
8270 gp_ci.renderPass = renderPass();
8271
8272 VkPipelineCacheCreateInfo pc_ci = {};
8273 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8274
8275 VkPipeline pipeline;
8276 VkPipelineCache pipelineCache;
8277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008279 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008282 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008283
8284 // Now hit second fail case where we set scissor w/ different count than PSO
8285 // First need to successfully create the PSO from above by setting
8286 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8288 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008289
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008290 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008291 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008293 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008294 m_commandBuffer->BeginCommandBuffer();
8295 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008297 VkViewport viewports[1] = {};
8298 viewports[0].width = 8;
8299 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008300 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008301 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008302 Draw(1, 0, 0, 0);
8303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008304 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008305
Chia-I Wuf7458c52015-10-26 21:10:41 +08008306 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8307 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8308 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008310 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008311}
8312
Mark Young7394fdd2016-03-31 14:56:43 -06008313TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8314 VkResult err;
8315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008317
8318 ASSERT_NO_FATAL_FAILURE(InitState());
8319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8320
8321 VkDescriptorPoolSize ds_type_count = {};
8322 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8323 ds_type_count.descriptorCount = 1;
8324
8325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8327 ds_pool_ci.maxSets = 1;
8328 ds_pool_ci.poolSizeCount = 1;
8329 ds_pool_ci.pPoolSizes = &ds_type_count;
8330
8331 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008333 ASSERT_VK_SUCCESS(err);
8334
8335 VkDescriptorSetLayoutBinding dsl_binding = {};
8336 dsl_binding.binding = 0;
8337 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8338 dsl_binding.descriptorCount = 1;
8339 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8340
8341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8343 ds_layout_ci.bindingCount = 1;
8344 ds_layout_ci.pBindings = &dsl_binding;
8345
8346 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008348 ASSERT_VK_SUCCESS(err);
8349
8350 VkDescriptorSet descriptorSet;
8351 VkDescriptorSetAllocateInfo alloc_info = {};
8352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8353 alloc_info.descriptorSetCount = 1;
8354 alloc_info.descriptorPool = ds_pool;
8355 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008357 ASSERT_VK_SUCCESS(err);
8358
8359 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8360 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8361 pipeline_layout_ci.setLayoutCount = 1;
8362 pipeline_layout_ci.pSetLayouts = &ds_layout;
8363
8364 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008366 ASSERT_VK_SUCCESS(err);
8367
8368 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8369 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8370 vp_state_ci.scissorCount = 1;
8371 vp_state_ci.pScissors = NULL;
8372 vp_state_ci.viewportCount = 1;
8373 vp_state_ci.pViewports = NULL;
8374
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008376 // Set scissor as dynamic to avoid that error
8377 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8378 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8379 dyn_state_ci.dynamicStateCount = 2;
8380 dyn_state_ci.pDynamicStates = dynamic_states;
8381
8382 VkPipelineShaderStageCreateInfo shaderStages[2];
8383 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8386 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008387 this); // TODO - We shouldn't need a fragment shader
8388 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008389 shaderStages[0] = vs.GetStageCreateInfo();
8390 shaderStages[1] = fs.GetStageCreateInfo();
8391
8392 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8393 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8394 vi_ci.pNext = nullptr;
8395 vi_ci.vertexBindingDescriptionCount = 0;
8396 vi_ci.pVertexBindingDescriptions = nullptr;
8397 vi_ci.vertexAttributeDescriptionCount = 0;
8398 vi_ci.pVertexAttributeDescriptions = nullptr;
8399
8400 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8401 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8402 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8403
8404 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8405 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8406 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008407 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008408
Mark Young47107952016-05-02 15:59:55 -06008409 // Check too low (line width of -1.0f).
8410 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008411
8412 VkPipelineColorBlendAttachmentState att = {};
8413 att.blendEnable = VK_FALSE;
8414 att.colorWriteMask = 0xf;
8415
8416 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8417 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8418 cb_ci.pNext = nullptr;
8419 cb_ci.attachmentCount = 1;
8420 cb_ci.pAttachments = &att;
8421
8422 VkGraphicsPipelineCreateInfo gp_ci = {};
8423 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8424 gp_ci.stageCount = 2;
8425 gp_ci.pStages = shaderStages;
8426 gp_ci.pVertexInputState = &vi_ci;
8427 gp_ci.pInputAssemblyState = &ia_ci;
8428 gp_ci.pViewportState = &vp_state_ci;
8429 gp_ci.pRasterizationState = &rs_ci;
8430 gp_ci.pColorBlendState = &cb_ci;
8431 gp_ci.pDynamicState = &dyn_state_ci;
8432 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8433 gp_ci.layout = pipeline_layout;
8434 gp_ci.renderPass = renderPass();
8435
8436 VkPipelineCacheCreateInfo pc_ci = {};
8437 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8438
8439 VkPipeline pipeline;
8440 VkPipelineCache pipelineCache;
8441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008443 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008445
8446 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008447 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008450
8451 // Check too high (line width of 65536.0f).
8452 rs_ci.lineWidth = 65536.0f;
8453
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008455 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008456 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008457
8458 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008459 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008460
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008462
8463 dyn_state_ci.dynamicStateCount = 3;
8464
8465 rs_ci.lineWidth = 1.0f;
8466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008468 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008470 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008472
8473 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008474 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008475 m_errorMonitor->VerifyFound();
8476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008478
8479 // Check too high with dynamic setting.
8480 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8481 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008482 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008483
8484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8485 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008488 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008489}
8490
Karl Schultz6addd812016-02-02 17:17:23 -07008491TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008492 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008494 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008495
8496 ASSERT_NO_FATAL_FAILURE(InitState());
8497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008498
Tony Barbour552f6c02016-12-21 14:34:07 -07008499 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008500 // Don't care about RenderPass handle b/c error should be flagged before
8501 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008503
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008504 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008505}
8506
Karl Schultz6addd812016-02-02 17:17:23 -07008507TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008508 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8510 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008511
8512 ASSERT_NO_FATAL_FAILURE(InitState());
8513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008514
Tony Barbour552f6c02016-12-21 14:34:07 -07008515 m_commandBuffer->BeginCommandBuffer();
8516 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008517 // Just create a dummy Renderpass that's non-NULL so we can get to the
8518 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008521 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008522}
8523
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008524TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008525 TEST_DESCRIPTION(
8526 "Begin a renderPass where clearValueCount is less than"
8527 "the number of renderPass attachments that use loadOp"
8528 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008529
8530 ASSERT_NO_FATAL_FAILURE(InitState());
8531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8532
8533 // Create a renderPass with a single attachment that uses loadOp CLEAR
8534 VkAttachmentReference attach = {};
8535 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8536 VkSubpassDescription subpass = {};
8537 subpass.inputAttachmentCount = 1;
8538 subpass.pInputAttachments = &attach;
8539 VkRenderPassCreateInfo rpci = {};
8540 rpci.subpassCount = 1;
8541 rpci.pSubpasses = &subpass;
8542 rpci.attachmentCount = 1;
8543 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008544 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008545 // Set loadOp to CLEAR
8546 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8547 rpci.pAttachments = &attach_desc;
8548 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8549 VkRenderPass rp;
8550 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8551
8552 VkCommandBufferInheritanceInfo hinfo = {};
8553 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8554 hinfo.renderPass = VK_NULL_HANDLE;
8555 hinfo.subpass = 0;
8556 hinfo.framebuffer = VK_NULL_HANDLE;
8557 hinfo.occlusionQueryEnable = VK_FALSE;
8558 hinfo.queryFlags = 0;
8559 hinfo.pipelineStatistics = 0;
8560 VkCommandBufferBeginInfo info = {};
8561 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8562 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8563 info.pInheritanceInfo = &hinfo;
8564
8565 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8566 VkRenderPassBeginInfo rp_begin = {};
8567 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8568 rp_begin.pNext = NULL;
8569 rp_begin.renderPass = renderPass();
8570 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008571 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008572
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008575 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008576
8577 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008578
8579 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008580}
8581
Slawomir Cygan0808f392016-11-28 17:53:23 +01008582TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008583 TEST_DESCRIPTION(
8584 "Begin a renderPass where clearValueCount is greater than"
8585 "the number of renderPass attachments that use loadOp"
8586 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008587
8588 ASSERT_NO_FATAL_FAILURE(InitState());
8589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8590
8591 // Create a renderPass with a single attachment that uses loadOp CLEAR
8592 VkAttachmentReference attach = {};
8593 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8594 VkSubpassDescription subpass = {};
8595 subpass.inputAttachmentCount = 1;
8596 subpass.pInputAttachments = &attach;
8597 VkRenderPassCreateInfo rpci = {};
8598 rpci.subpassCount = 1;
8599 rpci.pSubpasses = &subpass;
8600 rpci.attachmentCount = 1;
8601 VkAttachmentDescription attach_desc = {};
8602 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8603 // Set loadOp to CLEAR
8604 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8605 rpci.pAttachments = &attach_desc;
8606 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8607 VkRenderPass rp;
8608 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8609
8610 VkCommandBufferBeginInfo info = {};
8611 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8612 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8613
8614 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8615 VkRenderPassBeginInfo rp_begin = {};
8616 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8617 rp_begin.pNext = NULL;
8618 rp_begin.renderPass = renderPass();
8619 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008620 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8623 " has a clearValueCount of"
8624 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008625
8626 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8627
8628 m_errorMonitor->VerifyFound();
8629
8630 vkDestroyRenderPass(m_device->device(), rp, NULL);
8631}
8632
Cody Northrop3bb4d962016-05-09 16:15:57 -06008633TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008634 TEST_DESCRIPTION("End a command buffer with an active render pass");
8635
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8637 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008638
8639 ASSERT_NO_FATAL_FAILURE(InitState());
8640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8641
Tony Barbour552f6c02016-12-21 14:34:07 -07008642 m_commandBuffer->BeginCommandBuffer();
8643 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8644 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008645
8646 m_errorMonitor->VerifyFound();
8647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8649 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008650}
8651
Karl Schultz6addd812016-02-02 17:17:23 -07008652TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008653 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8655 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008656
8657 ASSERT_NO_FATAL_FAILURE(InitState());
8658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008659
Tony Barbour552f6c02016-12-21 14:34:07 -07008660 m_commandBuffer->BeginCommandBuffer();
8661 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008662
8663 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008664 vk_testing::Buffer dstBuffer;
8665 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008666
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008667 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008668
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008669 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008670}
8671
Karl Schultz6addd812016-02-02 17:17:23 -07008672TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Tony Barbour552f6c02016-12-21 14:34:07 -07008680 m_commandBuffer->BeginCommandBuffer();
8681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682
8683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008684 vk_testing::Buffer dstBuffer;
8685 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
Karl Schultz6addd812016-02-02 17:17:23 -07008687 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008688 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8689 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8690 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008692 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693}
8694
Karl Schultz6addd812016-02-02 17:17:23 -07008695TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8698 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
8700 ASSERT_NO_FATAL_FAILURE(InitState());
8701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
Tony Barbour552f6c02016-12-21 14:34:07 -07008703 m_commandBuffer->BeginCommandBuffer();
8704 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008705
Michael Lentine0a369f62016-02-03 16:51:46 -06008706 VkClearColorValue clear_color;
8707 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008708 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8709 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8710 const int32_t tex_width = 32;
8711 const int32_t tex_height = 32;
8712 VkImageCreateInfo image_create_info = {};
8713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8714 image_create_info.pNext = NULL;
8715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8716 image_create_info.format = tex_format;
8717 image_create_info.extent.width = tex_width;
8718 image_create_info.extent.height = tex_height;
8719 image_create_info.extent.depth = 1;
8720 image_create_info.mipLevels = 1;
8721 image_create_info.arrayLayers = 1;
8722 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8723 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8724 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008726 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008728
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008729 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008730
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008731 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008732 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008733
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008734 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008735}
8736
Karl Schultz6addd812016-02-02 17:17:23 -07008737TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008738 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8740 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008741
8742 ASSERT_NO_FATAL_FAILURE(InitState());
8743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008744
Tony Barbour552f6c02016-12-21 14:34:07 -07008745 m_commandBuffer->BeginCommandBuffer();
8746 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008747
8748 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008749 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008750 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8751 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8752 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8753 image_create_info.extent.width = 64;
8754 image_create_info.extent.height = 64;
8755 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8756 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008758 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008761 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008762
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008763 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8764 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008766 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008767}
8768
Karl Schultz6addd812016-02-02 17:17:23 -07008769TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008770 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008771 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8774 "vkCmdClearAttachments(): This call "
8775 "must be issued inside an active "
8776 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008777
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008778 ASSERT_NO_FATAL_FAILURE(InitState());
8779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008780
8781 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008782 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008783 ASSERT_VK_SUCCESS(err);
8784
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008785 VkClearAttachment color_attachment;
8786 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8787 color_attachment.clearValue.color.float32[0] = 0;
8788 color_attachment.clearValue.color.float32[1] = 0;
8789 color_attachment.clearValue.color.float32[2] = 0;
8790 color_attachment.clearValue.color.float32[3] = 0;
8791 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008792 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008793 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008795 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008796}
8797
Chris Forbes3b97e932016-09-07 11:29:24 +12008798TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008799 TEST_DESCRIPTION(
8800 "Test that an error is produced when CmdNextSubpass is "
8801 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8804 "vkCmdNextSubpass(): Attempted to advance "
8805 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008806
8807 ASSERT_NO_FATAL_FAILURE(InitState());
8808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8809
Tony Barbour552f6c02016-12-21 14:34:07 -07008810 m_commandBuffer->BeginCommandBuffer();
8811 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008812
8813 // error here.
8814 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8815 m_errorMonitor->VerifyFound();
8816
Tony Barbour552f6c02016-12-21 14:34:07 -07008817 m_commandBuffer->EndRenderPass();
8818 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008819}
8820
Chris Forbes6d624702016-09-07 13:57:05 +12008821TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008822 TEST_DESCRIPTION(
8823 "Test that an error is produced when CmdEndRenderPass is "
8824 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8827 "vkCmdEndRenderPass(): Called before reaching "
8828 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008829
8830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8832 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008833
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008834 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008835
8836 VkRenderPass rp;
8837 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8838 ASSERT_VK_SUCCESS(err);
8839
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008840 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008841
8842 VkFramebuffer fb;
8843 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8844 ASSERT_VK_SUCCESS(err);
8845
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008846 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008849
8850 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8851
8852 // Error here.
8853 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8854 m_errorMonitor->VerifyFound();
8855
8856 // Clean up.
8857 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8858 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8859}
8860
Karl Schultz9e66a292016-04-21 15:57:51 -06008861TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8862 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8864 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008865
8866 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008867 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008868
8869 VkBufferMemoryBarrier buf_barrier = {};
8870 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8871 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8872 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8873 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8874 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8875 buf_barrier.buffer = VK_NULL_HANDLE;
8876 buf_barrier.offset = 0;
8877 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008878 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8879 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008880
8881 m_errorMonitor->VerifyFound();
8882}
8883
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008884TEST_F(VkLayerTest, InvalidBarriers) {
8885 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008888
8889 ASSERT_NO_FATAL_FAILURE(InitState());
8890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8891
8892 VkMemoryBarrier mem_barrier = {};
8893 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8894 mem_barrier.pNext = NULL;
8895 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8896 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008897 m_commandBuffer->BeginCommandBuffer();
8898 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008901 &mem_barrier, 0, nullptr, 0, nullptr);
8902 m_errorMonitor->VerifyFound();
8903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008905 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008906 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008907 ASSERT_TRUE(image.initialized());
8908 VkImageMemoryBarrier img_barrier = {};
8909 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8910 img_barrier.pNext = NULL;
8911 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8912 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8913 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8914 // New layout can't be UNDEFINED
8915 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8916 img_barrier.image = image.handle();
8917 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8918 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8919 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8920 img_barrier.subresourceRange.baseArrayLayer = 0;
8921 img_barrier.subresourceRange.baseMipLevel = 0;
8922 img_barrier.subresourceRange.layerCount = 1;
8923 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8925 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008926 m_errorMonitor->VerifyFound();
8927 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8928
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8930 "Subresource must have the sum of the "
8931 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008932 // baseArrayLayer + layerCount must be <= image's arrayLayers
8933 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8935 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008936 m_errorMonitor->VerifyFound();
8937 img_barrier.subresourceRange.baseArrayLayer = 0;
8938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008940 // baseMipLevel + levelCount must be <= image's mipLevels
8941 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8943 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008944 m_errorMonitor->VerifyFound();
8945 img_barrier.subresourceRange.baseMipLevel = 0;
8946
Mike Weiblen7053aa32017-01-25 15:21:10 -07008947 // levelCount must be non-zero.
8948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8949 img_barrier.subresourceRange.levelCount = 0;
8950 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8951 nullptr, 0, nullptr, 1, &img_barrier);
8952 m_errorMonitor->VerifyFound();
8953 img_barrier.subresourceRange.levelCount = 1;
8954
8955 // layerCount must be non-zero.
8956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8957 img_barrier.subresourceRange.layerCount = 0;
8958 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8959 nullptr, 0, nullptr, 1, &img_barrier);
8960 m_errorMonitor->VerifyFound();
8961 img_barrier.subresourceRange.layerCount = 1;
8962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008964 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008965 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8966 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008967 VkBufferMemoryBarrier buf_barrier = {};
8968 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8969 buf_barrier.pNext = NULL;
8970 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8971 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8972 buf_barrier.buffer = buffer.handle();
8973 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8974 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8975 buf_barrier.offset = 0;
8976 buf_barrier.size = VK_WHOLE_SIZE;
8977 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8979 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008980 m_errorMonitor->VerifyFound();
8981 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008984 buf_barrier.offset = 257;
8985 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008986 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8987 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008988 m_errorMonitor->VerifyFound();
8989 buf_barrier.offset = 0;
8990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008992 buf_barrier.size = 257;
8993 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008994 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8995 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008996 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008997
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008998 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008999 m_errorMonitor->SetDesiredFailureMsg(
9000 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009001 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009002 VkDepthStencilObj ds_image(m_device);
9003 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9004 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009005 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9006 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009007 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009008
9009 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009010 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9012 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009013 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009014
9015 // Having anything other than DEPTH or STENCIL is an error
9016 m_errorMonitor->SetDesiredFailureMsg(
9017 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9018 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9019 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9020 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9021 nullptr, 0, nullptr, 1, &img_barrier);
9022 m_errorMonitor->VerifyFound();
9023
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009024 // Now test depth-only
9025 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009026 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9027 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009028 VkDepthStencilObj d_image(m_device);
9029 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9030 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009031 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009032 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009033 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009034
9035 // DEPTH bit must be set
9036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9037 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009038 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009039 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9040 0, nullptr, 0, nullptr, 1, &img_barrier);
9041 m_errorMonitor->VerifyFound();
9042
9043 // No bits other than DEPTH may be set
9044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9045 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9046 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009047 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9048 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009049 m_errorMonitor->VerifyFound();
9050 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009051
9052 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009053 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9054 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009055 VkDepthStencilObj s_image(m_device);
9056 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9057 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009059 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009060 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009061 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9063 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009064 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009065 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9066 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009067 m_errorMonitor->VerifyFound();
9068 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009069
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009070 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009071 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009072 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009073 ASSERT_TRUE(c_image.initialized());
9074 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9075 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9076 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009077
9078 // COLOR bit must be set
9079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9080 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009081 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009082 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9083 nullptr, 0, nullptr, 1, &img_barrier);
9084 m_errorMonitor->VerifyFound();
9085
9086 // No bits other than COLOR may be set
9087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9088 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9089 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9091 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009092 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009093
9094 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9095
9096 // Create command pool with incompatible queueflags
9097 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9098 uint32_t queue_family_index = UINT32_MAX;
9099 for (uint32_t i = 0; i < queue_props.size(); i++) {
9100 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9101 queue_family_index = i;
9102 break;
9103 }
9104 }
9105 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009106 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009107 return;
9108 }
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9110
9111 VkCommandPool command_pool;
9112 VkCommandPoolCreateInfo pool_create_info{};
9113 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9114 pool_create_info.queueFamilyIndex = queue_family_index;
9115 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9116 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9117
9118 // Allocate a command buffer
9119 VkCommandBuffer bad_command_buffer;
9120 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9121 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9122 command_buffer_allocate_info.commandPool = command_pool;
9123 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9124 command_buffer_allocate_info.commandBufferCount = 1;
9125 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9126
9127 VkCommandBufferBeginInfo cbbi = {};
9128 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9129 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9130 buf_barrier.offset = 0;
9131 buf_barrier.size = VK_WHOLE_SIZE;
9132 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9133 &buf_barrier, 0, nullptr);
9134 m_errorMonitor->VerifyFound();
9135
9136 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9137 vkEndCommandBuffer(bad_command_buffer);
9138 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009139 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009140 return;
9141 }
9142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9143 VkEvent event;
9144 VkEventCreateInfo event_create_info{};
9145 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9146 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9147 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9148 nullptr, 0, nullptr);
9149 m_errorMonitor->VerifyFound();
9150
9151 vkEndCommandBuffer(bad_command_buffer);
9152 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009153}
9154
Tony Barbour18ba25c2016-09-29 13:42:40 -06009155TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9156 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9157
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009159 ASSERT_NO_FATAL_FAILURE(InitState());
9160 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009161 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009162 ASSERT_TRUE(image.initialized());
9163
9164 VkImageMemoryBarrier barrier = {};
9165 VkImageSubresourceRange range;
9166 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9167 barrier.srcAccessMask = 0;
9168 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9169 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9170 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9171 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9172 barrier.image = image.handle();
9173 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9174 range.baseMipLevel = 0;
9175 range.levelCount = 1;
9176 range.baseArrayLayer = 0;
9177 range.layerCount = 1;
9178 barrier.subresourceRange = range;
9179 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9180 cmdbuf.BeginCommandBuffer();
9181 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9182 &barrier);
9183 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9184 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9185 barrier.srcAccessMask = 0;
9186 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9187 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9188 &barrier);
9189
9190 m_errorMonitor->VerifyFound();
9191}
9192
Karl Schultz6addd812016-02-02 17:17:23 -07009193TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009194 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009195 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009198
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009199 ASSERT_NO_FATAL_FAILURE(InitState());
9200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009201 uint32_t qfi = 0;
9202 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009203 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9204 buffCI.size = 1024;
9205 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9206 buffCI.queueFamilyIndexCount = 1;
9207 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009208
9209 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009210 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009211 ASSERT_VK_SUCCESS(err);
9212
Tony Barbour552f6c02016-12-21 14:34:07 -07009213 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009214 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009215 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9216 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009217 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009218 m_errorMonitor->SetUnexpectedError(
9219 "If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009220 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009221
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009222 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009223
Chia-I Wuf7458c52015-10-26 21:10:41 +08009224 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009225}
9226
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009227TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9228 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9230 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9231 "of the indices specified when the device was created, via the "
9232 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009233
9234 ASSERT_NO_FATAL_FAILURE(InitState());
9235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9236 VkBufferCreateInfo buffCI = {};
9237 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9238 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009239 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009240 buffCI.queueFamilyIndexCount = 1;
9241 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009242 uint32_t qfi[2];
9243 qfi[0] = 777;
9244
9245 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009246 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009247
9248 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009249 m_errorMonitor->SetUnexpectedError(
9250 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009251 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9252
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009253 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009254
9255 if (m_device->queue_props.size() > 2) {
9256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9257
9258 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9259 buffCI.queueFamilyIndexCount = 2;
9260 qfi[0] = 1;
9261 qfi[1] = 2;
9262 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9263 VkDeviceMemory mem;
9264 VkMemoryRequirements mem_reqs;
9265 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9266
9267 VkMemoryAllocateInfo alloc_info = {};
9268 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9269 alloc_info.allocationSize = 1024;
9270 bool pass = false;
9271 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9272 if (!pass) {
9273 vkDestroyBuffer(m_device->device(), ib, NULL);
9274 return;
9275 }
9276 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9277 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9278
9279 m_commandBuffer->begin();
9280 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9281 m_commandBuffer->end();
9282 QueueCommandBuffer(false);
9283 m_errorMonitor->VerifyFound();
9284 }
9285
Tony Barbourdf4c0042016-06-01 15:55:43 -06009286 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009287}
9288
Karl Schultz6addd812016-02-02 17:17:23 -07009289TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009290 TEST_DESCRIPTION(
9291 "Attempt vkCmdExecuteCommands with a primary command buffer"
9292 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009293
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009294 ASSERT_NO_FATAL_FAILURE(InitState());
9295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009296
Chris Forbesf29a84f2016-10-06 18:39:28 +13009297 // An empty primary command buffer
9298 VkCommandBufferObj cb(m_device, m_commandPool);
9299 cb.BeginCommandBuffer();
9300 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009301
Chris Forbesf29a84f2016-10-06 18:39:28 +13009302 m_commandBuffer->BeginCommandBuffer();
9303 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9304 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009305
Chris Forbesf29a84f2016-10-06 18:39:28 +13009306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9307 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009308 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009309
9310 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009311}
9312
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009313TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009314 TEST_DESCRIPTION(
9315 "Attempt to update descriptor sets for images and buffers "
9316 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009317 VkResult err;
9318
9319 ASSERT_NO_FATAL_FAILURE(InitState());
9320 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9321 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9322 ds_type_count[i].type = VkDescriptorType(i);
9323 ds_type_count[i].descriptorCount = 1;
9324 }
9325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9327 ds_pool_ci.pNext = NULL;
9328 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9329 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9330 ds_pool_ci.pPoolSizes = ds_type_count;
9331
9332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009333 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009334 ASSERT_VK_SUCCESS(err);
9335
9336 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009337 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009338 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9339 dsl_binding[i].binding = 0;
9340 dsl_binding[i].descriptorType = VkDescriptorType(i);
9341 dsl_binding[i].descriptorCount = 1;
9342 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9343 dsl_binding[i].pImmutableSamplers = NULL;
9344 }
9345
9346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9348 ds_layout_ci.pNext = NULL;
9349 ds_layout_ci.bindingCount = 1;
9350 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9351 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9352 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009354 ASSERT_VK_SUCCESS(err);
9355 }
9356 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9357 VkDescriptorSetAllocateInfo alloc_info = {};
9358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9359 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9360 alloc_info.descriptorPool = ds_pool;
9361 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009363 ASSERT_VK_SUCCESS(err);
9364
9365 // Create a buffer & bufferView to be used for invalid updates
9366 VkBufferCreateInfo buff_ci = {};
9367 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009368 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009369 buff_ci.size = 256;
9370 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009371 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009372 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9373 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009374
9375 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9376 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9377 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9378 ASSERT_VK_SUCCESS(err);
9379
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009380 VkMemoryRequirements mem_reqs;
9381 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9382 VkMemoryAllocateInfo mem_alloc_info = {};
9383 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9384 mem_alloc_info.pNext = NULL;
9385 mem_alloc_info.memoryTypeIndex = 0;
9386 mem_alloc_info.allocationSize = mem_reqs.size;
9387 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9388 if (!pass) {
9389 vkDestroyBuffer(m_device->device(), buffer, NULL);
9390 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9391 return;
9392 }
9393 VkDeviceMemory mem;
9394 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9395 ASSERT_VK_SUCCESS(err);
9396 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9397 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009398
9399 VkBufferViewCreateInfo buff_view_ci = {};
9400 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9401 buff_view_ci.buffer = buffer;
9402 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9403 buff_view_ci.range = VK_WHOLE_SIZE;
9404 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009405 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009406 ASSERT_VK_SUCCESS(err);
9407
Tony Barbour415497c2017-01-24 10:06:09 -07009408 // Now get resources / view for storage_texel_buffer
9409 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9410 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9411 if (!pass) {
9412 vkDestroyBuffer(m_device->device(), buffer, NULL);
9413 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9414 vkFreeMemory(m_device->device(), mem, NULL);
9415 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9417 return;
9418 }
9419 VkDeviceMemory storage_texel_buffer_mem;
9420 VkBufferView storage_texel_buffer_view;
9421 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9422 ASSERT_VK_SUCCESS(err);
9423 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9424 ASSERT_VK_SUCCESS(err);
9425 buff_view_ci.buffer = storage_texel_buffer;
9426 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9427 ASSERT_VK_SUCCESS(err);
9428
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009429 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009430 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009431 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009432 image_ci.format = VK_FORMAT_UNDEFINED;
9433 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9434 VkFormat format = static_cast<VkFormat>(f);
9435 VkFormatProperties fProps = m_device->format_properties(format);
9436 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9437 image_ci.format = format;
9438 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9439 break;
9440 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9441 image_ci.format = format;
9442 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9443 break;
9444 }
9445 }
9446 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9447 return;
9448 }
9449
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009450 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9451 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009452 image_ci.extent.width = 64;
9453 image_ci.extent.height = 64;
9454 image_ci.extent.depth = 1;
9455 image_ci.mipLevels = 1;
9456 image_ci.arrayLayers = 1;
9457 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009458 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009459 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009460 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9461 VkImage image;
9462 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9463 ASSERT_VK_SUCCESS(err);
9464 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009465 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009466
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009467 VkMemoryAllocateInfo mem_alloc = {};
9468 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9469 mem_alloc.pNext = NULL;
9470 mem_alloc.allocationSize = 0;
9471 mem_alloc.memoryTypeIndex = 0;
9472 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9473 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 ASSERT_TRUE(pass);
9476 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9477 ASSERT_VK_SUCCESS(err);
9478 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9479 ASSERT_VK_SUCCESS(err);
9480 // Now create view for image
9481 VkImageViewCreateInfo image_view_ci = {};
9482 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9483 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009484 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009485 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9486 image_view_ci.subresourceRange.layerCount = 1;
9487 image_view_ci.subresourceRange.baseArrayLayer = 0;
9488 image_view_ci.subresourceRange.levelCount = 1;
9489 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9490 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009491 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009492 ASSERT_VK_SUCCESS(err);
9493
9494 VkDescriptorBufferInfo buff_info = {};
9495 buff_info.buffer = buffer;
9496 VkDescriptorImageInfo img_info = {};
9497 img_info.imageView = image_view;
9498 VkWriteDescriptorSet descriptor_write = {};
9499 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9500 descriptor_write.dstBinding = 0;
9501 descriptor_write.descriptorCount = 1;
9502 descriptor_write.pTexelBufferView = &buff_view;
9503 descriptor_write.pBufferInfo = &buff_info;
9504 descriptor_write.pImageInfo = &img_info;
9505
9506 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009507 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009508 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9509 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9510 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9511 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9512 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9513 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9514 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9515 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9516 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9517 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9518 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009519 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009520 // Start loop at 1 as SAMPLER desc type has no usage bit error
9521 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009522 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9523 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9524 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9525 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009526 descriptor_write.descriptorType = VkDescriptorType(i);
9527 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009529
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009531
9532 m_errorMonitor->VerifyFound();
9533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009534 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9535 descriptor_write.pTexelBufferView = &buff_view;
9536 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009537 }
Tony Barbour415497c2017-01-24 10:06:09 -07009538
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9540 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009541 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009542 vkDestroyImageView(m_device->device(), image_view, NULL);
9543 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009544 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009545 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009546 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009547 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009548 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9550}
9551
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009552TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009553 TEST_DESCRIPTION(
9554 "Attempt to update buffer descriptor set that has incorrect "
9555 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9556 "1. offset value greater than buffer size\n"
9557 "2. range value of 0\n"
9558 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009559 VkResult err;
9560
9561 ASSERT_NO_FATAL_FAILURE(InitState());
9562 VkDescriptorPoolSize ds_type_count = {};
9563 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9564 ds_type_count.descriptorCount = 1;
9565
9566 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9567 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9568 ds_pool_ci.pNext = NULL;
9569 ds_pool_ci.maxSets = 1;
9570 ds_pool_ci.poolSizeCount = 1;
9571 ds_pool_ci.pPoolSizes = &ds_type_count;
9572
9573 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009575 ASSERT_VK_SUCCESS(err);
9576
9577 // Create layout with single uniform buffer descriptor
9578 VkDescriptorSetLayoutBinding dsl_binding = {};
9579 dsl_binding.binding = 0;
9580 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9581 dsl_binding.descriptorCount = 1;
9582 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9583 dsl_binding.pImmutableSamplers = NULL;
9584
9585 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9586 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9587 ds_layout_ci.pNext = NULL;
9588 ds_layout_ci.bindingCount = 1;
9589 ds_layout_ci.pBindings = &dsl_binding;
9590 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009592 ASSERT_VK_SUCCESS(err);
9593
9594 VkDescriptorSet descriptor_set = {};
9595 VkDescriptorSetAllocateInfo alloc_info = {};
9596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9597 alloc_info.descriptorSetCount = 1;
9598 alloc_info.descriptorPool = ds_pool;
9599 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009601 ASSERT_VK_SUCCESS(err);
9602
9603 // Create a buffer to be used for invalid updates
9604 VkBufferCreateInfo buff_ci = {};
9605 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9606 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9607 buff_ci.size = 256;
9608 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9609 VkBuffer buffer;
9610 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9611 ASSERT_VK_SUCCESS(err);
9612 // Have to bind memory to buffer before descriptor update
9613 VkMemoryAllocateInfo mem_alloc = {};
9614 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9615 mem_alloc.pNext = NULL;
9616 mem_alloc.allocationSize = 256;
9617 mem_alloc.memoryTypeIndex = 0;
9618
9619 VkMemoryRequirements mem_reqs;
9620 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009622 if (!pass) {
9623 vkDestroyBuffer(m_device->device(), buffer, NULL);
9624 return;
9625 }
9626
9627 VkDeviceMemory mem;
9628 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9629 ASSERT_VK_SUCCESS(err);
9630 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9631 ASSERT_VK_SUCCESS(err);
9632
9633 VkDescriptorBufferInfo buff_info = {};
9634 buff_info.buffer = buffer;
9635 // First make offset 1 larger than buffer size
9636 buff_info.offset = 257;
9637 buff_info.range = VK_WHOLE_SIZE;
9638 VkWriteDescriptorSet descriptor_write = {};
9639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9640 descriptor_write.dstBinding = 0;
9641 descriptor_write.descriptorCount = 1;
9642 descriptor_write.pTexelBufferView = nullptr;
9643 descriptor_write.pBufferInfo = &buff_info;
9644 descriptor_write.pImageInfo = nullptr;
9645
9646 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9647 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009649
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009650 m_errorMonitor->SetUnexpectedError(
9651 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9652 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009653 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9654
9655 m_errorMonitor->VerifyFound();
9656 // Now cause error due to range of 0
9657 buff_info.offset = 0;
9658 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009660
9661 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9662
9663 m_errorMonitor->VerifyFound();
9664 // Now cause error due to range exceeding buffer size - offset
9665 buff_info.offset = 128;
9666 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009668
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009669 m_errorMonitor->SetUnexpectedError(
9670 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9671 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009672 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9673
9674 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009675 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9677 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009678 m_errorMonitor->SetUnexpectedError(
9679 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009680 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9681 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9682}
9683
Tobin Ehlis845887e2017-02-02 19:01:44 -07009684TEST_F(VkLayerTest, DSBufferLimitErrors) {
9685 TEST_DESCRIPTION(
9686 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9687 "Test cases include:\n"
9688 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9689 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9690 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9691 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9692 VkResult err;
9693
9694 ASSERT_NO_FATAL_FAILURE(InitState());
9695 VkDescriptorPoolSize ds_type_count[2] = {};
9696 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9697 ds_type_count[0].descriptorCount = 1;
9698 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9699 ds_type_count[1].descriptorCount = 1;
9700
9701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9703 ds_pool_ci.pNext = NULL;
9704 ds_pool_ci.maxSets = 1;
9705 ds_pool_ci.poolSizeCount = 2;
9706 ds_pool_ci.pPoolSizes = ds_type_count;
9707
9708 VkDescriptorPool ds_pool;
9709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9710 ASSERT_VK_SUCCESS(err);
9711
9712 // Create layout with single uniform buffer & single storage buffer descriptor
9713 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9714 dsl_binding[0].binding = 0;
9715 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9716 dsl_binding[0].descriptorCount = 1;
9717 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9718 dsl_binding[0].pImmutableSamplers = NULL;
9719 dsl_binding[1].binding = 1;
9720 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9721 dsl_binding[1].descriptorCount = 1;
9722 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9723 dsl_binding[1].pImmutableSamplers = NULL;
9724
9725 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9726 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9727 ds_layout_ci.pNext = NULL;
9728 ds_layout_ci.bindingCount = 2;
9729 ds_layout_ci.pBindings = dsl_binding;
9730 VkDescriptorSetLayout ds_layout;
9731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9732 ASSERT_VK_SUCCESS(err);
9733
9734 VkDescriptorSet descriptor_set = {};
9735 VkDescriptorSetAllocateInfo alloc_info = {};
9736 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9737 alloc_info.descriptorSetCount = 1;
9738 alloc_info.descriptorPool = ds_pool;
9739 alloc_info.pSetLayouts = &ds_layout;
9740 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9741 ASSERT_VK_SUCCESS(err);
9742
9743 // Create a buffer to be used for invalid updates
9744 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9745 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9746 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9747 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9748 VkBufferCreateInfo ub_ci = {};
9749 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9750 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9751 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9752 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9753 VkBuffer uniform_buffer;
9754 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9755 ASSERT_VK_SUCCESS(err);
9756 VkBufferCreateInfo sb_ci = {};
9757 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9758 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9759 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9760 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9761 VkBuffer storage_buffer;
9762 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9763 ASSERT_VK_SUCCESS(err);
9764 // Have to bind memory to buffer before descriptor update
9765 VkMemoryAllocateInfo mem_alloc = {};
9766 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9767 mem_alloc.pNext = NULL;
9768 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9769 mem_alloc.memoryTypeIndex = 0;
9770
Cort Stratton77a0d592017-02-17 13:14:13 -08009771 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9772 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9773 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9774 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9775 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009776 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009778 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009779 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9780 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009781 return;
9782 }
9783
9784 VkDeviceMemory mem;
9785 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009786 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009787 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009788 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9789 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9790 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9792 return;
9793 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009794 ASSERT_VK_SUCCESS(err);
9795 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9796 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009797 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009798 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9799 ASSERT_VK_SUCCESS(err);
9800
9801 VkDescriptorBufferInfo buff_info = {};
9802 buff_info.buffer = uniform_buffer;
9803 buff_info.range = ub_ci.size; // This will exceed limit
9804 VkWriteDescriptorSet descriptor_write = {};
9805 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9806 descriptor_write.dstBinding = 0;
9807 descriptor_write.descriptorCount = 1;
9808 descriptor_write.pTexelBufferView = nullptr;
9809 descriptor_write.pBufferInfo = &buff_info;
9810 descriptor_write.pImageInfo = nullptr;
9811
9812 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9813 descriptor_write.dstSet = descriptor_set;
9814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9815 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9816 m_errorMonitor->VerifyFound();
9817
9818 // Reduce size of range to acceptable limit & cause offset error
9819 buff_info.range = max_ub_range;
9820 buff_info.offset = min_ub_align - 1;
9821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9822 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9823 m_errorMonitor->VerifyFound();
9824
9825 // Now break storage updates
9826 buff_info.buffer = storage_buffer;
9827 buff_info.range = sb_ci.size; // This will exceed limit
9828 buff_info.offset = 0; // Reset offset for this update
9829
9830 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9831 descriptor_write.dstBinding = 1;
9832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9833 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9834 m_errorMonitor->VerifyFound();
9835
9836 // Reduce size of range to acceptable limit & cause offset error
9837 buff_info.range = max_sb_range;
9838 buff_info.offset = min_sb_align - 1;
9839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9840 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9841 m_errorMonitor->VerifyFound();
9842
9843 vkFreeMemory(m_device->device(), mem, NULL);
9844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9845 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9846 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9847 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9848}
9849
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009850TEST_F(VkLayerTest, DSAspectBitsErrors) {
9851 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9852 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009853 TEST_DESCRIPTION(
9854 "Attempt to update descriptor sets for images "
9855 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009856 VkResult err;
9857
9858 ASSERT_NO_FATAL_FAILURE(InitState());
9859 VkDescriptorPoolSize ds_type_count = {};
9860 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9861 ds_type_count.descriptorCount = 1;
9862
9863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9865 ds_pool_ci.pNext = NULL;
9866 ds_pool_ci.maxSets = 5;
9867 ds_pool_ci.poolSizeCount = 1;
9868 ds_pool_ci.pPoolSizes = &ds_type_count;
9869
9870 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009871 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009872 ASSERT_VK_SUCCESS(err);
9873
9874 VkDescriptorSetLayoutBinding dsl_binding = {};
9875 dsl_binding.binding = 0;
9876 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9877 dsl_binding.descriptorCount = 1;
9878 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9879 dsl_binding.pImmutableSamplers = NULL;
9880
9881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9883 ds_layout_ci.pNext = NULL;
9884 ds_layout_ci.bindingCount = 1;
9885 ds_layout_ci.pBindings = &dsl_binding;
9886 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009888 ASSERT_VK_SUCCESS(err);
9889
9890 VkDescriptorSet descriptor_set = {};
9891 VkDescriptorSetAllocateInfo alloc_info = {};
9892 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9893 alloc_info.descriptorSetCount = 1;
9894 alloc_info.descriptorPool = ds_pool;
9895 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009896 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009897 ASSERT_VK_SUCCESS(err);
9898
9899 // Create an image to be used for invalid updates
9900 VkImageCreateInfo image_ci = {};
9901 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9902 image_ci.imageType = VK_IMAGE_TYPE_2D;
9903 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9904 image_ci.extent.width = 64;
9905 image_ci.extent.height = 64;
9906 image_ci.extent.depth = 1;
9907 image_ci.mipLevels = 1;
9908 image_ci.arrayLayers = 1;
9909 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009910 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009911 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9912 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9913 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9914 VkImage image;
9915 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9916 ASSERT_VK_SUCCESS(err);
9917 // Bind memory to image
9918 VkMemoryRequirements mem_reqs;
9919 VkDeviceMemory image_mem;
9920 bool pass;
9921 VkMemoryAllocateInfo mem_alloc = {};
9922 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9923 mem_alloc.pNext = NULL;
9924 mem_alloc.allocationSize = 0;
9925 mem_alloc.memoryTypeIndex = 0;
9926 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9927 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009929 ASSERT_TRUE(pass);
9930 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9931 ASSERT_VK_SUCCESS(err);
9932 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9933 ASSERT_VK_SUCCESS(err);
9934 // Now create view for image
9935 VkImageViewCreateInfo image_view_ci = {};
9936 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9937 image_view_ci.image = image;
9938 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9939 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9940 image_view_ci.subresourceRange.layerCount = 1;
9941 image_view_ci.subresourceRange.baseArrayLayer = 0;
9942 image_view_ci.subresourceRange.levelCount = 1;
9943 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009945
9946 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009948 ASSERT_VK_SUCCESS(err);
9949
9950 VkDescriptorImageInfo img_info = {};
9951 img_info.imageView = image_view;
9952 VkWriteDescriptorSet descriptor_write = {};
9953 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9954 descriptor_write.dstBinding = 0;
9955 descriptor_write.descriptorCount = 1;
9956 descriptor_write.pTexelBufferView = NULL;
9957 descriptor_write.pBufferInfo = NULL;
9958 descriptor_write.pImageInfo = &img_info;
9959 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9960 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009961 const char *error_msg =
9962 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9963 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009965
9966 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9967
9968 m_errorMonitor->VerifyFound();
9969 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9970 vkDestroyImage(m_device->device(), image, NULL);
9971 vkFreeMemory(m_device->device(), image_mem, NULL);
9972 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009973 m_errorMonitor->SetUnexpectedError(
9974 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009975 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9976 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9977}
9978
Karl Schultz6addd812016-02-02 17:17:23 -07009979TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009980 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009981 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9984 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9985 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009986
Tobin Ehlis3b780662015-05-28 12:11:26 -06009987 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009988 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009989 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009990 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9991 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009992
9993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9995 ds_pool_ci.pNext = NULL;
9996 ds_pool_ci.maxSets = 1;
9997 ds_pool_ci.poolSizeCount = 1;
9998 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009999
Tobin Ehlis3b780662015-05-28 12:11:26 -060010000 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010002 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010003 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010004 dsl_binding.binding = 0;
10005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10006 dsl_binding.descriptorCount = 1;
10007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10008 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010009
Tony Barboureb254902015-07-15 12:50:33 -060010010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10012 ds_layout_ci.pNext = NULL;
10013 ds_layout_ci.bindingCount = 1;
10014 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010015
Tobin Ehlis3b780662015-05-28 12:11:26 -060010016 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010018 ASSERT_VK_SUCCESS(err);
10019
10020 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010021 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010023 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010024 alloc_info.descriptorPool = ds_pool;
10025 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010027 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010028
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010029 VkSamplerCreateInfo sampler_ci = {};
10030 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10031 sampler_ci.pNext = NULL;
10032 sampler_ci.magFilter = VK_FILTER_NEAREST;
10033 sampler_ci.minFilter = VK_FILTER_NEAREST;
10034 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10035 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10036 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10037 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10038 sampler_ci.mipLodBias = 1.0;
10039 sampler_ci.anisotropyEnable = VK_FALSE;
10040 sampler_ci.maxAnisotropy = 1;
10041 sampler_ci.compareEnable = VK_FALSE;
10042 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10043 sampler_ci.minLod = 1.0;
10044 sampler_ci.maxLod = 1.0;
10045 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10046 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10047 VkSampler sampler;
10048 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10049 ASSERT_VK_SUCCESS(err);
10050
10051 VkDescriptorImageInfo info = {};
10052 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010053
10054 VkWriteDescriptorSet descriptor_write;
10055 memset(&descriptor_write, 0, sizeof(descriptor_write));
10056 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010057 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010058 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010059 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010060 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010061 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010062
10063 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010065 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010066
Chia-I Wuf7458c52015-10-26 21:10:41 +080010067 vkDestroySampler(m_device->device(), sampler, NULL);
10068 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10069 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010070}
10071
Karl Schultz6addd812016-02-02 17:17:23 -070010072TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010073 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010074 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010075
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010077
Tobin Ehlis3b780662015-05-28 12:11:26 -060010078 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010079 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010080 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010081 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10082 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010083
10084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10086 ds_pool_ci.pNext = NULL;
10087 ds_pool_ci.maxSets = 1;
10088 ds_pool_ci.poolSizeCount = 1;
10089 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010090
Tobin Ehlis3b780662015-05-28 12:11:26 -060010091 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010093 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010094
Tony Barboureb254902015-07-15 12:50:33 -060010095 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010096 dsl_binding.binding = 0;
10097 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10098 dsl_binding.descriptorCount = 1;
10099 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10100 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010101
10102 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010103 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10104 ds_layout_ci.pNext = NULL;
10105 ds_layout_ci.bindingCount = 1;
10106 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010107
Tobin Ehlis3b780662015-05-28 12:11:26 -060010108 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010109 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010110 ASSERT_VK_SUCCESS(err);
10111
10112 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010113 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010115 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010116 alloc_info.descriptorPool = ds_pool;
10117 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010120
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010121 // Correctly update descriptor to avoid "NOT_UPDATED" error
10122 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010123 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010124 buff_info.offset = 0;
10125 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010126
10127 VkWriteDescriptorSet descriptor_write;
10128 memset(&descriptor_write, 0, sizeof(descriptor_write));
10129 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010130 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010131 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010132 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010133 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10134 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010135
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010136 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010137 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010139 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010140
Chia-I Wuf7458c52015-10-26 21:10:41 +080010141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010143}
10144
Karl Schultz6addd812016-02-02 17:17:23 -070010145TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010146 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010147 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010150
Tobin Ehlis3b780662015-05-28 12:11:26 -060010151 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010152 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010153 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010154 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10155 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010156
10157 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010158 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10159 ds_pool_ci.pNext = NULL;
10160 ds_pool_ci.maxSets = 1;
10161 ds_pool_ci.poolSizeCount = 1;
10162 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010163
Tobin Ehlis3b780662015-05-28 12:11:26 -060010164 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010166 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010167
Tony Barboureb254902015-07-15 12:50:33 -060010168 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010169 dsl_binding.binding = 0;
10170 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10171 dsl_binding.descriptorCount = 1;
10172 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10173 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010174
10175 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010176 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10177 ds_layout_ci.pNext = NULL;
10178 ds_layout_ci.bindingCount = 1;
10179 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010180 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010182 ASSERT_VK_SUCCESS(err);
10183
10184 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010185 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010187 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010188 alloc_info.descriptorPool = ds_pool;
10189 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010192
Tony Barboureb254902015-07-15 12:50:33 -060010193 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010194 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10195 sampler_ci.pNext = NULL;
10196 sampler_ci.magFilter = VK_FILTER_NEAREST;
10197 sampler_ci.minFilter = VK_FILTER_NEAREST;
10198 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10199 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10200 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10201 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10202 sampler_ci.mipLodBias = 1.0;
10203 sampler_ci.anisotropyEnable = VK_FALSE;
10204 sampler_ci.maxAnisotropy = 1;
10205 sampler_ci.compareEnable = VK_FALSE;
10206 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10207 sampler_ci.minLod = 1.0;
10208 sampler_ci.maxLod = 1.0;
10209 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10210 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010211
Tobin Ehlis3b780662015-05-28 12:11:26 -060010212 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010213 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010214 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010215
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010216 VkDescriptorImageInfo info = {};
10217 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010218
10219 VkWriteDescriptorSet descriptor_write;
10220 memset(&descriptor_write, 0, sizeof(descriptor_write));
10221 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010222 descriptor_write.dstSet = descriptorSet;
10223 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010224 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010225 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010226 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010227 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010228
10229 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10230
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010231 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010232
Chia-I Wuf7458c52015-10-26 21:10:41 +080010233 vkDestroySampler(m_device->device(), sampler, NULL);
10234 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10235 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010236}
10237
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010238TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10239 // Create layout w/ empty binding and attempt to update it
10240 VkResult err;
10241
10242 ASSERT_NO_FATAL_FAILURE(InitState());
10243
10244 VkDescriptorPoolSize ds_type_count = {};
10245 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10246 ds_type_count.descriptorCount = 1;
10247
10248 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10249 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10250 ds_pool_ci.pNext = NULL;
10251 ds_pool_ci.maxSets = 1;
10252 ds_pool_ci.poolSizeCount = 1;
10253 ds_pool_ci.pPoolSizes = &ds_type_count;
10254
10255 VkDescriptorPool ds_pool;
10256 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10257 ASSERT_VK_SUCCESS(err);
10258
10259 VkDescriptorSetLayoutBinding dsl_binding = {};
10260 dsl_binding.binding = 0;
10261 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10262 dsl_binding.descriptorCount = 0;
10263 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10264 dsl_binding.pImmutableSamplers = NULL;
10265
10266 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10267 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10268 ds_layout_ci.pNext = NULL;
10269 ds_layout_ci.bindingCount = 1;
10270 ds_layout_ci.pBindings = &dsl_binding;
10271 VkDescriptorSetLayout ds_layout;
10272 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10273 ASSERT_VK_SUCCESS(err);
10274
10275 VkDescriptorSet descriptor_set;
10276 VkDescriptorSetAllocateInfo alloc_info = {};
10277 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10278 alloc_info.descriptorSetCount = 1;
10279 alloc_info.descriptorPool = ds_pool;
10280 alloc_info.pSetLayouts = &ds_layout;
10281 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10282 ASSERT_VK_SUCCESS(err);
10283
10284 VkSamplerCreateInfo sampler_ci = {};
10285 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10286 sampler_ci.magFilter = VK_FILTER_NEAREST;
10287 sampler_ci.minFilter = VK_FILTER_NEAREST;
10288 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10289 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10290 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10291 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10292 sampler_ci.mipLodBias = 1.0;
10293 sampler_ci.maxAnisotropy = 1;
10294 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10295 sampler_ci.minLod = 1.0;
10296 sampler_ci.maxLod = 1.0;
10297 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10298
10299 VkSampler sampler;
10300 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10301 ASSERT_VK_SUCCESS(err);
10302
10303 VkDescriptorImageInfo info = {};
10304 info.sampler = sampler;
10305
10306 VkWriteDescriptorSet descriptor_write;
10307 memset(&descriptor_write, 0, sizeof(descriptor_write));
10308 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10309 descriptor_write.dstSet = descriptor_set;
10310 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010311 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010312 // This is the wrong type, but empty binding error will be flagged first
10313 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10314 descriptor_write.pImageInfo = &info;
10315
10316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10317 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10318 m_errorMonitor->VerifyFound();
10319
10320 vkDestroySampler(m_device->device(), sampler, NULL);
10321 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10322 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10323}
10324
Karl Schultz6addd812016-02-02 17:17:23 -070010325TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10326 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10327 // types
10328 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010331
Tobin Ehlis3b780662015-05-28 12:11:26 -060010332 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010333
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010334 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010335 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10336 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010337
10338 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010339 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10340 ds_pool_ci.pNext = NULL;
10341 ds_pool_ci.maxSets = 1;
10342 ds_pool_ci.poolSizeCount = 1;
10343 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010344
Tobin Ehlis3b780662015-05-28 12:11:26 -060010345 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010347 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010348 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010349 dsl_binding.binding = 0;
10350 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10351 dsl_binding.descriptorCount = 1;
10352 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10353 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354
Tony Barboureb254902015-07-15 12:50:33 -060010355 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010356 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10357 ds_layout_ci.pNext = NULL;
10358 ds_layout_ci.bindingCount = 1;
10359 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010360
Tobin Ehlis3b780662015-05-28 12:11:26 -060010361 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010363 ASSERT_VK_SUCCESS(err);
10364
10365 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010366 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010367 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010368 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010369 alloc_info.descriptorPool = ds_pool;
10370 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010373
Tony Barboureb254902015-07-15 12:50:33 -060010374 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010375 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10376 sampler_ci.pNext = NULL;
10377 sampler_ci.magFilter = VK_FILTER_NEAREST;
10378 sampler_ci.minFilter = VK_FILTER_NEAREST;
10379 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10380 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10381 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10382 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10383 sampler_ci.mipLodBias = 1.0;
10384 sampler_ci.anisotropyEnable = VK_FALSE;
10385 sampler_ci.maxAnisotropy = 1;
10386 sampler_ci.compareEnable = VK_FALSE;
10387 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10388 sampler_ci.minLod = 1.0;
10389 sampler_ci.maxLod = 1.0;
10390 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10391 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010392 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010393 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010394 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010395
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010396 VkDescriptorImageInfo info = {};
10397 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010398
10399 VkWriteDescriptorSet descriptor_write;
10400 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010401 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010402 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010403 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010404 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010405 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010406 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010407
10408 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10409
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010410 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010411
Chia-I Wuf7458c52015-10-26 21:10:41 +080010412 vkDestroySampler(m_device->device(), sampler, NULL);
10413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010415}
10416
Karl Schultz6addd812016-02-02 17:17:23 -070010417TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010418 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010419 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010420
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010422
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010423 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010424 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10425 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010426 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010427 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10428 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010429
10430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10432 ds_pool_ci.pNext = NULL;
10433 ds_pool_ci.maxSets = 1;
10434 ds_pool_ci.poolSizeCount = 1;
10435 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010436
10437 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010439 ASSERT_VK_SUCCESS(err);
10440
10441 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010442 dsl_binding.binding = 0;
10443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10444 dsl_binding.descriptorCount = 1;
10445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010447
10448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10450 ds_layout_ci.pNext = NULL;
10451 ds_layout_ci.bindingCount = 1;
10452 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010453 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010454 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010455 ASSERT_VK_SUCCESS(err);
10456
10457 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010458 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010459 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010460 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010461 alloc_info.descriptorPool = ds_pool;
10462 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010464 ASSERT_VK_SUCCESS(err);
10465
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010466 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010467
10468 VkDescriptorImageInfo descriptor_info;
10469 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10470 descriptor_info.sampler = sampler;
10471
10472 VkWriteDescriptorSet descriptor_write;
10473 memset(&descriptor_write, 0, sizeof(descriptor_write));
10474 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010475 descriptor_write.dstSet = descriptorSet;
10476 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010477 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10479 descriptor_write.pImageInfo = &descriptor_info;
10480
10481 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10482
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010483 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010484
Chia-I Wuf7458c52015-10-26 21:10:41 +080010485 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10486 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010487}
10488
Karl Schultz6addd812016-02-02 17:17:23 -070010489TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10490 // Create a single combined Image/Sampler descriptor and send it an invalid
10491 // imageView
10492 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010493
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010495
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010496 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010497 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010498 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10499 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010500
10501 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010502 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10503 ds_pool_ci.pNext = NULL;
10504 ds_pool_ci.maxSets = 1;
10505 ds_pool_ci.poolSizeCount = 1;
10506 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010507
10508 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010510 ASSERT_VK_SUCCESS(err);
10511
10512 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010513 dsl_binding.binding = 0;
10514 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10515 dsl_binding.descriptorCount = 1;
10516 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10517 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010518
10519 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010520 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10521 ds_layout_ci.pNext = NULL;
10522 ds_layout_ci.bindingCount = 1;
10523 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010524 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010526 ASSERT_VK_SUCCESS(err);
10527
10528 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010529 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010530 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010531 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010532 alloc_info.descriptorPool = ds_pool;
10533 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010535 ASSERT_VK_SUCCESS(err);
10536
10537 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010538 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10539 sampler_ci.pNext = NULL;
10540 sampler_ci.magFilter = VK_FILTER_NEAREST;
10541 sampler_ci.minFilter = VK_FILTER_NEAREST;
10542 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10543 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10544 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10545 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10546 sampler_ci.mipLodBias = 1.0;
10547 sampler_ci.anisotropyEnable = VK_FALSE;
10548 sampler_ci.maxAnisotropy = 1;
10549 sampler_ci.compareEnable = VK_FALSE;
10550 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10551 sampler_ci.minLod = 1.0;
10552 sampler_ci.maxLod = 1.0;
10553 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10554 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010555
10556 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010557 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010558 ASSERT_VK_SUCCESS(err);
10559
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010560 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010561
10562 VkDescriptorImageInfo descriptor_info;
10563 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10564 descriptor_info.sampler = sampler;
10565 descriptor_info.imageView = view;
10566
10567 VkWriteDescriptorSet descriptor_write;
10568 memset(&descriptor_write, 0, sizeof(descriptor_write));
10569 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010570 descriptor_write.dstSet = descriptorSet;
10571 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010572 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010573 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10574 descriptor_write.pImageInfo = &descriptor_info;
10575
10576 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10577
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010578 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579
Chia-I Wuf7458c52015-10-26 21:10:41 +080010580 vkDestroySampler(m_device->device(), sampler, NULL);
10581 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10582 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010583}
10584
Karl Schultz6addd812016-02-02 17:17:23 -070010585TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10586 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10587 // into the other
10588 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10591 " binding #1 with type "
10592 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10593 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010594
Tobin Ehlis04356f92015-10-27 16:35:27 -060010595 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010596 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010597 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010598 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10599 ds_type_count[0].descriptorCount = 1;
10600 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10601 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010602
10603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10605 ds_pool_ci.pNext = NULL;
10606 ds_pool_ci.maxSets = 1;
10607 ds_pool_ci.poolSizeCount = 2;
10608 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010609
10610 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010611 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010612 ASSERT_VK_SUCCESS(err);
10613 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010614 dsl_binding[0].binding = 0;
10615 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10616 dsl_binding[0].descriptorCount = 1;
10617 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10618 dsl_binding[0].pImmutableSamplers = NULL;
10619 dsl_binding[1].binding = 1;
10620 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10621 dsl_binding[1].descriptorCount = 1;
10622 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10623 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010624
10625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10627 ds_layout_ci.pNext = NULL;
10628 ds_layout_ci.bindingCount = 2;
10629 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010630
10631 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010633 ASSERT_VK_SUCCESS(err);
10634
10635 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010636 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010637 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010638 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010639 alloc_info.descriptorPool = ds_pool;
10640 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010641 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010642 ASSERT_VK_SUCCESS(err);
10643
10644 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010645 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10646 sampler_ci.pNext = NULL;
10647 sampler_ci.magFilter = VK_FILTER_NEAREST;
10648 sampler_ci.minFilter = VK_FILTER_NEAREST;
10649 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10650 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10651 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10652 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10653 sampler_ci.mipLodBias = 1.0;
10654 sampler_ci.anisotropyEnable = VK_FALSE;
10655 sampler_ci.maxAnisotropy = 1;
10656 sampler_ci.compareEnable = VK_FALSE;
10657 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10658 sampler_ci.minLod = 1.0;
10659 sampler_ci.maxLod = 1.0;
10660 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10661 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010662
10663 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010664 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010665 ASSERT_VK_SUCCESS(err);
10666
10667 VkDescriptorImageInfo info = {};
10668 info.sampler = sampler;
10669
10670 VkWriteDescriptorSet descriptor_write;
10671 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010673 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010674 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010675 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10677 descriptor_write.pImageInfo = &info;
10678 // This write update should succeed
10679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10680 // Now perform a copy update that fails due to type mismatch
10681 VkCopyDescriptorSet copy_ds_update;
10682 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10683 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10684 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010685 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010686 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010687 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10688 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010689 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010691 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010692 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060010694 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10695 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10696 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010697 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010698 copy_ds_update.dstSet = descriptorSet;
10699 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010700 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010701 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10702
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010703 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010704
Tobin Ehlis04356f92015-10-27 16:35:27 -060010705 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10707 " binding#1 with offset index of 1 plus "
10708 "update array offset of 0 and update of "
10709 "5 descriptors oversteps total number "
10710 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010711
Tobin Ehlis04356f92015-10-27 16:35:27 -060010712 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10713 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10714 copy_ds_update.srcSet = descriptorSet;
10715 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010716 copy_ds_update.dstSet = descriptorSet;
10717 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010718 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010719 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10720
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010721 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010722
Chia-I Wuf7458c52015-10-26 21:10:41 +080010723 vkDestroySampler(m_device->device(), sampler, NULL);
10724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010726}
10727
Karl Schultz6addd812016-02-02 17:17:23 -070010728TEST_F(VkLayerTest, NumSamplesMismatch) {
10729 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10730 // sampleCount
10731 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010734
Tobin Ehlis3b780662015-05-28 12:11:26 -060010735 ASSERT_NO_FATAL_FAILURE(InitState());
10736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010737 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010739 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010740
10741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10743 ds_pool_ci.pNext = NULL;
10744 ds_pool_ci.maxSets = 1;
10745 ds_pool_ci.poolSizeCount = 1;
10746 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010747
Tobin Ehlis3b780662015-05-28 12:11:26 -060010748 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010750 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010751
Tony Barboureb254902015-07-15 12:50:33 -060010752 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010753 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010754 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010755 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010756 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10757 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010758
Tony Barboureb254902015-07-15 12:50:33 -060010759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10761 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010762 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010763 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010764
Tobin Ehlis3b780662015-05-28 12:11:26 -060010765 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010767 ASSERT_VK_SUCCESS(err);
10768
10769 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010770 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010772 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010773 alloc_info.descriptorPool = ds_pool;
10774 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010776 ASSERT_VK_SUCCESS(err);
10777
Tony Barboureb254902015-07-15 12:50:33 -060010778 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010780 pipe_ms_state_ci.pNext = NULL;
10781 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10782 pipe_ms_state_ci.sampleShadingEnable = 0;
10783 pipe_ms_state_ci.minSampleShading = 1.0;
10784 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010785
Tony Barboureb254902015-07-15 12:50:33 -060010786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10788 pipeline_layout_ci.pNext = NULL;
10789 pipeline_layout_ci.setLayoutCount = 1;
10790 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010791
10792 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794 ASSERT_VK_SUCCESS(err);
10795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010796 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010797 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010798 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010799 VkPipelineObj pipe(m_device);
10800 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010801 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010802 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010803 pipe.SetMSAA(&pipe_ms_state_ci);
10804 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010805
Tony Barbour552f6c02016-12-21 14:34:07 -070010806 m_commandBuffer->BeginCommandBuffer();
10807 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010808 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010809
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010810 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10811 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10812 VkRect2D scissor = {{0, 0}, {16, 16}};
10813 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10814
Mark Young29927482016-05-04 14:38:51 -060010815 // Render triangle (the error should trigger on the attempt to draw).
10816 Draw(3, 1, 0, 0);
10817
10818 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010819 m_commandBuffer->EndRenderPass();
10820 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010822 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010823
Chia-I Wuf7458c52015-10-26 21:10:41 +080010824 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010827}
Mark Young29927482016-05-04 14:38:51 -060010828
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010829TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010830 TEST_DESCRIPTION(
10831 "Hit RenderPass incompatible cases. "
10832 "Initial case is drawing with an active renderpass that's "
10833 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010834 VkResult err;
10835
10836 ASSERT_NO_FATAL_FAILURE(InitState());
10837 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10838
10839 VkDescriptorSetLayoutBinding dsl_binding = {};
10840 dsl_binding.binding = 0;
10841 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10842 dsl_binding.descriptorCount = 1;
10843 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10844 dsl_binding.pImmutableSamplers = NULL;
10845
10846 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10847 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10848 ds_layout_ci.pNext = NULL;
10849 ds_layout_ci.bindingCount = 1;
10850 ds_layout_ci.pBindings = &dsl_binding;
10851
10852 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010854 ASSERT_VK_SUCCESS(err);
10855
10856 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10857 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10858 pipeline_layout_ci.pNext = NULL;
10859 pipeline_layout_ci.setLayoutCount = 1;
10860 pipeline_layout_ci.pSetLayouts = &ds_layout;
10861
10862 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010864 ASSERT_VK_SUCCESS(err);
10865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010867 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010869 // Create a renderpass that will be incompatible with default renderpass
10870 VkAttachmentReference attach = {};
10871 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10872 VkAttachmentReference color_att = {};
10873 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10874 VkSubpassDescription subpass = {};
10875 subpass.inputAttachmentCount = 1;
10876 subpass.pInputAttachments = &attach;
10877 subpass.colorAttachmentCount = 1;
10878 subpass.pColorAttachments = &color_att;
10879 VkRenderPassCreateInfo rpci = {};
10880 rpci.subpassCount = 1;
10881 rpci.pSubpasses = &subpass;
10882 rpci.attachmentCount = 1;
10883 VkAttachmentDescription attach_desc = {};
10884 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010885 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10886 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010887 rpci.pAttachments = &attach_desc;
10888 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10889 VkRenderPass rp;
10890 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10891 VkPipelineObj pipe(m_device);
10892 pipe.AddShader(&vs);
10893 pipe.AddShader(&fs);
10894 pipe.AddColorAttachment();
10895 VkViewport view_port = {};
10896 m_viewports.push_back(view_port);
10897 pipe.SetViewport(m_viewports);
10898 VkRect2D rect = {};
10899 m_scissors.push_back(rect);
10900 pipe.SetScissor(m_scissors);
10901 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10902
10903 VkCommandBufferInheritanceInfo cbii = {};
10904 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10905 cbii.renderPass = rp;
10906 cbii.subpass = 0;
10907 VkCommandBufferBeginInfo cbbi = {};
10908 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10909 cbbi.pInheritanceInfo = &cbii;
10910 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10911 VkRenderPassBeginInfo rpbi = {};
10912 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10913 rpbi.framebuffer = m_framebuffer;
10914 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10916 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010919 // Render triangle (the error should trigger on the attempt to draw).
10920 Draw(3, 1, 0, 0);
10921
10922 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010923 m_commandBuffer->EndRenderPass();
10924 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010925
10926 m_errorMonitor->VerifyFound();
10927
10928 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10929 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10930 vkDestroyRenderPass(m_device->device(), rp, NULL);
10931}
10932
Mark Youngc89c6312016-03-31 16:03:20 -060010933TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10934 // Create Pipeline where the number of blend attachments doesn't match the
10935 // number of color attachments. In this case, we don't add any color
10936 // blend attachments even though we have a color attachment.
10937 VkResult err;
10938
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010940
10941 ASSERT_NO_FATAL_FAILURE(InitState());
10942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10943 VkDescriptorPoolSize ds_type_count = {};
10944 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10945 ds_type_count.descriptorCount = 1;
10946
10947 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10948 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10949 ds_pool_ci.pNext = NULL;
10950 ds_pool_ci.maxSets = 1;
10951 ds_pool_ci.poolSizeCount = 1;
10952 ds_pool_ci.pPoolSizes = &ds_type_count;
10953
10954 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010956 ASSERT_VK_SUCCESS(err);
10957
10958 VkDescriptorSetLayoutBinding dsl_binding = {};
10959 dsl_binding.binding = 0;
10960 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10961 dsl_binding.descriptorCount = 1;
10962 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10963 dsl_binding.pImmutableSamplers = NULL;
10964
10965 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10966 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10967 ds_layout_ci.pNext = NULL;
10968 ds_layout_ci.bindingCount = 1;
10969 ds_layout_ci.pBindings = &dsl_binding;
10970
10971 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010973 ASSERT_VK_SUCCESS(err);
10974
10975 VkDescriptorSet descriptorSet;
10976 VkDescriptorSetAllocateInfo alloc_info = {};
10977 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10978 alloc_info.descriptorSetCount = 1;
10979 alloc_info.descriptorPool = ds_pool;
10980 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010981 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010982 ASSERT_VK_SUCCESS(err);
10983
10984 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010986 pipe_ms_state_ci.pNext = NULL;
10987 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10988 pipe_ms_state_ci.sampleShadingEnable = 0;
10989 pipe_ms_state_ci.minSampleShading = 1.0;
10990 pipe_ms_state_ci.pSampleMask = NULL;
10991
10992 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10993 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10994 pipeline_layout_ci.pNext = NULL;
10995 pipeline_layout_ci.setLayoutCount = 1;
10996 pipeline_layout_ci.pSetLayouts = &ds_layout;
10997
10998 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010999 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011000 ASSERT_VK_SUCCESS(err);
11001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011002 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011003 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011005 VkPipelineObj pipe(m_device);
11006 pipe.AddShader(&vs);
11007 pipe.AddShader(&fs);
11008 pipe.SetMSAA(&pipe_ms_state_ci);
11009 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011010 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011011
11012 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11015}
Mark Young29927482016-05-04 14:38:51 -060011016
Mark Muellerd4914412016-06-13 17:52:06 -060011017TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011018 TEST_DESCRIPTION(
11019 "Points to a wrong colorAttachment index in a VkClearAttachment "
11020 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011021 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011023
11024 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11025 m_errorMonitor->VerifyFound();
11026}
11027
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011028TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011029 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11030 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011031
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011032 ASSERT_NO_FATAL_FAILURE(InitState());
11033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011034
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011035 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011036 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11037 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011038
11039 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011040 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11041 ds_pool_ci.pNext = NULL;
11042 ds_pool_ci.maxSets = 1;
11043 ds_pool_ci.poolSizeCount = 1;
11044 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011045
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011046 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011047 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011048 ASSERT_VK_SUCCESS(err);
11049
Tony Barboureb254902015-07-15 12:50:33 -060011050 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011051 dsl_binding.binding = 0;
11052 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11053 dsl_binding.descriptorCount = 1;
11054 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11055 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011056
Tony Barboureb254902015-07-15 12:50:33 -060011057 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011058 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11059 ds_layout_ci.pNext = NULL;
11060 ds_layout_ci.bindingCount = 1;
11061 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011062
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011063 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011065 ASSERT_VK_SUCCESS(err);
11066
11067 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011068 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011070 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011071 alloc_info.descriptorPool = ds_pool;
11072 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011074 ASSERT_VK_SUCCESS(err);
11075
Tony Barboureb254902015-07-15 12:50:33 -060011076 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011078 pipe_ms_state_ci.pNext = NULL;
11079 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11080 pipe_ms_state_ci.sampleShadingEnable = 0;
11081 pipe_ms_state_ci.minSampleShading = 1.0;
11082 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011083
Tony Barboureb254902015-07-15 12:50:33 -060011084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11086 pipeline_layout_ci.pNext = NULL;
11087 pipeline_layout_ci.setLayoutCount = 1;
11088 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011089
11090 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011092 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011094 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011095 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011096 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011097 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011098
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011099 VkPipelineObj pipe(m_device);
11100 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011101 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011102 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011103 m_errorMonitor->SetUnexpectedError(
11104 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11105 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011106 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011107
Tony Barbour552f6c02016-12-21 14:34:07 -070011108 m_commandBuffer->BeginCommandBuffer();
11109 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011110
Karl Schultz6addd812016-02-02 17:17:23 -070011111 // Main thing we care about for this test is that the VkImage obj we're
11112 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011113 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011114 VkClearAttachment color_attachment;
11115 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11116 color_attachment.clearValue.color.float32[0] = 1.0;
11117 color_attachment.clearValue.color.float32[1] = 1.0;
11118 color_attachment.clearValue.color.float32[2] = 1.0;
11119 color_attachment.clearValue.color.float32[3] = 1.0;
11120 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011122
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011123 // Call for full-sized FB Color attachment prior to issuing a Draw
11124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011125 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011127 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011128
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011129 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11130 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11132 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11133 m_errorMonitor->VerifyFound();
11134
11135 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11136 clear_rect.layerCount = 2;
11137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11138 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011139 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011140
Chia-I Wuf7458c52015-10-26 21:10:41 +080011141 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011144}
11145
Karl Schultz6addd812016-02-02 17:17:23 -070011146TEST_F(VkLayerTest, VtxBufferBadIndex) {
11147 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11150 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011151
Tobin Ehlis502480b2015-06-24 15:53:07 -060011152 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011153 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011155
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011156 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011157 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11158 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011159
11160 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011161 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11162 ds_pool_ci.pNext = NULL;
11163 ds_pool_ci.maxSets = 1;
11164 ds_pool_ci.poolSizeCount = 1;
11165 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011166
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011167 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011168 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011169 ASSERT_VK_SUCCESS(err);
11170
Tony Barboureb254902015-07-15 12:50:33 -060011171 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011172 dsl_binding.binding = 0;
11173 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11174 dsl_binding.descriptorCount = 1;
11175 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11176 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011177
Tony Barboureb254902015-07-15 12:50:33 -060011178 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011179 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11180 ds_layout_ci.pNext = NULL;
11181 ds_layout_ci.bindingCount = 1;
11182 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011183
Tobin Ehlis502480b2015-06-24 15:53:07 -060011184 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011185 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011186 ASSERT_VK_SUCCESS(err);
11187
11188 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011189 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011190 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011191 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011192 alloc_info.descriptorPool = ds_pool;
11193 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011195 ASSERT_VK_SUCCESS(err);
11196
Tony Barboureb254902015-07-15 12:50:33 -060011197 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011199 pipe_ms_state_ci.pNext = NULL;
11200 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11201 pipe_ms_state_ci.sampleShadingEnable = 0;
11202 pipe_ms_state_ci.minSampleShading = 1.0;
11203 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011204
Tony Barboureb254902015-07-15 12:50:33 -060011205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11207 pipeline_layout_ci.pNext = NULL;
11208 pipeline_layout_ci.setLayoutCount = 1;
11209 pipeline_layout_ci.pSetLayouts = &ds_layout;
11210 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011213 ASSERT_VK_SUCCESS(err);
11214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011215 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011216 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011218 VkPipelineObj pipe(m_device);
11219 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011220 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011221 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011222 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011223 pipe.SetViewport(m_viewports);
11224 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011226
Tony Barbour552f6c02016-12-21 14:34:07 -070011227 m_commandBuffer->BeginCommandBuffer();
11228 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011229 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011230 // Don't care about actual data, just need to get to draw to flag error
11231 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011233 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011234 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011235
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011236 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011237
Chia-I Wuf7458c52015-10-26 21:10:41 +080011238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011241}
Mark Muellerdfe37552016-07-07 14:47:42 -060011242
Mark Mueller2ee294f2016-08-04 12:59:48 -060011243TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011244 TEST_DESCRIPTION(
11245 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11246 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011247 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011248
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011249 const char *invalid_queueFamilyIndex_message =
11250 "Invalid queue create request in vkCreateDevice(). Invalid "
11251 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011253 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011254
Mark Mueller880fce52016-08-17 15:23:23 -060011255 // The following test fails with recent NVidia drivers.
11256 // By the time core_validation is reached, the NVidia
11257 // driver has sanitized the invalid condition and core_validation
11258 // is not introduced to the failure condition. This is not the case
11259 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011260 // uint32_t count = static_cast<uint32_t>(~0);
11261 // VkPhysicalDevice physical_device;
11262 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11263 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011266 float queue_priority = 0.0;
11267
11268 VkDeviceQueueCreateInfo queue_create_info = {};
11269 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11270 queue_create_info.queueCount = 1;
11271 queue_create_info.pQueuePriorities = &queue_priority;
11272 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11273
11274 VkPhysicalDeviceFeatures features = m_device->phy().features();
11275 VkDevice testDevice;
11276 VkDeviceCreateInfo device_create_info = {};
11277 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11278 device_create_info.queueCreateInfoCount = 1;
11279 device_create_info.pQueueCreateInfos = &queue_create_info;
11280 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011281 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011282 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11283 m_errorMonitor->VerifyFound();
11284
11285 queue_create_info.queueFamilyIndex = 1;
11286
11287 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11288 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11289 for (unsigned i = 0; i < feature_count; i++) {
11290 if (VK_FALSE == feature_array[i]) {
11291 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011293 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011294 m_errorMonitor->SetUnexpectedError(
11295 "You requested features that are unavailable on this device. You should first query feature availability by "
11296 "calling vkGetPhysicalDeviceFeatures().");
11297 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011298 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11299 m_errorMonitor->VerifyFound();
11300 break;
11301 }
11302 }
11303}
11304
Tobin Ehlis16edf082016-11-21 12:33:49 -070011305TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11306 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11307
11308 ASSERT_NO_FATAL_FAILURE(InitState());
11309
11310 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11311 std::vector<VkDeviceQueueCreateInfo> queue_info;
11312 queue_info.reserve(queue_props.size());
11313 std::vector<std::vector<float>> queue_priorities;
11314 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11315 VkDeviceQueueCreateInfo qi{};
11316 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11317 qi.queueFamilyIndex = i;
11318 qi.queueCount = queue_props[i].queueCount;
11319 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11320 qi.pQueuePriorities = queue_priorities[i].data();
11321 queue_info.push_back(qi);
11322 }
11323
11324 std::vector<const char *> device_extension_names;
11325
11326 VkDevice local_device;
11327 VkDeviceCreateInfo device_create_info = {};
11328 auto features = m_device->phy().features();
11329 // Intentionally disable pipeline stats
11330 features.pipelineStatisticsQuery = VK_FALSE;
11331 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11332 device_create_info.pNext = NULL;
11333 device_create_info.queueCreateInfoCount = queue_info.size();
11334 device_create_info.pQueueCreateInfos = queue_info.data();
11335 device_create_info.enabledLayerCount = 0;
11336 device_create_info.ppEnabledLayerNames = NULL;
11337 device_create_info.pEnabledFeatures = &features;
11338 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11339 ASSERT_VK_SUCCESS(err);
11340
11341 VkQueryPoolCreateInfo qpci{};
11342 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11343 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11344 qpci.queryCount = 1;
11345 VkQueryPool query_pool;
11346
11347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11348 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11349 m_errorMonitor->VerifyFound();
11350
11351 vkDestroyDevice(local_device, nullptr);
11352}
11353
Mark Mueller2ee294f2016-08-04 12:59:48 -060011354TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011355 TEST_DESCRIPTION(
11356 "Use an invalid queue index in a vkCmdWaitEvents call."
11357 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011359 const char *invalid_queue_index =
11360 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11361 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11362 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011364 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011367
11368 ASSERT_NO_FATAL_FAILURE(InitState());
11369
11370 VkEvent event;
11371 VkEventCreateInfo event_create_info{};
11372 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11373 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11374
Mark Mueller2ee294f2016-08-04 12:59:48 -060011375 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011376 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011377
Tony Barbour552f6c02016-12-21 14:34:07 -070011378 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011379
11380 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011382 ASSERT_TRUE(image.initialized());
11383 VkImageMemoryBarrier img_barrier = {};
11384 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11385 img_barrier.pNext = NULL;
11386 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11387 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11388 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11389 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11390 img_barrier.image = image.handle();
11391 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011392
11393 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11394 // that layer validation catches the case when it is not.
11395 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011396 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11397 img_barrier.subresourceRange.baseArrayLayer = 0;
11398 img_barrier.subresourceRange.baseMipLevel = 0;
11399 img_barrier.subresourceRange.layerCount = 1;
11400 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11402 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011403 m_errorMonitor->VerifyFound();
11404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011406
11407 VkQueryPool query_pool;
11408 VkQueryPoolCreateInfo query_pool_create_info = {};
11409 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11410 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11411 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011412 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011414 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011415 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11416
11417 vkEndCommandBuffer(m_commandBuffer->handle());
11418 m_errorMonitor->VerifyFound();
11419
11420 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11421 vkDestroyEvent(m_device->device(), event, nullptr);
11422}
11423
Mark Muellerdfe37552016-07-07 14:47:42 -060011424TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011425 TEST_DESCRIPTION(
11426 "Submit a command buffer using deleted vertex buffer, "
11427 "delete a buffer twice, use an invalid offset for each "
11428 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011429
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011430 const char *deleted_buffer_in_command_buffer =
11431 "Cannot submit cmd buffer "
11432 "using deleted buffer ";
11433 const char *invalid_offset_message =
11434 "vkBindBufferMemory(): "
11435 "memoryOffset is 0x";
11436 const char *invalid_storage_buffer_offset_message =
11437 "vkBindBufferMemory(): "
11438 "storage memoryOffset "
11439 "is 0x";
11440 const char *invalid_texel_buffer_offset_message =
11441 "vkBindBufferMemory(): "
11442 "texel memoryOffset "
11443 "is 0x";
11444 const char *invalid_uniform_buffer_offset_message =
11445 "vkBindBufferMemory(): "
11446 "uniform memoryOffset "
11447 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011448
11449 ASSERT_NO_FATAL_FAILURE(InitState());
11450 ASSERT_NO_FATAL_FAILURE(InitViewport());
11451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11452
11453 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011454 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011455 pipe_ms_state_ci.pNext = NULL;
11456 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11457 pipe_ms_state_ci.sampleShadingEnable = 0;
11458 pipe_ms_state_ci.minSampleShading = 1.0;
11459 pipe_ms_state_ci.pSampleMask = nullptr;
11460
11461 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11462 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11463 VkPipelineLayout pipeline_layout;
11464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011466 ASSERT_VK_SUCCESS(err);
11467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011468 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11469 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011470 VkPipelineObj pipe(m_device);
11471 pipe.AddShader(&vs);
11472 pipe.AddShader(&fs);
11473 pipe.AddColorAttachment();
11474 pipe.SetMSAA(&pipe_ms_state_ci);
11475 pipe.SetViewport(m_viewports);
11476 pipe.SetScissor(m_scissors);
11477 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11478
Tony Barbour552f6c02016-12-21 14:34:07 -070011479 m_commandBuffer->BeginCommandBuffer();
11480 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011481 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011482
11483 {
11484 // Create and bind a vertex buffer in a reduced scope, which will cause
11485 // it to be deleted upon leaving this scope
11486 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011487 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011488 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11489 draw_verticies.AddVertexInputToPipe(pipe);
11490 }
11491
11492 Draw(1, 0, 0, 0);
11493
Tony Barbour552f6c02016-12-21 14:34:07 -070011494 m_commandBuffer->EndRenderPass();
11495 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011498 QueueCommandBuffer(false);
11499 m_errorMonitor->VerifyFound();
11500
11501 {
11502 // Create and bind a vertex buffer in a reduced scope, and delete it
11503 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011504 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011506 buffer_test.TestDoubleDestroy();
11507 }
11508 m_errorMonitor->VerifyFound();
11509
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011510 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011511 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011512 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011514 m_errorMonitor->SetUnexpectedError(
11515 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11516 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011517 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11518 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011519 m_errorMonitor->VerifyFound();
11520 }
11521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11523 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011524 // Create and bind a memory buffer with an invalid offset again,
11525 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011527 m_errorMonitor->SetUnexpectedError(
11528 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11529 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11531 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011532 m_errorMonitor->VerifyFound();
11533 }
11534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011536 // Create and bind a memory buffer with an invalid offset again, but
11537 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011539 m_errorMonitor->SetUnexpectedError(
11540 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11541 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011542 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11543 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011544 m_errorMonitor->VerifyFound();
11545 }
11546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011547 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011548 // Create and bind a memory buffer with an invalid offset again, but
11549 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011551 m_errorMonitor->SetUnexpectedError(
11552 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11553 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11555 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011556 m_errorMonitor->VerifyFound();
11557 }
11558
11559 {
11560 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011562 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11563 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11565 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011566 m_errorMonitor->VerifyFound();
11567 }
11568
11569 {
11570 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011572 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11573 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011574 }
11575 m_errorMonitor->VerifyFound();
11576
11577 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11578}
11579
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011580// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11581TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011582 TEST_DESCRIPTION(
11583 "Hit all possible validation checks associated with the "
11584 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11585 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011586 // 3 in ValidateCmdBufImageLayouts
11587 // * -1 Attempt to submit cmd buf w/ deleted image
11588 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11589 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011590
11591 ASSERT_NO_FATAL_FAILURE(InitState());
11592 // Create src & dst images to use for copy operations
11593 VkImage src_image;
11594 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011595 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011596
11597 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11598 const int32_t tex_width = 32;
11599 const int32_t tex_height = 32;
11600
11601 VkImageCreateInfo image_create_info = {};
11602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11603 image_create_info.pNext = NULL;
11604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11605 image_create_info.format = tex_format;
11606 image_create_info.extent.width = tex_width;
11607 image_create_info.extent.height = tex_height;
11608 image_create_info.extent.depth = 1;
11609 image_create_info.mipLevels = 1;
11610 image_create_info.arrayLayers = 4;
11611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11612 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11613 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011614 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011615 image_create_info.flags = 0;
11616
11617 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11618 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011619 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11621 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011622 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11623 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11625 ASSERT_VK_SUCCESS(err);
11626
11627 // Allocate memory
11628 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011629 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011630 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011631 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11632 mem_alloc.pNext = NULL;
11633 mem_alloc.allocationSize = 0;
11634 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011635
11636 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011637 mem_alloc.allocationSize = img_mem_reqs.size;
11638 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011639 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011640 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011641 ASSERT_VK_SUCCESS(err);
11642
11643 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011644 mem_alloc.allocationSize = img_mem_reqs.size;
11645 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011646 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011647 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011648 ASSERT_VK_SUCCESS(err);
11649
11650 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011651 mem_alloc.allocationSize = img_mem_reqs.size;
11652 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011653 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011654 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011655 ASSERT_VK_SUCCESS(err);
11656
11657 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11658 ASSERT_VK_SUCCESS(err);
11659 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11660 ASSERT_VK_SUCCESS(err);
11661 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11662 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011663
Tony Barbour552f6c02016-12-21 14:34:07 -070011664 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011665 VkImageCopy copy_region;
11666 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11667 copy_region.srcSubresource.mipLevel = 0;
11668 copy_region.srcSubresource.baseArrayLayer = 0;
11669 copy_region.srcSubresource.layerCount = 1;
11670 copy_region.srcOffset.x = 0;
11671 copy_region.srcOffset.y = 0;
11672 copy_region.srcOffset.z = 0;
11673 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11674 copy_region.dstSubresource.mipLevel = 0;
11675 copy_region.dstSubresource.baseArrayLayer = 0;
11676 copy_region.dstSubresource.layerCount = 1;
11677 copy_region.dstOffset.x = 0;
11678 copy_region.dstOffset.y = 0;
11679 copy_region.dstOffset.z = 0;
11680 copy_region.extent.width = 1;
11681 copy_region.extent.height = 1;
11682 copy_region.extent.depth = 1;
11683
11684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11685 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011686 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011687 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011688 m_errorMonitor->VerifyFound();
11689 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11691 "Cannot copy from an image whose source layout is "
11692 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11693 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011694 m_errorMonitor->SetUnexpectedError(
11695 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011696 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011697 m_errorMonitor->VerifyFound();
11698 // Final src error is due to bad layout type
11699 m_errorMonitor->SetDesiredFailureMsg(
11700 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11701 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011702 m_errorMonitor->SetUnexpectedError(
11703 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11704 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011705 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011706 m_errorMonitor->VerifyFound();
11707 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11709 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011710 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011711 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011712 m_errorMonitor->VerifyFound();
11713 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11715 "Cannot copy from an image whose dest layout is "
11716 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11717 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011718 m_errorMonitor->SetUnexpectedError(
11719 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011720 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011721 m_errorMonitor->VerifyFound();
11722 m_errorMonitor->SetDesiredFailureMsg(
11723 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11724 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011725 m_errorMonitor->SetUnexpectedError(
11726 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11727 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011728 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011729 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011730
Cort3b021012016-12-07 12:00:57 -080011731 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11732 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11733 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11734 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11735 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11736 transfer_dst_image_barrier[0].srcAccessMask = 0;
11737 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11738 transfer_dst_image_barrier[0].image = dst_image;
11739 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11740 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11741 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11742 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11743 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11744 transfer_dst_image_barrier[0].image = depth_image;
11745 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11746 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11747 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11748
11749 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011750 VkClearColorValue color_clear_value = {};
11751 VkImageSubresourceRange clear_range;
11752 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11753 clear_range.baseMipLevel = 0;
11754 clear_range.baseArrayLayer = 0;
11755 clear_range.layerCount = 1;
11756 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011757
Cort3b021012016-12-07 12:00:57 -080011758 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11759 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011762 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011763 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011764 // Fail due to provided layout not matching actual current layout for color clear.
11765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011766 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011767 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011768
Cort530cf382016-12-08 09:59:47 -080011769 VkClearDepthStencilValue depth_clear_value = {};
11770 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011771
11772 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11773 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011776 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011777 m_errorMonitor->VerifyFound();
11778 // Fail due to provided layout not matching actual current layout for depth clear.
11779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011780 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011781 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011782
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011783 // Now cause error due to bad image layout transition in PipelineBarrier
11784 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011785 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011786 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011787 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011788 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011789 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11790 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011791 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11793 "You cannot transition the layout of aspect 1 from "
11794 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11795 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011796 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11797 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011798 m_errorMonitor->VerifyFound();
11799
11800 // Finally some layout errors at RenderPass create time
11801 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11802 VkAttachmentReference attach = {};
11803 // perf warning for GENERAL layout w/ non-DS input attachment
11804 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11805 VkSubpassDescription subpass = {};
11806 subpass.inputAttachmentCount = 1;
11807 subpass.pInputAttachments = &attach;
11808 VkRenderPassCreateInfo rpci = {};
11809 rpci.subpassCount = 1;
11810 rpci.pSubpasses = &subpass;
11811 rpci.attachmentCount = 1;
11812 VkAttachmentDescription attach_desc = {};
11813 attach_desc.format = VK_FORMAT_UNDEFINED;
11814 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011815 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011816 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11818 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011819 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11820 m_errorMonitor->VerifyFound();
11821 // error w/ non-general layout
11822 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11823
11824 m_errorMonitor->SetDesiredFailureMsg(
11825 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11826 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11827 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11828 m_errorMonitor->VerifyFound();
11829 subpass.inputAttachmentCount = 0;
11830 subpass.colorAttachmentCount = 1;
11831 subpass.pColorAttachments = &attach;
11832 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11833 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11835 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011836 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11837 m_errorMonitor->VerifyFound();
11838 // error w/ non-color opt or GENERAL layout for color attachment
11839 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11840 m_errorMonitor->SetDesiredFailureMsg(
11841 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11842 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11843 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11844 m_errorMonitor->VerifyFound();
11845 subpass.colorAttachmentCount = 0;
11846 subpass.pDepthStencilAttachment = &attach;
11847 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11848 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11850 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011851 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11852 m_errorMonitor->VerifyFound();
11853 // error w/ non-ds opt or GENERAL layout for color attachment
11854 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11856 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11857 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011858 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11859 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011860 // For this error we need a valid renderpass so create default one
11861 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11862 attach.attachment = 0;
11863 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11864 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11865 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11866 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11867 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11868 // Can't do a CLEAR load on READ_ONLY initialLayout
11869 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11870 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11871 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11873 " with invalid first layout "
11874 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11875 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011876 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11877 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011878
Cort3b021012016-12-07 12:00:57 -080011879 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11880 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11881 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011882 vkDestroyImage(m_device->device(), src_image, NULL);
11883 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011884 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011885}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011886
Tobin Ehlise0936662016-10-11 08:10:51 -060011887TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11888 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11889 VkResult err;
11890
11891 ASSERT_NO_FATAL_FAILURE(InitState());
11892
11893 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11894 VkImageTiling tiling;
11895 VkFormatProperties format_properties;
11896 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11897 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11898 tiling = VK_IMAGE_TILING_LINEAR;
11899 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11900 tiling = VK_IMAGE_TILING_OPTIMAL;
11901 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011902 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011903 return;
11904 }
11905
11906 VkDescriptorPoolSize ds_type = {};
11907 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11908 ds_type.descriptorCount = 1;
11909
11910 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11911 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11912 ds_pool_ci.maxSets = 1;
11913 ds_pool_ci.poolSizeCount = 1;
11914 ds_pool_ci.pPoolSizes = &ds_type;
11915 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11916
11917 VkDescriptorPool ds_pool;
11918 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11919 ASSERT_VK_SUCCESS(err);
11920
11921 VkDescriptorSetLayoutBinding dsl_binding = {};
11922 dsl_binding.binding = 0;
11923 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11924 dsl_binding.descriptorCount = 1;
11925 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11926 dsl_binding.pImmutableSamplers = NULL;
11927
11928 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11929 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11930 ds_layout_ci.pNext = NULL;
11931 ds_layout_ci.bindingCount = 1;
11932 ds_layout_ci.pBindings = &dsl_binding;
11933
11934 VkDescriptorSetLayout ds_layout;
11935 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11936 ASSERT_VK_SUCCESS(err);
11937
11938 VkDescriptorSetAllocateInfo alloc_info = {};
11939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11940 alloc_info.descriptorSetCount = 1;
11941 alloc_info.descriptorPool = ds_pool;
11942 alloc_info.pSetLayouts = &ds_layout;
11943 VkDescriptorSet descriptor_set;
11944 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11945 ASSERT_VK_SUCCESS(err);
11946
11947 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11948 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11949 pipeline_layout_ci.pNext = NULL;
11950 pipeline_layout_ci.setLayoutCount = 1;
11951 pipeline_layout_ci.pSetLayouts = &ds_layout;
11952 VkPipelineLayout pipeline_layout;
11953 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11954 ASSERT_VK_SUCCESS(err);
11955
11956 VkImageObj image(m_device);
11957 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11958 ASSERT_TRUE(image.initialized());
11959 VkImageView view = image.targetView(tex_format);
11960
11961 VkDescriptorImageInfo image_info = {};
11962 image_info.imageView = view;
11963 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11964
11965 VkWriteDescriptorSet descriptor_write = {};
11966 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11967 descriptor_write.dstSet = descriptor_set;
11968 descriptor_write.dstBinding = 0;
11969 descriptor_write.descriptorCount = 1;
11970 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11971 descriptor_write.pImageInfo = &image_info;
11972
11973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11974 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11975 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11977 m_errorMonitor->VerifyFound();
11978
11979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11981 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11983}
11984
Mark Mueller93b938f2016-08-18 10:27:40 -060011985TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011986 TEST_DESCRIPTION(
11987 "Use vkCmdExecuteCommands with invalid state "
11988 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011989
11990 ASSERT_NO_FATAL_FAILURE(InitState());
11991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11992
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011993 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011994 const char *simultaneous_use_message2 =
11995 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11996 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011997
11998 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011999 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012000 command_buffer_allocate_info.commandPool = m_commandPool;
12001 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12002 command_buffer_allocate_info.commandBufferCount = 1;
12003
12004 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012005 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012006 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12007 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012008 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012009 command_buffer_inheritance_info.renderPass = m_renderPass;
12010 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012011
Mark Mueller93b938f2016-08-18 10:27:40 -060012012 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012013 command_buffer_begin_info.flags =
12014 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012015 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12016
12017 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12018 vkEndCommandBuffer(secondary_command_buffer);
12019
Mark Mueller93b938f2016-08-18 10:27:40 -060012020 VkSubmitInfo submit_info = {};
12021 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12022 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012024
Mark Mueller4042b652016-09-05 22:52:21 -060012025 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12028 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012029 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012030 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012031 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12032 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012033
Dave Houltonfbf52152017-01-06 12:55:29 -070012034 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012036 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012037
Mark Mueller4042b652016-09-05 22:52:21 -060012038 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012039 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12040 m_errorMonitor->SetUnexpectedError(
12041 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12042 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012043 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012044 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12047 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012048 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012049 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12050 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012051
12052 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012053
12054 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012055}
12056
Tony Barbour626994c2017-02-08 15:29:37 -070012057TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12058 TEST_DESCRIPTION(
12059 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12060 "errors");
12061 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12062 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12063 ASSERT_NO_FATAL_FAILURE(InitState());
12064
12065 VkCommandBuffer cmd_bufs[2];
12066 VkCommandBufferAllocateInfo alloc_info;
12067 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12068 alloc_info.pNext = NULL;
12069 alloc_info.commandBufferCount = 2;
12070 alloc_info.commandPool = m_commandPool;
12071 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12072 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12073
12074 VkCommandBufferBeginInfo cb_binfo;
12075 cb_binfo.pNext = NULL;
12076 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12077 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12078 cb_binfo.flags = 0;
12079 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12080 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12081 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12082 vkEndCommandBuffer(cmd_bufs[0]);
12083 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12084
12085 VkSubmitInfo submit_info = {};
12086 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12087 submit_info.commandBufferCount = 2;
12088 submit_info.pCommandBuffers = duplicates;
12089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12090 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12091 m_errorMonitor->VerifyFound();
12092 vkQueueWaitIdle(m_device->m_queue);
12093
12094 // Set one time use and now look for one time submit
12095 duplicates[0] = duplicates[1] = cmd_bufs[1];
12096 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12097 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12098 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12099 vkEndCommandBuffer(cmd_bufs[1]);
12100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12101 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12102 m_errorMonitor->VerifyFound();
12103 vkQueueWaitIdle(m_device->m_queue);
12104}
12105
Tobin Ehlisb093da82017-01-19 12:05:27 -070012106TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012107 TEST_DESCRIPTION(
12108 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12109 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012110
12111 ASSERT_NO_FATAL_FAILURE(InitState());
12112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12113
12114 std::vector<const char *> device_extension_names;
12115 auto features = m_device->phy().features();
12116 // Make sure gs & ts are disabled
12117 features.geometryShader = false;
12118 features.tessellationShader = false;
12119 // The sacrificial device object
12120 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12121
12122 VkCommandPoolCreateInfo pool_create_info{};
12123 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12124 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12125
12126 VkCommandPool command_pool;
12127 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12128
12129 VkCommandBufferAllocateInfo cmd = {};
12130 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12131 cmd.pNext = NULL;
12132 cmd.commandPool = command_pool;
12133 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12134 cmd.commandBufferCount = 1;
12135
12136 VkCommandBuffer cmd_buffer;
12137 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12138 ASSERT_VK_SUCCESS(err);
12139
12140 VkEvent event;
12141 VkEventCreateInfo evci = {};
12142 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12143 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12144 ASSERT_VK_SUCCESS(result);
12145
12146 VkCommandBufferBeginInfo cbbi = {};
12147 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12148 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12150 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12151 m_errorMonitor->VerifyFound();
12152
12153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12154 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12155 m_errorMonitor->VerifyFound();
12156
12157 vkDestroyEvent(test_device.handle(), event, NULL);
12158 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12159}
12160
Mark Mueller917f6bc2016-08-30 10:57:19 -060012161TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012162 TEST_DESCRIPTION(
12163 "Use vkCmdExecuteCommands with invalid state "
12164 "in primary and secondary command buffers. "
12165 "Delete objects that are inuse. Call VkQueueSubmit "
12166 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012167
12168 ASSERT_NO_FATAL_FAILURE(InitState());
12169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12170
Tony Barbour552f6c02016-12-21 14:34:07 -070012171 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012172
12173 VkEvent event;
12174 VkEventCreateInfo event_create_info = {};
12175 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12176 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012178
Tony Barbour552f6c02016-12-21 14:34:07 -070012179 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012180 vkDestroyEvent(m_device->device(), event, nullptr);
12181
12182 VkSubmitInfo submit_info = {};
12183 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12184 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012187 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12188 m_errorMonitor->VerifyFound();
12189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012190 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012191 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12192
12193 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12194
Mark Mueller917f6bc2016-08-30 10:57:19 -060012195 VkSemaphoreCreateInfo semaphore_create_info = {};
12196 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12197 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012199 VkFenceCreateInfo fence_create_info = {};
12200 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12201 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012202 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012203
12204 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012205 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012206 descriptor_pool_type_count.descriptorCount = 1;
12207
12208 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12209 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12210 descriptor_pool_create_info.maxSets = 1;
12211 descriptor_pool_create_info.poolSizeCount = 1;
12212 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012214
12215 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012216 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012217
12218 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012219 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012220 descriptorset_layout_binding.descriptorCount = 1;
12221 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12222
12223 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012224 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012225 descriptorset_layout_create_info.bindingCount = 1;
12226 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12227
12228 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012229 ASSERT_VK_SUCCESS(
12230 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012231
12232 VkDescriptorSet descriptorset;
12233 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012235 descriptorset_allocate_info.descriptorSetCount = 1;
12236 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12237 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012239
Mark Mueller4042b652016-09-05 22:52:21 -060012240 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12241
12242 VkDescriptorBufferInfo buffer_info = {};
12243 buffer_info.buffer = buffer_test.GetBuffer();
12244 buffer_info.offset = 0;
12245 buffer_info.range = 1024;
12246
12247 VkWriteDescriptorSet write_descriptor_set = {};
12248 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12249 write_descriptor_set.dstSet = descriptorset;
12250 write_descriptor_set.descriptorCount = 1;
12251 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12252 write_descriptor_set.pBufferInfo = &buffer_info;
12253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012254 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012256 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12257 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012258
12259 VkPipelineObj pipe(m_device);
12260 pipe.AddColorAttachment();
12261 pipe.AddShader(&vs);
12262 pipe.AddShader(&fs);
12263
12264 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012266 pipeline_layout_create_info.setLayoutCount = 1;
12267 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12268
12269 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012271
12272 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12273
Tony Barbour552f6c02016-12-21 14:34:07 -070012274 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012275 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12279 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012280
Tony Barbour552f6c02016-12-21 14:34:07 -070012281 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012282
Mark Mueller917f6bc2016-08-30 10:57:19 -060012283 submit_info.signalSemaphoreCount = 1;
12284 submit_info.pSignalSemaphores = &semaphore;
12285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012286 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012287
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012289 vkDestroyEvent(m_device->device(), event, nullptr);
12290 m_errorMonitor->VerifyFound();
12291
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012293 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12294 m_errorMonitor->VerifyFound();
12295
Jeremy Hayes08369882017-02-02 10:31:06 -070012296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012297 vkDestroyFence(m_device->device(), fence, nullptr);
12298 m_errorMonitor->VerifyFound();
12299
Tobin Ehlis122207b2016-09-01 08:50:06 -070012300 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012301 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12302 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012303 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012304 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12305 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012306 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012307 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12308 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012309 vkDestroyEvent(m_device->device(), event, nullptr);
12310 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12313}
12314
Tobin Ehlis2adda372016-09-01 08:51:06 -070012315TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12316 TEST_DESCRIPTION("Delete in-use query pool.");
12317
12318 ASSERT_NO_FATAL_FAILURE(InitState());
12319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12320
12321 VkQueryPool query_pool;
12322 VkQueryPoolCreateInfo query_pool_ci{};
12323 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12324 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12325 query_pool_ci.queryCount = 1;
12326 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012327 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012328 // Reset query pool to create binding with cmd buffer
12329 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12330
Tony Barbour552f6c02016-12-21 14:34:07 -070012331 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012332
12333 VkSubmitInfo submit_info = {};
12334 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12335 submit_info.commandBufferCount = 1;
12336 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12337 // Submit cmd buffer and then destroy query pool while in-flight
12338 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12339
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012341 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12342 m_errorMonitor->VerifyFound();
12343
12344 vkQueueWaitIdle(m_device->m_queue);
12345 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012346 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12347 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012348 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12349}
12350
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012351TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12352 TEST_DESCRIPTION("Delete in-use pipeline.");
12353
12354 ASSERT_NO_FATAL_FAILURE(InitState());
12355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12356
12357 // Empty pipeline layout used for binding PSO
12358 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12359 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12360 pipeline_layout_ci.setLayoutCount = 0;
12361 pipeline_layout_ci.pSetLayouts = NULL;
12362
12363 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012364 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012365 ASSERT_VK_SUCCESS(err);
12366
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012368 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12370 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012371 // Store pipeline handle so we can actually delete it before test finishes
12372 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012373 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012374 VkPipelineObj pipe(m_device);
12375 pipe.AddShader(&vs);
12376 pipe.AddShader(&fs);
12377 pipe.AddColorAttachment();
12378 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12379 delete_this_pipeline = pipe.handle();
12380
Tony Barbour552f6c02016-12-21 14:34:07 -070012381 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012382 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012383 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012384
Tony Barbour552f6c02016-12-21 14:34:07 -070012385 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012386
12387 VkSubmitInfo submit_info = {};
12388 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12389 submit_info.commandBufferCount = 1;
12390 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12391 // Submit cmd buffer and then pipeline destroyed while in-flight
12392 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012393 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012394 m_errorMonitor->VerifyFound();
12395 // Make sure queue finished and then actually delete pipeline
12396 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012397 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12398 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12400 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12401}
12402
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012403TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12404 TEST_DESCRIPTION("Delete in-use imageView.");
12405
12406 ASSERT_NO_FATAL_FAILURE(InitState());
12407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12408
12409 VkDescriptorPoolSize ds_type_count;
12410 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12411 ds_type_count.descriptorCount = 1;
12412
12413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12415 ds_pool_ci.maxSets = 1;
12416 ds_pool_ci.poolSizeCount = 1;
12417 ds_pool_ci.pPoolSizes = &ds_type_count;
12418
12419 VkDescriptorPool ds_pool;
12420 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12421 ASSERT_VK_SUCCESS(err);
12422
12423 VkSamplerCreateInfo sampler_ci = {};
12424 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12425 sampler_ci.pNext = NULL;
12426 sampler_ci.magFilter = VK_FILTER_NEAREST;
12427 sampler_ci.minFilter = VK_FILTER_NEAREST;
12428 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12429 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12430 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12431 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12432 sampler_ci.mipLodBias = 1.0;
12433 sampler_ci.anisotropyEnable = VK_FALSE;
12434 sampler_ci.maxAnisotropy = 1;
12435 sampler_ci.compareEnable = VK_FALSE;
12436 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12437 sampler_ci.minLod = 1.0;
12438 sampler_ci.maxLod = 1.0;
12439 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12440 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12441 VkSampler sampler;
12442
12443 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12444 ASSERT_VK_SUCCESS(err);
12445
12446 VkDescriptorSetLayoutBinding layout_binding;
12447 layout_binding.binding = 0;
12448 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12449 layout_binding.descriptorCount = 1;
12450 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12451 layout_binding.pImmutableSamplers = NULL;
12452
12453 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12454 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12455 ds_layout_ci.bindingCount = 1;
12456 ds_layout_ci.pBindings = &layout_binding;
12457 VkDescriptorSetLayout ds_layout;
12458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12459 ASSERT_VK_SUCCESS(err);
12460
12461 VkDescriptorSetAllocateInfo alloc_info = {};
12462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12463 alloc_info.descriptorSetCount = 1;
12464 alloc_info.descriptorPool = ds_pool;
12465 alloc_info.pSetLayouts = &ds_layout;
12466 VkDescriptorSet descriptor_set;
12467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12468 ASSERT_VK_SUCCESS(err);
12469
12470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12472 pipeline_layout_ci.pNext = NULL;
12473 pipeline_layout_ci.setLayoutCount = 1;
12474 pipeline_layout_ci.pSetLayouts = &ds_layout;
12475
12476 VkPipelineLayout pipeline_layout;
12477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12478 ASSERT_VK_SUCCESS(err);
12479
12480 VkImageObj image(m_device);
12481 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12482 ASSERT_TRUE(image.initialized());
12483
12484 VkImageView view;
12485 VkImageViewCreateInfo ivci = {};
12486 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12487 ivci.image = image.handle();
12488 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12489 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12490 ivci.subresourceRange.layerCount = 1;
12491 ivci.subresourceRange.baseMipLevel = 0;
12492 ivci.subresourceRange.levelCount = 1;
12493 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12494
12495 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12496 ASSERT_VK_SUCCESS(err);
12497
12498 VkDescriptorImageInfo image_info{};
12499 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12500 image_info.imageView = view;
12501 image_info.sampler = sampler;
12502
12503 VkWriteDescriptorSet descriptor_write = {};
12504 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12505 descriptor_write.dstSet = descriptor_set;
12506 descriptor_write.dstBinding = 0;
12507 descriptor_write.descriptorCount = 1;
12508 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12509 descriptor_write.pImageInfo = &image_info;
12510
12511 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12512
12513 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012514 char const *vsSource =
12515 "#version 450\n"
12516 "\n"
12517 "out gl_PerVertex { \n"
12518 " vec4 gl_Position;\n"
12519 "};\n"
12520 "void main(){\n"
12521 " gl_Position = vec4(1);\n"
12522 "}\n";
12523 char const *fsSource =
12524 "#version 450\n"
12525 "\n"
12526 "layout(set=0, binding=0) uniform sampler2D s;\n"
12527 "layout(location=0) out vec4 x;\n"
12528 "void main(){\n"
12529 " x = texture(s, vec2(1));\n"
12530 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12533 VkPipelineObj pipe(m_device);
12534 pipe.AddShader(&vs);
12535 pipe.AddShader(&fs);
12536 pipe.AddColorAttachment();
12537 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12538
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012540
Tony Barbour552f6c02016-12-21 14:34:07 -070012541 m_commandBuffer->BeginCommandBuffer();
12542 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012543 // Bind pipeline to cmd buffer
12544 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12545 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12546 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012547
12548 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12549 VkRect2D scissor = {{0, 0}, {16, 16}};
12550 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12551 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12552
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012553 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012554 m_commandBuffer->EndRenderPass();
12555 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012556 // Submit cmd buffer then destroy sampler
12557 VkSubmitInfo submit_info = {};
12558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12559 submit_info.commandBufferCount = 1;
12560 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12561 // Submit cmd buffer and then destroy imageView while in-flight
12562 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12563
12564 vkDestroyImageView(m_device->device(), view, nullptr);
12565 m_errorMonitor->VerifyFound();
12566 vkQueueWaitIdle(m_device->m_queue);
12567 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012568 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12569 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012570 vkDestroyImageView(m_device->device(), view, NULL);
12571 vkDestroySampler(m_device->device(), sampler, nullptr);
12572 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12575}
12576
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012577TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12578 TEST_DESCRIPTION("Delete in-use bufferView.");
12579
12580 ASSERT_NO_FATAL_FAILURE(InitState());
12581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12582
12583 VkDescriptorPoolSize ds_type_count;
12584 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12585 ds_type_count.descriptorCount = 1;
12586
12587 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12588 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12589 ds_pool_ci.maxSets = 1;
12590 ds_pool_ci.poolSizeCount = 1;
12591 ds_pool_ci.pPoolSizes = &ds_type_count;
12592
12593 VkDescriptorPool ds_pool;
12594 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12595 ASSERT_VK_SUCCESS(err);
12596
12597 VkDescriptorSetLayoutBinding layout_binding;
12598 layout_binding.binding = 0;
12599 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12600 layout_binding.descriptorCount = 1;
12601 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12602 layout_binding.pImmutableSamplers = NULL;
12603
12604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12606 ds_layout_ci.bindingCount = 1;
12607 ds_layout_ci.pBindings = &layout_binding;
12608 VkDescriptorSetLayout ds_layout;
12609 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12610 ASSERT_VK_SUCCESS(err);
12611
12612 VkDescriptorSetAllocateInfo alloc_info = {};
12613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12614 alloc_info.descriptorSetCount = 1;
12615 alloc_info.descriptorPool = ds_pool;
12616 alloc_info.pSetLayouts = &ds_layout;
12617 VkDescriptorSet descriptor_set;
12618 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12619 ASSERT_VK_SUCCESS(err);
12620
12621 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12622 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12623 pipeline_layout_ci.pNext = NULL;
12624 pipeline_layout_ci.setLayoutCount = 1;
12625 pipeline_layout_ci.pSetLayouts = &ds_layout;
12626
12627 VkPipelineLayout pipeline_layout;
12628 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12629 ASSERT_VK_SUCCESS(err);
12630
12631 VkBuffer buffer;
12632 uint32_t queue_family_index = 0;
12633 VkBufferCreateInfo buffer_create_info = {};
12634 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12635 buffer_create_info.size = 1024;
12636 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12637 buffer_create_info.queueFamilyIndexCount = 1;
12638 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12639
12640 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12641 ASSERT_VK_SUCCESS(err);
12642
12643 VkMemoryRequirements memory_reqs;
12644 VkDeviceMemory buffer_memory;
12645
12646 VkMemoryAllocateInfo memory_info = {};
12647 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12648 memory_info.allocationSize = 0;
12649 memory_info.memoryTypeIndex = 0;
12650
12651 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12652 memory_info.allocationSize = memory_reqs.size;
12653 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12654 ASSERT_TRUE(pass);
12655
12656 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12657 ASSERT_VK_SUCCESS(err);
12658 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12659 ASSERT_VK_SUCCESS(err);
12660
12661 VkBufferView view;
12662 VkBufferViewCreateInfo bvci = {};
12663 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12664 bvci.buffer = buffer;
12665 bvci.format = VK_FORMAT_R8_UNORM;
12666 bvci.range = VK_WHOLE_SIZE;
12667
12668 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12669 ASSERT_VK_SUCCESS(err);
12670
12671 VkWriteDescriptorSet descriptor_write = {};
12672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12673 descriptor_write.dstSet = descriptor_set;
12674 descriptor_write.dstBinding = 0;
12675 descriptor_write.descriptorCount = 1;
12676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12677 descriptor_write.pTexelBufferView = &view;
12678
12679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012681 char const *vsSource =
12682 "#version 450\n"
12683 "\n"
12684 "out gl_PerVertex { \n"
12685 " vec4 gl_Position;\n"
12686 "};\n"
12687 "void main(){\n"
12688 " gl_Position = vec4(1);\n"
12689 "}\n";
12690 char const *fsSource =
12691 "#version 450\n"
12692 "\n"
12693 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12694 "layout(location=0) out vec4 x;\n"
12695 "void main(){\n"
12696 " x = imageLoad(s, 0);\n"
12697 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12700 VkPipelineObj pipe(m_device);
12701 pipe.AddShader(&vs);
12702 pipe.AddShader(&fs);
12703 pipe.AddColorAttachment();
12704 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12705
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012707
Tony Barbour552f6c02016-12-21 14:34:07 -070012708 m_commandBuffer->BeginCommandBuffer();
12709 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012710 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12711 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12712 VkRect2D scissor = {{0, 0}, {16, 16}};
12713 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12714 // Bind pipeline to cmd buffer
12715 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12716 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12717 &descriptor_set, 0, nullptr);
12718 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012719 m_commandBuffer->EndRenderPass();
12720 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012721
12722 VkSubmitInfo submit_info = {};
12723 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12724 submit_info.commandBufferCount = 1;
12725 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12726 // Submit cmd buffer and then destroy bufferView while in-flight
12727 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12728
12729 vkDestroyBufferView(m_device->device(), view, nullptr);
12730 m_errorMonitor->VerifyFound();
12731 vkQueueWaitIdle(m_device->m_queue);
12732 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012733 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12734 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012735 vkDestroyBufferView(m_device->device(), view, NULL);
12736 vkDestroyBuffer(m_device->device(), buffer, NULL);
12737 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12741}
12742
Tobin Ehlis209532e2016-09-07 13:52:18 -060012743TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12744 TEST_DESCRIPTION("Delete in-use sampler.");
12745
12746 ASSERT_NO_FATAL_FAILURE(InitState());
12747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12748
12749 VkDescriptorPoolSize ds_type_count;
12750 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12751 ds_type_count.descriptorCount = 1;
12752
12753 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12754 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12755 ds_pool_ci.maxSets = 1;
12756 ds_pool_ci.poolSizeCount = 1;
12757 ds_pool_ci.pPoolSizes = &ds_type_count;
12758
12759 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012760 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012761 ASSERT_VK_SUCCESS(err);
12762
12763 VkSamplerCreateInfo sampler_ci = {};
12764 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12765 sampler_ci.pNext = NULL;
12766 sampler_ci.magFilter = VK_FILTER_NEAREST;
12767 sampler_ci.minFilter = VK_FILTER_NEAREST;
12768 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12769 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12770 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12771 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12772 sampler_ci.mipLodBias = 1.0;
12773 sampler_ci.anisotropyEnable = VK_FALSE;
12774 sampler_ci.maxAnisotropy = 1;
12775 sampler_ci.compareEnable = VK_FALSE;
12776 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12777 sampler_ci.minLod = 1.0;
12778 sampler_ci.maxLod = 1.0;
12779 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12780 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12781 VkSampler sampler;
12782
12783 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12784 ASSERT_VK_SUCCESS(err);
12785
12786 VkDescriptorSetLayoutBinding layout_binding;
12787 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012788 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012789 layout_binding.descriptorCount = 1;
12790 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12791 layout_binding.pImmutableSamplers = NULL;
12792
12793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12795 ds_layout_ci.bindingCount = 1;
12796 ds_layout_ci.pBindings = &layout_binding;
12797 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012798 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012799 ASSERT_VK_SUCCESS(err);
12800
12801 VkDescriptorSetAllocateInfo alloc_info = {};
12802 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12803 alloc_info.descriptorSetCount = 1;
12804 alloc_info.descriptorPool = ds_pool;
12805 alloc_info.pSetLayouts = &ds_layout;
12806 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012807 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012808 ASSERT_VK_SUCCESS(err);
12809
12810 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12811 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12812 pipeline_layout_ci.pNext = NULL;
12813 pipeline_layout_ci.setLayoutCount = 1;
12814 pipeline_layout_ci.pSetLayouts = &ds_layout;
12815
12816 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012817 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012818 ASSERT_VK_SUCCESS(err);
12819
12820 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012821 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012822 ASSERT_TRUE(image.initialized());
12823
12824 VkImageView view;
12825 VkImageViewCreateInfo ivci = {};
12826 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12827 ivci.image = image.handle();
12828 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12829 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12830 ivci.subresourceRange.layerCount = 1;
12831 ivci.subresourceRange.baseMipLevel = 0;
12832 ivci.subresourceRange.levelCount = 1;
12833 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12834
12835 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12836 ASSERT_VK_SUCCESS(err);
12837
12838 VkDescriptorImageInfo image_info{};
12839 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12840 image_info.imageView = view;
12841 image_info.sampler = sampler;
12842
12843 VkWriteDescriptorSet descriptor_write = {};
12844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12845 descriptor_write.dstSet = descriptor_set;
12846 descriptor_write.dstBinding = 0;
12847 descriptor_write.descriptorCount = 1;
12848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12849 descriptor_write.pImageInfo = &image_info;
12850
12851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12852
12853 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012854 char const *vsSource =
12855 "#version 450\n"
12856 "\n"
12857 "out gl_PerVertex { \n"
12858 " vec4 gl_Position;\n"
12859 "};\n"
12860 "void main(){\n"
12861 " gl_Position = vec4(1);\n"
12862 "}\n";
12863 char const *fsSource =
12864 "#version 450\n"
12865 "\n"
12866 "layout(set=0, binding=0) uniform sampler2D s;\n"
12867 "layout(location=0) out vec4 x;\n"
12868 "void main(){\n"
12869 " x = texture(s, vec2(1));\n"
12870 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012871 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12872 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12873 VkPipelineObj pipe(m_device);
12874 pipe.AddShader(&vs);
12875 pipe.AddShader(&fs);
12876 pipe.AddColorAttachment();
12877 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12878
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012880
Tony Barbour552f6c02016-12-21 14:34:07 -070012881 m_commandBuffer->BeginCommandBuffer();
12882 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012883 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012884 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12886 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012887
12888 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12889 VkRect2D scissor = {{0, 0}, {16, 16}};
12890 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12891 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12892
Tobin Ehlis209532e2016-09-07 13:52:18 -060012893 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012894 m_commandBuffer->EndRenderPass();
12895 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012896 // Submit cmd buffer then destroy sampler
12897 VkSubmitInfo submit_info = {};
12898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12899 submit_info.commandBufferCount = 1;
12900 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12901 // Submit cmd buffer and then destroy sampler while in-flight
12902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012904 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012905 m_errorMonitor->VerifyFound();
12906 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012907
Tobin Ehlis209532e2016-09-07 13:52:18 -060012908 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012909 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12910 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012911 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012912 vkDestroyImageView(m_device->device(), view, NULL);
12913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12914 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12916}
12917
Mark Mueller1cd9f412016-08-25 13:23:52 -060012918TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012919 TEST_DESCRIPTION(
12920 "Call VkQueueSubmit with a semaphore that is already "
12921 "signaled but not waited on by the queue. Wait on a "
12922 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012923
12924 ASSERT_NO_FATAL_FAILURE(InitState());
12925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012927 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012928 const char *invalid_fence_wait_message =
12929 " which has not been submitted on a Queue or during "
12930 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012931
Tony Barbour552f6c02016-12-21 14:34:07 -070012932 m_commandBuffer->BeginCommandBuffer();
12933 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012934
12935 VkSemaphoreCreateInfo semaphore_create_info = {};
12936 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12937 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012939 VkSubmitInfo submit_info = {};
12940 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12941 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012942 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012943 submit_info.signalSemaphoreCount = 1;
12944 submit_info.pSignalSemaphores = &semaphore;
12945 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012946 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012947 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012948 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012949 m_commandBuffer->BeginCommandBuffer();
12950 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012952 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12953 m_errorMonitor->VerifyFound();
12954
Mark Mueller1cd9f412016-08-25 13:23:52 -060012955 VkFenceCreateInfo fence_create_info = {};
12956 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12957 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012961 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12962 m_errorMonitor->VerifyFound();
12963
Mark Mueller4042b652016-09-05 22:52:21 -060012964 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012965 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012966 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12967}
12968
Tobin Ehlis4af23302016-07-19 10:50:30 -060012969TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012970 TEST_DESCRIPTION(
12971 "Bind a secondary command buffer with with a framebuffer "
12972 "that does not match the framebuffer for the active "
12973 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012974 ASSERT_NO_FATAL_FAILURE(InitState());
12975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12976
12977 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012978 VkAttachmentDescription attachment = {0,
12979 VK_FORMAT_B8G8R8A8_UNORM,
12980 VK_SAMPLE_COUNT_1_BIT,
12981 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12982 VK_ATTACHMENT_STORE_OP_STORE,
12983 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12984 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12985 VK_IMAGE_LAYOUT_UNDEFINED,
12986 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012988 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012992 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012993
12994 VkRenderPass rp;
12995 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12996 ASSERT_VK_SUCCESS(err);
12997
12998 // A compatible framebuffer.
12999 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013000 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013001 ASSERT_TRUE(image.initialized());
13002
13003 VkImageViewCreateInfo ivci = {
13004 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13005 nullptr,
13006 0,
13007 image.handle(),
13008 VK_IMAGE_VIEW_TYPE_2D,
13009 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013010 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13011 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013012 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13013 };
13014 VkImageView view;
13015 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13016 ASSERT_VK_SUCCESS(err);
13017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013018 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013019 VkFramebuffer fb;
13020 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13021 ASSERT_VK_SUCCESS(err);
13022
13023 VkCommandBufferAllocateInfo cbai = {};
13024 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13025 cbai.commandPool = m_commandPool;
13026 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13027 cbai.commandBufferCount = 1;
13028
13029 VkCommandBuffer sec_cb;
13030 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13031 ASSERT_VK_SUCCESS(err);
13032 VkCommandBufferBeginInfo cbbi = {};
13033 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013034 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013035 cbii.renderPass = renderPass();
13036 cbii.framebuffer = fb;
13037 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13038 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013039 cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013040 cbbi.pInheritanceInfo = &cbii;
13041 vkBeginCommandBuffer(sec_cb, &cbbi);
13042 vkEndCommandBuffer(sec_cb);
13043
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013044 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013045 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13046 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013049 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013050 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13051 m_errorMonitor->VerifyFound();
13052 // Cleanup
13053 vkDestroyImageView(m_device->device(), view, NULL);
13054 vkDestroyRenderPass(m_device->device(), rp, NULL);
13055 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13056}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013057
13058TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013059 TEST_DESCRIPTION(
13060 "If logicOp is available on the device, set it to an "
13061 "invalid value. If logicOp is not available, attempt to "
13062 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013063 ASSERT_NO_FATAL_FAILURE(InitState());
13064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13065
13066 auto features = m_device->phy().features();
13067 // Set the expected error depending on whether or not logicOp available
13068 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13070 "If logic operations feature not "
13071 "enabled, logicOpEnable must be "
13072 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013073 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013075 }
13076 // Create a pipeline using logicOp
13077 VkResult err;
13078
13079 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13080 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13081
13082 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013083 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013084 ASSERT_VK_SUCCESS(err);
13085
13086 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13087 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13088 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013089 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013090 vp_state_ci.pViewports = &vp;
13091 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013092 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013093 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013094
13095 VkPipelineShaderStageCreateInfo shaderStages[2];
13096 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013098 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13099 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013100 shaderStages[0] = vs.GetStageCreateInfo();
13101 shaderStages[1] = fs.GetStageCreateInfo();
13102
13103 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13104 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13105
13106 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13107 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13108 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13109
13110 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13111 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013112 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013113
13114 VkPipelineColorBlendAttachmentState att = {};
13115 att.blendEnable = VK_FALSE;
13116 att.colorWriteMask = 0xf;
13117
13118 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13119 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13120 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13121 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013122 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013123 cb_ci.attachmentCount = 1;
13124 cb_ci.pAttachments = &att;
13125
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013126 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13127 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13128 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13129
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013130 VkGraphicsPipelineCreateInfo gp_ci = {};
13131 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13132 gp_ci.stageCount = 2;
13133 gp_ci.pStages = shaderStages;
13134 gp_ci.pVertexInputState = &vi_ci;
13135 gp_ci.pInputAssemblyState = &ia_ci;
13136 gp_ci.pViewportState = &vp_state_ci;
13137 gp_ci.pRasterizationState = &rs_ci;
13138 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013139 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013140 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13141 gp_ci.layout = pipeline_layout;
13142 gp_ci.renderPass = renderPass();
13143
13144 VkPipelineCacheCreateInfo pc_ci = {};
13145 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13146
13147 VkPipeline pipeline;
13148 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013149 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013150 ASSERT_VK_SUCCESS(err);
13151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013152 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013153 m_errorMonitor->VerifyFound();
13154 if (VK_SUCCESS == err) {
13155 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13156 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013157 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13159}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013160
Mike Stroyanaccf7692015-05-12 16:00:45 -060013161#if GTEST_IS_THREADSAFE
13162struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013163 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013164 VkEvent event;
13165 bool bailout;
13166};
13167
Karl Schultz6addd812016-02-02 17:17:23 -070013168extern "C" void *AddToCommandBuffer(void *arg) {
13169 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013170
Mike Stroyana6d14942016-07-13 15:10:05 -060013171 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013172 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013173 if (data->bailout) {
13174 break;
13175 }
13176 }
13177 return NULL;
13178}
13179
Karl Schultz6addd812016-02-02 17:17:23 -070013180TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013181 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013184
Mike Stroyanaccf7692015-05-12 16:00:45 -060013185 ASSERT_NO_FATAL_FAILURE(InitState());
13186 ASSERT_NO_FATAL_FAILURE(InitViewport());
13187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13188
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013189 // Calls AllocateCommandBuffers
13190 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013191
13192 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013193 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194
13195 VkEventCreateInfo event_info;
13196 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013197 VkResult err;
13198
13199 memset(&event_info, 0, sizeof(event_info));
13200 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13201
Chia-I Wuf7458c52015-10-26 21:10:41 +080013202 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013203 ASSERT_VK_SUCCESS(err);
13204
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205 err = vkResetEvent(device(), event);
13206 ASSERT_VK_SUCCESS(err);
13207
13208 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013209 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210 data.event = event;
13211 data.bailout = false;
13212 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013213
13214 // First do some correct operations using multiple threads.
13215 // Add many entries to command buffer from another thread.
13216 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13217 // Make non-conflicting calls from this thread at the same time.
13218 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013219 uint32_t count;
13220 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013221 }
13222 test_platform_thread_join(thread, NULL);
13223
13224 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013225 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013226 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013227 // Add many entries to command buffer from this thread at the same time.
13228 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013229
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013230 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013231 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013232
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013233 m_errorMonitor->SetBailout(NULL);
13234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013235 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013236
Chia-I Wuf7458c52015-10-26 21:10:41 +080013237 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013238}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013239#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013240
Karl Schultz6addd812016-02-02 17:17:23 -070013241TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013242 TEST_DESCRIPTION(
13243 "Test that an error is produced for a spirv module "
13244 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013247
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013248 ASSERT_NO_FATAL_FAILURE(InitState());
13249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13250
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013251 VkShaderModule module;
13252 VkShaderModuleCreateInfo moduleCreateInfo;
13253 struct icd_spv_header spv;
13254
13255 spv.magic = ICD_SPV_MAGIC;
13256 spv.version = ICD_SPV_VERSION;
13257 spv.gen_magic = 0;
13258
13259 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13260 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013261 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262 moduleCreateInfo.codeSize = 4;
13263 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013264 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013265
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013266 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013267}
13268
Karl Schultz6addd812016-02-02 17:17:23 -070013269TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013270 TEST_DESCRIPTION(
13271 "Test that an error is produced for a spirv module "
13272 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013275
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013276 ASSERT_NO_FATAL_FAILURE(InitState());
13277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13278
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013279 VkShaderModule module;
13280 VkShaderModuleCreateInfo moduleCreateInfo;
13281 struct icd_spv_header spv;
13282
13283 spv.magic = ~ICD_SPV_MAGIC;
13284 spv.version = ICD_SPV_VERSION;
13285 spv.gen_magic = 0;
13286
13287 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13288 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013289 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13291 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013292 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013293
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013294 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013295}
13296
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013297#if 0
13298// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013299TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013301 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013302
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013303 ASSERT_NO_FATAL_FAILURE(InitState());
13304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13305
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013306 VkShaderModule module;
13307 VkShaderModuleCreateInfo moduleCreateInfo;
13308 struct icd_spv_header spv;
13309
13310 spv.magic = ICD_SPV_MAGIC;
13311 spv.version = ~ICD_SPV_VERSION;
13312 spv.gen_magic = 0;
13313
13314 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13315 moduleCreateInfo.pNext = NULL;
13316
Karl Schultz6addd812016-02-02 17:17:23 -070013317 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013318 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13319 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013320 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013322 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013323}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013324#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013325
Karl Schultz6addd812016-02-02 17:17:23 -070013326TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013327 TEST_DESCRIPTION(
13328 "Test that a warning is produced for a vertex output that "
13329 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013331
Chris Forbes9f7ff632015-05-25 11:13:08 +120013332 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013335 char const *vsSource =
13336 "#version 450\n"
13337 "\n"
13338 "layout(location=0) out float x;\n"
13339 "out gl_PerVertex {\n"
13340 " vec4 gl_Position;\n"
13341 "};\n"
13342 "void main(){\n"
13343 " gl_Position = vec4(1);\n"
13344 " x = 0;\n"
13345 "}\n";
13346 char const *fsSource =
13347 "#version 450\n"
13348 "\n"
13349 "layout(location=0) out vec4 color;\n"
13350 "void main(){\n"
13351 " color = vec4(1);\n"
13352 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013353
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013356
13357 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013358 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013359 pipe.AddShader(&vs);
13360 pipe.AddShader(&fs);
13361
Chris Forbes9f7ff632015-05-25 11:13:08 +120013362 VkDescriptorSetObj descriptorSet(m_device);
13363 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013365
Tony Barbour5781e8f2015-08-04 16:23:11 -060013366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013368 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013369}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013370
Mark Mueller098c9cb2016-09-08 09:01:57 -060013371TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13372 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13373
13374 ASSERT_NO_FATAL_FAILURE(InitState());
13375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13376
13377 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013378 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013379
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013380 char const *vsSource =
13381 "#version 450\n"
13382 "\n"
13383 "out gl_PerVertex {\n"
13384 " vec4 gl_Position;\n"
13385 "};\n"
13386 "void main(){\n"
13387 " gl_Position = vec4(1);\n"
13388 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013389
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013390 char const *fsSource =
13391 "#version 450\n"
13392 "\n"
13393 "layout (constant_id = 0) const float r = 0.0f;\n"
13394 "layout(location = 0) out vec4 uFragColor;\n"
13395 "void main(){\n"
13396 " uFragColor = vec4(r,1,0,1);\n"
13397 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013398
13399 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13400 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13401
13402 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13403 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13404
13405 VkPipelineLayout pipeline_layout;
13406 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13407
13408 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13409 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13410 vp_state_create_info.viewportCount = 1;
13411 VkViewport viewport = {};
13412 vp_state_create_info.pViewports = &viewport;
13413 vp_state_create_info.scissorCount = 1;
13414 VkRect2D scissors = {};
13415 vp_state_create_info.pScissors = &scissors;
13416
13417 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13418
13419 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13420 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13421 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13422 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13423
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013424 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013425
13426 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13427 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13428
13429 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13430 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13431 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13432
13433 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13434 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13435 rasterization_state_create_info.pNext = nullptr;
13436 rasterization_state_create_info.lineWidth = 1.0f;
13437 rasterization_state_create_info.rasterizerDiscardEnable = true;
13438
13439 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13440 color_blend_attachment_state.blendEnable = VK_FALSE;
13441 color_blend_attachment_state.colorWriteMask = 0xf;
13442
13443 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13444 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13445 color_blend_state_create_info.attachmentCount = 1;
13446 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13447
13448 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13449 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13450 graphicspipe_create_info.stageCount = 2;
13451 graphicspipe_create_info.pStages = shader_stage_create_info;
13452 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13453 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13454 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13455 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13456 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13457 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13458 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13459 graphicspipe_create_info.layout = pipeline_layout;
13460 graphicspipe_create_info.renderPass = renderPass();
13461
13462 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13463 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13464
13465 VkPipelineCache pipelineCache;
13466 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13467
13468 // This structure maps constant ids to data locations.
13469 const VkSpecializationMapEntry entry =
13470 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013471 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013472
13473 uint32_t data = 1;
13474
13475 // Set up the info describing spec map and data
13476 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013477 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013478 };
13479 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13480
13481 VkPipeline pipeline;
13482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13483 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13484 m_errorMonitor->VerifyFound();
13485
13486 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13487 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13488}
13489
13490TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13491 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13492
13493 ASSERT_NO_FATAL_FAILURE(InitState());
13494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13495
13496 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13497
13498 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13499 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13500 descriptor_pool_type_count[0].descriptorCount = 1;
13501 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13502 descriptor_pool_type_count[1].descriptorCount = 1;
13503
13504 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13505 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13506 descriptor_pool_create_info.maxSets = 1;
13507 descriptor_pool_create_info.poolSizeCount = 2;
13508 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13509 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13510
13511 VkDescriptorPool descriptorset_pool;
13512 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13513
13514 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13515 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13516 descriptorset_layout_binding.descriptorCount = 1;
13517 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13518
13519 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13520 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13521 descriptorset_layout_create_info.bindingCount = 1;
13522 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13523
13524 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013525 ASSERT_VK_SUCCESS(
13526 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013527
13528 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13529 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13530 descriptorset_allocate_info.descriptorSetCount = 1;
13531 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13532 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13533 VkDescriptorSet descriptorset;
13534 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13535
13536 // Challenge core_validation with a non uniform buffer type.
13537 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13538
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013539 char const *vsSource =
13540 "#version 450\n"
13541 "\n"
13542 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13543 " mat4 mvp;\n"
13544 "} ubuf;\n"
13545 "out gl_PerVertex {\n"
13546 " vec4 gl_Position;\n"
13547 "};\n"
13548 "void main(){\n"
13549 " gl_Position = ubuf.mvp * vec4(1);\n"
13550 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013551
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013552 char const *fsSource =
13553 "#version 450\n"
13554 "\n"
13555 "layout(location = 0) out vec4 uFragColor;\n"
13556 "void main(){\n"
13557 " uFragColor = vec4(0,1,0,1);\n"
13558 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013559
13560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13562
13563 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13564 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13565 pipeline_layout_create_info.setLayoutCount = 1;
13566 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13567
13568 VkPipelineLayout pipeline_layout;
13569 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13570
13571 VkPipelineObj pipe(m_device);
13572 pipe.AddColorAttachment();
13573 pipe.AddShader(&vs);
13574 pipe.AddShader(&fs);
13575
13576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13577 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13578 m_errorMonitor->VerifyFound();
13579
13580 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13581 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13582 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13583}
13584
13585TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13586 TEST_DESCRIPTION(
13587 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13588
13589 ASSERT_NO_FATAL_FAILURE(InitState());
13590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13591
13592 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13593
13594 VkDescriptorPoolSize descriptor_pool_type_count = {};
13595 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13596 descriptor_pool_type_count.descriptorCount = 1;
13597
13598 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13599 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13600 descriptor_pool_create_info.maxSets = 1;
13601 descriptor_pool_create_info.poolSizeCount = 1;
13602 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13603 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13604
13605 VkDescriptorPool descriptorset_pool;
13606 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13607
13608 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13609 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13610 descriptorset_layout_binding.descriptorCount = 1;
13611 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13612 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13613
13614 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13615 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13616 descriptorset_layout_create_info.bindingCount = 1;
13617 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13618
13619 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013620 ASSERT_VK_SUCCESS(
13621 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013622
13623 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13624 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13625 descriptorset_allocate_info.descriptorSetCount = 1;
13626 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13627 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13628 VkDescriptorSet descriptorset;
13629 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13630
13631 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13632
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013633 char const *vsSource =
13634 "#version 450\n"
13635 "\n"
13636 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13637 " mat4 mvp;\n"
13638 "} ubuf;\n"
13639 "out gl_PerVertex {\n"
13640 " vec4 gl_Position;\n"
13641 "};\n"
13642 "void main(){\n"
13643 " gl_Position = ubuf.mvp * vec4(1);\n"
13644 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013645
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013646 char const *fsSource =
13647 "#version 450\n"
13648 "\n"
13649 "layout(location = 0) out vec4 uFragColor;\n"
13650 "void main(){\n"
13651 " uFragColor = vec4(0,1,0,1);\n"
13652 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013653
13654 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13655 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13656
13657 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13658 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13659 pipeline_layout_create_info.setLayoutCount = 1;
13660 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13661
13662 VkPipelineLayout pipeline_layout;
13663 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13664
13665 VkPipelineObj pipe(m_device);
13666 pipe.AddColorAttachment();
13667 pipe.AddShader(&vs);
13668 pipe.AddShader(&fs);
13669
13670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13671 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13672 m_errorMonitor->VerifyFound();
13673
13674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13675 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13676 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13677}
13678
13679TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013680 TEST_DESCRIPTION(
13681 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13682 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013683
13684 ASSERT_NO_FATAL_FAILURE(InitState());
13685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13686
13687 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013688 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013689
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013690 char const *vsSource =
13691 "#version 450\n"
13692 "\n"
13693 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13694 "out gl_PerVertex {\n"
13695 " vec4 gl_Position;\n"
13696 "};\n"
13697 "void main(){\n"
13698 " gl_Position = vec4(consts.x);\n"
13699 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013700
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013701 char const *fsSource =
13702 "#version 450\n"
13703 "\n"
13704 "layout(location = 0) out vec4 uFragColor;\n"
13705 "void main(){\n"
13706 " uFragColor = vec4(0,1,0,1);\n"
13707 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013708
13709 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13711
13712 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13713 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13714
13715 // Set up a push constant range
13716 VkPushConstantRange push_constant_ranges = {};
13717 // Set to the wrong stage to challenge core_validation
13718 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13719 push_constant_ranges.size = 4;
13720
13721 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13722 pipeline_layout_create_info.pushConstantRangeCount = 1;
13723
13724 VkPipelineLayout pipeline_layout;
13725 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13726
13727 VkPipelineObj pipe(m_device);
13728 pipe.AddColorAttachment();
13729 pipe.AddShader(&vs);
13730 pipe.AddShader(&fs);
13731
13732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13733 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13734 m_errorMonitor->VerifyFound();
13735
13736 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13737}
13738
13739TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13740 TEST_DESCRIPTION(
13741 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13742
13743 ASSERT_NO_FATAL_FAILURE(InitState());
13744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13745
13746 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013747 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013748
13749 // Some awkward steps are required to test with custom device features.
13750 std::vector<const char *> device_extension_names;
13751 auto features = m_device->phy().features();
13752 // Disable support for 64 bit floats
13753 features.shaderFloat64 = false;
13754 // The sacrificial device object
13755 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13756
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013757 char const *vsSource =
13758 "#version 450\n"
13759 "\n"
13760 "out gl_PerVertex {\n"
13761 " vec4 gl_Position;\n"
13762 "};\n"
13763 "void main(){\n"
13764 " gl_Position = vec4(1);\n"
13765 "}\n";
13766 char const *fsSource =
13767 "#version 450\n"
13768 "\n"
13769 "layout(location=0) out vec4 color;\n"
13770 "void main(){\n"
13771 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13772 " color = vec4(green);\n"
13773 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013774
13775 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13776 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13777
13778 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013779
13780 VkPipelineObj pipe(&test_device);
13781 pipe.AddColorAttachment();
13782 pipe.AddShader(&vs);
13783 pipe.AddShader(&fs);
13784
13785 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13786 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13787 VkPipelineLayout pipeline_layout;
13788 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13789
13790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13791 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13792 m_errorMonitor->VerifyFound();
13793
13794 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13795}
13796
13797TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13798 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13799
13800 ASSERT_NO_FATAL_FAILURE(InitState());
13801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13802
13803 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13804
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013805 char const *vsSource =
13806 "#version 450\n"
13807 "\n"
13808 "out gl_PerVertex {\n"
13809 " vec4 gl_Position;\n"
13810 "};\n"
13811 "layout(xfb_buffer = 1) out;"
13812 "void main(){\n"
13813 " gl_Position = vec4(1);\n"
13814 "}\n";
13815 char const *fsSource =
13816 "#version 450\n"
13817 "\n"
13818 "layout(location=0) out vec4 color;\n"
13819 "void main(){\n"
13820 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13821 " color = vec4(green);\n"
13822 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013823
13824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13826
13827 VkPipelineObj pipe(m_device);
13828 pipe.AddColorAttachment();
13829 pipe.AddShader(&vs);
13830 pipe.AddShader(&fs);
13831
13832 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13833 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13834 VkPipelineLayout pipeline_layout;
13835 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13836
13837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13838 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13839 m_errorMonitor->VerifyFound();
13840
13841 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13842}
13843
Karl Schultz6addd812016-02-02 17:17:23 -070013844TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013845 TEST_DESCRIPTION(
13846 "Test that an error is produced for a fragment shader input "
13847 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013850
Chris Forbes59cb88d2015-05-25 11:13:13 +120013851 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013853
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013854 char const *vsSource =
13855 "#version 450\n"
13856 "\n"
13857 "out gl_PerVertex {\n"
13858 " vec4 gl_Position;\n"
13859 "};\n"
13860 "void main(){\n"
13861 " gl_Position = vec4(1);\n"
13862 "}\n";
13863 char const *fsSource =
13864 "#version 450\n"
13865 "\n"
13866 "layout(location=0) in float x;\n"
13867 "layout(location=0) out vec4 color;\n"
13868 "void main(){\n"
13869 " color = vec4(x);\n"
13870 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013871
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013874
13875 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013876 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013877 pipe.AddShader(&vs);
13878 pipe.AddShader(&fs);
13879
Chris Forbes59cb88d2015-05-25 11:13:13 +120013880 VkDescriptorSetObj descriptorSet(m_device);
13881 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013883
Tony Barbour5781e8f2015-08-04 16:23:11 -060013884 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013885
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013886 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013887}
13888
Karl Schultz6addd812016-02-02 17:17:23 -070013889TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013890 TEST_DESCRIPTION(
13891 "Test that an error is produced for a fragment shader input "
13892 "within an interace block, which is not present in the outputs "
13893 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013895
13896 ASSERT_NO_FATAL_FAILURE(InitState());
13897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13898
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013899 char const *vsSource =
13900 "#version 450\n"
13901 "\n"
13902 "out gl_PerVertex {\n"
13903 " vec4 gl_Position;\n"
13904 "};\n"
13905 "void main(){\n"
13906 " gl_Position = vec4(1);\n"
13907 "}\n";
13908 char const *fsSource =
13909 "#version 450\n"
13910 "\n"
13911 "in block { layout(location=0) float x; } ins;\n"
13912 "layout(location=0) out vec4 color;\n"
13913 "void main(){\n"
13914 " color = vec4(ins.x);\n"
13915 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013916
13917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13919
13920 VkPipelineObj pipe(m_device);
13921 pipe.AddColorAttachment();
13922 pipe.AddShader(&vs);
13923 pipe.AddShader(&fs);
13924
13925 VkDescriptorSetObj descriptorSet(m_device);
13926 descriptorSet.AppendDummy();
13927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13928
13929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13930
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013931 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013932}
13933
Karl Schultz6addd812016-02-02 17:17:23 -070013934TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013935 TEST_DESCRIPTION(
13936 "Test that an error is produced for mismatched array sizes "
13937 "across the vertex->fragment shader interface");
13938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13939 "Type mismatch on location 0.0: 'ptr to "
13940 "output arr[2] of float32' vs 'ptr to "
13941 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013942
13943 ASSERT_NO_FATAL_FAILURE(InitState());
13944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13945
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013946 char const *vsSource =
13947 "#version 450\n"
13948 "\n"
13949 "layout(location=0) out float x[2];\n"
13950 "out gl_PerVertex {\n"
13951 " vec4 gl_Position;\n"
13952 "};\n"
13953 "void main(){\n"
13954 " x[0] = 0; x[1] = 0;\n"
13955 " gl_Position = vec4(1);\n"
13956 "}\n";
13957 char const *fsSource =
13958 "#version 450\n"
13959 "\n"
13960 "layout(location=0) in float x[1];\n"
13961 "layout(location=0) out vec4 color;\n"
13962 "void main(){\n"
13963 " color = vec4(x[0]);\n"
13964 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013965
13966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13968
13969 VkPipelineObj pipe(m_device);
13970 pipe.AddColorAttachment();
13971 pipe.AddShader(&vs);
13972 pipe.AddShader(&fs);
13973
13974 VkDescriptorSetObj descriptorSet(m_device);
13975 descriptorSet.AppendDummy();
13976 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13977
13978 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13979
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013980 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013981}
13982
Karl Schultz6addd812016-02-02 17:17:23 -070013983TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013984 TEST_DESCRIPTION(
13985 "Test that an error is produced for mismatched types across "
13986 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013988
Chris Forbesb56af562015-05-25 11:13:17 +120013989 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013991
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013992 char const *vsSource =
13993 "#version 450\n"
13994 "\n"
13995 "layout(location=0) out int x;\n"
13996 "out gl_PerVertex {\n"
13997 " vec4 gl_Position;\n"
13998 "};\n"
13999 "void main(){\n"
14000 " x = 0;\n"
14001 " gl_Position = vec4(1);\n"
14002 "}\n";
14003 char const *fsSource =
14004 "#version 450\n"
14005 "\n"
14006 "layout(location=0) in float x;\n" /* VS writes int */
14007 "layout(location=0) out vec4 color;\n"
14008 "void main(){\n"
14009 " color = vec4(x);\n"
14010 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014011
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014014
14015 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014016 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014017 pipe.AddShader(&vs);
14018 pipe.AddShader(&fs);
14019
Chris Forbesb56af562015-05-25 11:13:17 +120014020 VkDescriptorSetObj descriptorSet(m_device);
14021 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014022 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014023
Tony Barbour5781e8f2015-08-04 16:23:11 -060014024 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014025
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014026 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014027}
14028
Karl Schultz6addd812016-02-02 17:17:23 -070014029TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014030 TEST_DESCRIPTION(
14031 "Test that an error is produced for mismatched types across "
14032 "the vertex->fragment shader interface, when the variable is contained within "
14033 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014035
14036 ASSERT_NO_FATAL_FAILURE(InitState());
14037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014039 char const *vsSource =
14040 "#version 450\n"
14041 "\n"
14042 "out block { layout(location=0) int x; } outs;\n"
14043 "out gl_PerVertex {\n"
14044 " vec4 gl_Position;\n"
14045 "};\n"
14046 "void main(){\n"
14047 " outs.x = 0;\n"
14048 " gl_Position = vec4(1);\n"
14049 "}\n";
14050 char const *fsSource =
14051 "#version 450\n"
14052 "\n"
14053 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14054 "layout(location=0) out vec4 color;\n"
14055 "void main(){\n"
14056 " color = vec4(ins.x);\n"
14057 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014058
14059 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14060 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14061
14062 VkPipelineObj pipe(m_device);
14063 pipe.AddColorAttachment();
14064 pipe.AddShader(&vs);
14065 pipe.AddShader(&fs);
14066
14067 VkDescriptorSetObj descriptorSet(m_device);
14068 descriptorSet.AppendDummy();
14069 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14070
14071 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14072
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014073 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014074}
14075
14076TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014077 TEST_DESCRIPTION(
14078 "Test that an error is produced for location mismatches across "
14079 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14080 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.0 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130014082
14083 ASSERT_NO_FATAL_FAILURE(InitState());
14084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14085
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014086 char const *vsSource =
14087 "#version 450\n"
14088 "\n"
14089 "out block { layout(location=1) float x; } outs;\n"
14090 "out gl_PerVertex {\n"
14091 " vec4 gl_Position;\n"
14092 "};\n"
14093 "void main(){\n"
14094 " outs.x = 0;\n"
14095 " gl_Position = vec4(1);\n"
14096 "}\n";
14097 char const *fsSource =
14098 "#version 450\n"
14099 "\n"
14100 "in block { layout(location=0) float x; } ins;\n"
14101 "layout(location=0) out vec4 color;\n"
14102 "void main(){\n"
14103 " color = vec4(ins.x);\n"
14104 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014105
14106 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14108
14109 VkPipelineObj pipe(m_device);
14110 pipe.AddColorAttachment();
14111 pipe.AddShader(&vs);
14112 pipe.AddShader(&fs);
14113
14114 VkDescriptorSetObj descriptorSet(m_device);
14115 descriptorSet.AppendDummy();
14116 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14117
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014118 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014119 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014121 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014122}
14123
14124TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014125 TEST_DESCRIPTION(
14126 "Test that an error is produced for component mismatches across the "
14127 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14128 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.1 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130014130
14131 ASSERT_NO_FATAL_FAILURE(InitState());
14132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014134 char const *vsSource =
14135 "#version 450\n"
14136 "\n"
14137 "out block { layout(location=0, component=0) float x; } outs;\n"
14138 "out gl_PerVertex {\n"
14139 " vec4 gl_Position;\n"
14140 "};\n"
14141 "void main(){\n"
14142 " outs.x = 0;\n"
14143 " gl_Position = vec4(1);\n"
14144 "}\n";
14145 char const *fsSource =
14146 "#version 450\n"
14147 "\n"
14148 "in block { layout(location=0, component=1) float x; } ins;\n"
14149 "layout(location=0) out vec4 color;\n"
14150 "void main(){\n"
14151 " color = vec4(ins.x);\n"
14152 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014153
14154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14156
14157 VkPipelineObj pipe(m_device);
14158 pipe.AddColorAttachment();
14159 pipe.AddShader(&vs);
14160 pipe.AddShader(&fs);
14161
14162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
14164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14165
14166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014168 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014169}
14170
Chris Forbes1f3b0152016-11-30 12:48:40 +130014171TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14172 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14173
14174 ASSERT_NO_FATAL_FAILURE(InitState());
14175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14176
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014177 char const *vsSource =
14178 "#version 450\n"
14179 "layout(location=0) out mediump float x;\n"
14180 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14181 char const *fsSource =
14182 "#version 450\n"
14183 "layout(location=0) in highp float x;\n"
14184 "layout(location=0) out vec4 color;\n"
14185 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014186
14187 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14188 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14189
14190 VkPipelineObj pipe(m_device);
14191 pipe.AddColorAttachment();
14192 pipe.AddShader(&vs);
14193 pipe.AddShader(&fs);
14194
14195 VkDescriptorSetObj descriptorSet(m_device);
14196 descriptorSet.AppendDummy();
14197 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14198
14199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14200
14201 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14202
14203 m_errorMonitor->VerifyFound();
14204}
14205
Chris Forbes870a39e2016-11-30 12:55:56 +130014206TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14207 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14208
14209 ASSERT_NO_FATAL_FAILURE(InitState());
14210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14211
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014212 char const *vsSource =
14213 "#version 450\n"
14214 "out block { layout(location=0) mediump float x; };\n"
14215 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14216 char const *fsSource =
14217 "#version 450\n"
14218 "in block { layout(location=0) highp float x; };\n"
14219 "layout(location=0) out vec4 color;\n"
14220 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014221
14222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14223 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14224
14225 VkPipelineObj pipe(m_device);
14226 pipe.AddColorAttachment();
14227 pipe.AddShader(&vs);
14228 pipe.AddShader(&fs);
14229
14230 VkDescriptorSetObj descriptorSet(m_device);
14231 descriptorSet.AppendDummy();
14232 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14233
14234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14235
14236 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14237
14238 m_errorMonitor->VerifyFound();
14239}
14240
Karl Schultz6addd812016-02-02 17:17:23 -070014241TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014242 TEST_DESCRIPTION(
14243 "Test that a warning is produced for a vertex attribute which is "
14244 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014246
Chris Forbesde136e02015-05-25 11:13:28 +120014247 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014249
14250 VkVertexInputBindingDescription input_binding;
14251 memset(&input_binding, 0, sizeof(input_binding));
14252
14253 VkVertexInputAttributeDescription input_attrib;
14254 memset(&input_attrib, 0, sizeof(input_attrib));
14255 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14256
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014257 char const *vsSource =
14258 "#version 450\n"
14259 "\n"
14260 "out gl_PerVertex {\n"
14261 " vec4 gl_Position;\n"
14262 "};\n"
14263 "void main(){\n"
14264 " gl_Position = vec4(1);\n"
14265 "}\n";
14266 char const *fsSource =
14267 "#version 450\n"
14268 "\n"
14269 "layout(location=0) out vec4 color;\n"
14270 "void main(){\n"
14271 " color = vec4(1);\n"
14272 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014273
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014276
14277 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014278 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014279 pipe.AddShader(&vs);
14280 pipe.AddShader(&fs);
14281
14282 pipe.AddVertexInputBindings(&input_binding, 1);
14283 pipe.AddVertexInputAttribs(&input_attrib, 1);
14284
Chris Forbesde136e02015-05-25 11:13:28 +120014285 VkDescriptorSetObj descriptorSet(m_device);
14286 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014287 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014288
Tony Barbour5781e8f2015-08-04 16:23:11 -060014289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014290
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014291 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014292}
14293
Karl Schultz6addd812016-02-02 17:17:23 -070014294TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014295 TEST_DESCRIPTION(
14296 "Test that a warning is produced for a location mismatch on "
14297 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014299
14300 ASSERT_NO_FATAL_FAILURE(InitState());
14301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14302
14303 VkVertexInputBindingDescription input_binding;
14304 memset(&input_binding, 0, sizeof(input_binding));
14305
14306 VkVertexInputAttributeDescription input_attrib;
14307 memset(&input_attrib, 0, sizeof(input_attrib));
14308 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014310 char const *vsSource =
14311 "#version 450\n"
14312 "\n"
14313 "layout(location=1) in float x;\n"
14314 "out gl_PerVertex {\n"
14315 " vec4 gl_Position;\n"
14316 "};\n"
14317 "void main(){\n"
14318 " gl_Position = vec4(x);\n"
14319 "}\n";
14320 char const *fsSource =
14321 "#version 450\n"
14322 "\n"
14323 "layout(location=0) out vec4 color;\n"
14324 "void main(){\n"
14325 " color = vec4(1);\n"
14326 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014327
14328 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14329 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14330
14331 VkPipelineObj pipe(m_device);
14332 pipe.AddColorAttachment();
14333 pipe.AddShader(&vs);
14334 pipe.AddShader(&fs);
14335
14336 pipe.AddVertexInputBindings(&input_binding, 1);
14337 pipe.AddVertexInputAttribs(&input_attrib, 1);
14338
14339 VkDescriptorSetObj descriptorSet(m_device);
14340 descriptorSet.AppendDummy();
14341 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14342
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014343 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14345
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014346 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014347}
14348
Karl Schultz6addd812016-02-02 17:17:23 -070014349TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014350 TEST_DESCRIPTION(
14351 "Test that an error is produced for a vertex shader input which is not "
14352 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14354 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014355
Chris Forbes62e8e502015-05-25 11:13:29 +120014356 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014359 char const *vsSource =
14360 "#version 450\n"
14361 "\n"
14362 "layout(location=0) in vec4 x;\n" /* not provided */
14363 "out gl_PerVertex {\n"
14364 " vec4 gl_Position;\n"
14365 "};\n"
14366 "void main(){\n"
14367 " gl_Position = x;\n"
14368 "}\n";
14369 char const *fsSource =
14370 "#version 450\n"
14371 "\n"
14372 "layout(location=0) out vec4 color;\n"
14373 "void main(){\n"
14374 " color = vec4(1);\n"
14375 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014376
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014377 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14378 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014379
14380 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014381 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014382 pipe.AddShader(&vs);
14383 pipe.AddShader(&fs);
14384
Chris Forbes62e8e502015-05-25 11:13:29 +120014385 VkDescriptorSetObj descriptorSet(m_device);
14386 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014388
Tony Barbour5781e8f2015-08-04 16:23:11 -060014389 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014391 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014392}
14393
Karl Schultz6addd812016-02-02 17:17:23 -070014394TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014395 TEST_DESCRIPTION(
14396 "Test that an error is produced for a mismatch between the "
14397 "fundamental type (float/int/uint) of an attribute and the "
14398 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match vertex shader input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014400
Chris Forbesc97d98e2015-05-25 11:13:31 +120014401 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014403
14404 VkVertexInputBindingDescription input_binding;
14405 memset(&input_binding, 0, sizeof(input_binding));
14406
14407 VkVertexInputAttributeDescription input_attrib;
14408 memset(&input_attrib, 0, sizeof(input_attrib));
14409 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14410
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014411 char const *vsSource =
14412 "#version 450\n"
14413 "\n"
14414 "layout(location=0) in int x;\n" /* attrib provided float */
14415 "out gl_PerVertex {\n"
14416 " vec4 gl_Position;\n"
14417 "};\n"
14418 "void main(){\n"
14419 " gl_Position = vec4(x);\n"
14420 "}\n";
14421 char const *fsSource =
14422 "#version 450\n"
14423 "\n"
14424 "layout(location=0) out vec4 color;\n"
14425 "void main(){\n"
14426 " color = vec4(1);\n"
14427 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014428
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014429 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14430 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014431
14432 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014433 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014434 pipe.AddShader(&vs);
14435 pipe.AddShader(&fs);
14436
14437 pipe.AddVertexInputBindings(&input_binding, 1);
14438 pipe.AddVertexInputAttribs(&input_attrib, 1);
14439
Chris Forbesc97d98e2015-05-25 11:13:31 +120014440 VkDescriptorSetObj descriptorSet(m_device);
14441 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014442 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014443
Tony Barbour5781e8f2015-08-04 16:23:11 -060014444 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014446 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014447}
14448
Chris Forbesc68b43c2016-04-06 11:18:47 +120014449TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014450 TEST_DESCRIPTION(
14451 "Test that an error is produced for a pipeline containing multiple "
14452 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14454 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014455
14456 ASSERT_NO_FATAL_FAILURE(InitState());
14457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14458
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014459 char const *vsSource =
14460 "#version 450\n"
14461 "\n"
14462 "out gl_PerVertex {\n"
14463 " vec4 gl_Position;\n"
14464 "};\n"
14465 "void main(){\n"
14466 " gl_Position = vec4(1);\n"
14467 "}\n";
14468 char const *fsSource =
14469 "#version 450\n"
14470 "\n"
14471 "layout(location=0) out vec4 color;\n"
14472 "void main(){\n"
14473 " color = vec4(1);\n"
14474 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014475
14476 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14477 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14478
14479 VkPipelineObj pipe(m_device);
14480 pipe.AddColorAttachment();
14481 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014482 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014483 pipe.AddShader(&fs);
14484
14485 VkDescriptorSetObj descriptorSet(m_device);
14486 descriptorSet.AppendDummy();
14487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14488
14489 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14490
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014491 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014492}
14493
Chris Forbes82ff92a2016-09-09 10:50:24 +120014494TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014496
14497 ASSERT_NO_FATAL_FAILURE(InitState());
14498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014500 char const *vsSource =
14501 "#version 450\n"
14502 "out gl_PerVertex {\n"
14503 " vec4 gl_Position;\n"
14504 "};\n"
14505 "void main(){\n"
14506 " gl_Position = vec4(0);\n"
14507 "}\n";
14508 char const *fsSource =
14509 "#version 450\n"
14510 "\n"
14511 "layout(location=0) out vec4 color;\n"
14512 "void main(){\n"
14513 " color = vec4(1);\n"
14514 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014515
14516 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14517 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14518
14519 VkPipelineObj pipe(m_device);
14520 pipe.AddColorAttachment();
14521 pipe.AddShader(&vs);
14522 pipe.AddShader(&fs);
14523
14524 VkDescriptorSetObj descriptorSet(m_device);
14525 descriptorSet.AppendDummy();
14526 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14527
14528 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14529
14530 m_errorMonitor->VerifyFound();
14531}
14532
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014533TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14535 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14536 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014537
14538 ASSERT_NO_FATAL_FAILURE(InitState());
14539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14540
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014541 char const *vsSource =
14542 "#version 450\n"
14543 "void main(){ gl_Position = vec4(0); }\n";
14544 char const *fsSource =
14545 "#version 450\n"
14546 "\n"
14547 "layout(location=0) out vec4 color;\n"
14548 "void main(){\n"
14549 " color = vec4(1);\n"
14550 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014551
14552 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14553 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14554
14555 VkPipelineObj pipe(m_device);
14556 pipe.AddColorAttachment();
14557 pipe.AddShader(&vs);
14558 pipe.AddShader(&fs);
14559
14560 VkDescriptorSetObj descriptorSet(m_device);
14561 descriptorSet.AppendDummy();
14562 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14563
14564 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014565 {
14566 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14567 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14568 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014569 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014570 {
14571 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14572 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14573 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014574 },
14575 };
14576 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014577 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014578 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014579 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14580 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014581 VkRenderPass rp;
14582 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14583 ASSERT_VK_SUCCESS(err);
14584
14585 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14586
14587 m_errorMonitor->VerifyFound();
14588
14589 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14590}
14591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014592TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014593 TEST_DESCRIPTION(
14594 "Test that an error is produced for a variable output from "
14595 "the TCS without the patch decoration, but consumed in the TES "
14596 "with the decoration.");
14597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14598 "is per-vertex in tessellation control shader stage "
14599 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014600
14601 ASSERT_NO_FATAL_FAILURE(InitState());
14602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14603
Chris Forbesc1e852d2016-04-04 19:26:42 +120014604 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014605 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014606 return;
14607 }
14608
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014609 char const *vsSource =
14610 "#version 450\n"
14611 "void main(){}\n";
14612 char const *tcsSource =
14613 "#version 450\n"
14614 "layout(location=0) out int x[];\n"
14615 "layout(vertices=3) out;\n"
14616 "void main(){\n"
14617 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14618 " gl_TessLevelInner[0] = 1;\n"
14619 " x[gl_InvocationID] = gl_InvocationID;\n"
14620 "}\n";
14621 char const *tesSource =
14622 "#version 450\n"
14623 "layout(triangles, equal_spacing, cw) in;\n"
14624 "layout(location=0) patch in int x;\n"
14625 "out gl_PerVertex { vec4 gl_Position; };\n"
14626 "void main(){\n"
14627 " gl_Position.xyz = gl_TessCoord;\n"
14628 " gl_Position.w = x;\n"
14629 "}\n";
14630 char const *fsSource =
14631 "#version 450\n"
14632 "layout(location=0) out vec4 color;\n"
14633 "void main(){\n"
14634 " color = vec4(1);\n"
14635 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014636
14637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14638 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14639 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14640 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14643 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014645 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014646
14647 VkPipelineObj pipe(m_device);
14648 pipe.SetInputAssembly(&iasci);
14649 pipe.SetTessellation(&tsci);
14650 pipe.AddColorAttachment();
14651 pipe.AddShader(&vs);
14652 pipe.AddShader(&tcs);
14653 pipe.AddShader(&tes);
14654 pipe.AddShader(&fs);
14655
14656 VkDescriptorSetObj descriptorSet(m_device);
14657 descriptorSet.AppendDummy();
14658 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14659
14660 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14661
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014662 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014663}
14664
Karl Schultz6addd812016-02-02 17:17:23 -070014665TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014666 TEST_DESCRIPTION(
14667 "Test that an error is produced for a vertex attribute setup where multiple "
14668 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14670 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014671
Chris Forbes280ba2c2015-06-12 11:16:41 +120014672 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014674
14675 /* Two binding descriptions for binding 0 */
14676 VkVertexInputBindingDescription input_bindings[2];
14677 memset(input_bindings, 0, sizeof(input_bindings));
14678
14679 VkVertexInputAttributeDescription input_attrib;
14680 memset(&input_attrib, 0, sizeof(input_attrib));
14681 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14682
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014683 char const *vsSource =
14684 "#version 450\n"
14685 "\n"
14686 "layout(location=0) in float x;\n" /* attrib provided float */
14687 "out gl_PerVertex {\n"
14688 " vec4 gl_Position;\n"
14689 "};\n"
14690 "void main(){\n"
14691 " gl_Position = vec4(x);\n"
14692 "}\n";
14693 char const *fsSource =
14694 "#version 450\n"
14695 "\n"
14696 "layout(location=0) out vec4 color;\n"
14697 "void main(){\n"
14698 " color = vec4(1);\n"
14699 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014700
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014703
14704 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014705 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014706 pipe.AddShader(&vs);
14707 pipe.AddShader(&fs);
14708
14709 pipe.AddVertexInputBindings(input_bindings, 2);
14710 pipe.AddVertexInputAttribs(&input_attrib, 1);
14711
Chris Forbes280ba2c2015-06-12 11:16:41 +120014712 VkDescriptorSetObj descriptorSet(m_device);
14713 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014714 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014715
Tony Barbour5781e8f2015-08-04 16:23:11 -060014716 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014718 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014719}
Chris Forbes8f68b562015-05-25 11:13:32 +120014720
Karl Schultz6addd812016-02-02 17:17:23 -070014721TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014722 TEST_DESCRIPTION(
14723 "Test that an error is produced for a fragment shader which does not "
14724 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014726
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014727 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014728
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014729 char const *vsSource =
14730 "#version 450\n"
14731 "\n"
14732 "out gl_PerVertex {\n"
14733 " vec4 gl_Position;\n"
14734 "};\n"
14735 "void main(){\n"
14736 " gl_Position = vec4(1);\n"
14737 "}\n";
14738 char const *fsSource =
14739 "#version 450\n"
14740 "\n"
14741 "void main(){\n"
14742 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014743
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014744 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14745 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014746
14747 VkPipelineObj pipe(m_device);
14748 pipe.AddShader(&vs);
14749 pipe.AddShader(&fs);
14750
Chia-I Wu08accc62015-07-07 11:50:03 +080014751 /* set up CB 0, not written */
14752 pipe.AddColorAttachment();
14753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014754
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014755 VkDescriptorSetObj descriptorSet(m_device);
14756 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014758
Tony Barbour5781e8f2015-08-04 16:23:11 -060014759 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014761 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014762}
14763
Karl Schultz6addd812016-02-02 17:17:23 -070014764TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014765 TEST_DESCRIPTION(
14766 "Test that a warning is produced for a fragment shader which provides a spurious "
14767 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014769 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014770
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014771 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014773 char const *vsSource =
14774 "#version 450\n"
14775 "\n"
14776 "out gl_PerVertex {\n"
14777 " vec4 gl_Position;\n"
14778 "};\n"
14779 "void main(){\n"
14780 " gl_Position = vec4(1);\n"
14781 "}\n";
14782 char const *fsSource =
14783 "#version 450\n"
14784 "\n"
14785 "layout(location=0) out vec4 x;\n"
14786 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14787 "void main(){\n"
14788 " x = vec4(1);\n"
14789 " y = vec4(1);\n"
14790 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014791
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014792 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014794
14795 VkPipelineObj pipe(m_device);
14796 pipe.AddShader(&vs);
14797 pipe.AddShader(&fs);
14798
Chia-I Wu08accc62015-07-07 11:50:03 +080014799 /* set up CB 0, not written */
14800 pipe.AddColorAttachment();
14801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014802 /* FS writes CB 1, but we don't configure it */
14803
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014804 VkDescriptorSetObj descriptorSet(m_device);
14805 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014806 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014807
Tony Barbour5781e8f2015-08-04 16:23:11 -060014808 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014809
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014810 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014811}
14812
Karl Schultz6addd812016-02-02 17:17:23 -070014813TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014814 TEST_DESCRIPTION(
14815 "Test that an error is produced for a mismatch between the fundamental "
14816 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014818
Chris Forbesa36d69e2015-05-25 11:13:44 +120014819 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014820
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014821 char const *vsSource =
14822 "#version 450\n"
14823 "\n"
14824 "out gl_PerVertex {\n"
14825 " vec4 gl_Position;\n"
14826 "};\n"
14827 "void main(){\n"
14828 " gl_Position = vec4(1);\n"
14829 "}\n";
14830 char const *fsSource =
14831 "#version 450\n"
14832 "\n"
14833 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14834 "void main(){\n"
14835 " x = ivec4(1);\n"
14836 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014837
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014840
14841 VkPipelineObj pipe(m_device);
14842 pipe.AddShader(&vs);
14843 pipe.AddShader(&fs);
14844
Chia-I Wu08accc62015-07-07 11:50:03 +080014845 /* set up CB 0; type is UNORM by default */
14846 pipe.AddColorAttachment();
14847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014848
Chris Forbesa36d69e2015-05-25 11:13:44 +120014849 VkDescriptorSetObj descriptorSet(m_device);
14850 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014852
Tony Barbour5781e8f2015-08-04 16:23:11 -060014853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014855 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014856}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014857
Karl Schultz6addd812016-02-02 17:17:23 -070014858TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014859 TEST_DESCRIPTION(
14860 "Test that an error is produced for a shader consuming a uniform "
14861 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014863
Chris Forbes556c76c2015-08-14 12:04:59 +120014864 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014865
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014866 char const *vsSource =
14867 "#version 450\n"
14868 "\n"
14869 "out gl_PerVertex {\n"
14870 " vec4 gl_Position;\n"
14871 "};\n"
14872 "void main(){\n"
14873 " gl_Position = vec4(1);\n"
14874 "}\n";
14875 char const *fsSource =
14876 "#version 450\n"
14877 "\n"
14878 "layout(location=0) out vec4 x;\n"
14879 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14880 "void main(){\n"
14881 " x = vec4(bar.y);\n"
14882 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014883
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014886
Chris Forbes556c76c2015-08-14 12:04:59 +120014887 VkPipelineObj pipe(m_device);
14888 pipe.AddShader(&vs);
14889 pipe.AddShader(&fs);
14890
14891 /* set up CB 0; type is UNORM by default */
14892 pipe.AddColorAttachment();
14893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14894
14895 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014897
14898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014900 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014901}
14902
Chris Forbes5c59e902016-02-26 16:56:09 +130014903TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014904 TEST_DESCRIPTION(
14905 "Test that an error is produced for a shader consuming push constants "
14906 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014908
14909 ASSERT_NO_FATAL_FAILURE(InitState());
14910
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014911 char const *vsSource =
14912 "#version 450\n"
14913 "\n"
14914 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14915 "out gl_PerVertex {\n"
14916 " vec4 gl_Position;\n"
14917 "};\n"
14918 "void main(){\n"
14919 " gl_Position = vec4(consts.x);\n"
14920 "}\n";
14921 char const *fsSource =
14922 "#version 450\n"
14923 "\n"
14924 "layout(location=0) out vec4 x;\n"
14925 "void main(){\n"
14926 " x = vec4(1);\n"
14927 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014928
14929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14931
14932 VkPipelineObj pipe(m_device);
14933 pipe.AddShader(&vs);
14934 pipe.AddShader(&fs);
14935
14936 /* set up CB 0; type is UNORM by default */
14937 pipe.AddColorAttachment();
14938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14939
14940 VkDescriptorSetObj descriptorSet(m_device);
14941 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14942
14943 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14944
14945 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014946 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014947}
14948
Chris Forbes3fb17902016-08-22 14:57:55 +120014949TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014950 TEST_DESCRIPTION(
14951 "Test that an error is produced for a shader consuming an input attachment "
14952 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14954 "consumes input attachment index 0 but not provided in subpass");
14955
14956 ASSERT_NO_FATAL_FAILURE(InitState());
14957
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014958 char const *vsSource =
14959 "#version 450\n"
14960 "\n"
14961 "out gl_PerVertex {\n"
14962 " vec4 gl_Position;\n"
14963 "};\n"
14964 "void main(){\n"
14965 " gl_Position = vec4(1);\n"
14966 "}\n";
14967 char const *fsSource =
14968 "#version 450\n"
14969 "\n"
14970 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14971 "layout(location=0) out vec4 color;\n"
14972 "void main() {\n"
14973 " color = subpassLoad(x);\n"
14974 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014975
14976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14978
14979 VkPipelineObj pipe(m_device);
14980 pipe.AddShader(&vs);
14981 pipe.AddShader(&fs);
14982 pipe.AddColorAttachment();
14983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014985 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14986 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014987 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014988 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014989 ASSERT_VK_SUCCESS(err);
14990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014992 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014993 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014994 ASSERT_VK_SUCCESS(err);
14995
14996 // error here.
14997 pipe.CreateVKPipeline(pl, renderPass());
14998
14999 m_errorMonitor->VerifyFound();
15000
15001 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15002 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15003}
15004
Chris Forbes5a9a0472016-08-22 16:02:09 +120015005TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015006 TEST_DESCRIPTION(
15007 "Test that an error is produced for a shader consuming an input attachment "
15008 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15010 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15011
15012 ASSERT_NO_FATAL_FAILURE(InitState());
15013
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015014 char const *vsSource =
15015 "#version 450\n"
15016 "\n"
15017 "out gl_PerVertex {\n"
15018 " vec4 gl_Position;\n"
15019 "};\n"
15020 "void main(){\n"
15021 " gl_Position = vec4(1);\n"
15022 "}\n";
15023 char const *fsSource =
15024 "#version 450\n"
15025 "\n"
15026 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15027 "layout(location=0) out vec4 color;\n"
15028 "void main() {\n"
15029 " color = subpassLoad(x);\n"
15030 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015031
15032 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15033 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15034
15035 VkPipelineObj pipe(m_device);
15036 pipe.AddShader(&vs);
15037 pipe.AddShader(&fs);
15038 pipe.AddColorAttachment();
15039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15042 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015043 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015045 ASSERT_VK_SUCCESS(err);
15046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015048 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015050 ASSERT_VK_SUCCESS(err);
15051
15052 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15054 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15055 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15056 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15057 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes5a9a0472016-08-22 16:02:09 +120015058 };
15059 VkAttachmentReference color = {
15060 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15061 };
15062 VkAttachmentReference input = {
15063 1, VK_IMAGE_LAYOUT_GENERAL,
15064 };
15065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015068 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015069 VkRenderPass rp;
15070 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15071 ASSERT_VK_SUCCESS(err);
15072
15073 // error here.
15074 pipe.CreateVKPipeline(pl, rp);
15075
15076 m_errorMonitor->VerifyFound();
15077
15078 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15079 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15080 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15081}
15082
Chris Forbes541f7b02016-08-22 15:30:27 +120015083TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015084 TEST_DESCRIPTION(
15085 "Test that an error is produced for a shader consuming an input attachment "
15086 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015088 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015089
15090 ASSERT_NO_FATAL_FAILURE(InitState());
15091
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015092 char const *vsSource =
15093 "#version 450\n"
15094 "\n"
15095 "out gl_PerVertex {\n"
15096 " vec4 gl_Position;\n"
15097 "};\n"
15098 "void main(){\n"
15099 " gl_Position = vec4(1);\n"
15100 "}\n";
15101 char const *fsSource =
15102 "#version 450\n"
15103 "\n"
15104 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15105 "layout(location=0) out vec4 color;\n"
15106 "void main() {\n"
15107 " color = subpassLoad(xs[0]);\n"
15108 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015109
15110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15112
15113 VkPipelineObj pipe(m_device);
15114 pipe.AddShader(&vs);
15115 pipe.AddShader(&fs);
15116 pipe.AddColorAttachment();
15117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15120 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015121 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015123 ASSERT_VK_SUCCESS(err);
15124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015125 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015126 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015127 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015128 ASSERT_VK_SUCCESS(err);
15129
15130 // error here.
15131 pipe.CreateVKPipeline(pl, renderPass());
15132
15133 m_errorMonitor->VerifyFound();
15134
15135 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15136 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15137}
15138
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015139TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015140 TEST_DESCRIPTION(
15141 "Test that an error is produced for a compute pipeline consuming a "
15142 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015144
15145 ASSERT_NO_FATAL_FAILURE(InitState());
15146
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015147 char const *csSource =
15148 "#version 450\n"
15149 "\n"
15150 "layout(local_size_x=1) in;\n"
15151 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15152 "void main(){\n"
15153 " x = vec4(1);\n"
15154 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015155
15156 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15157
15158 VkDescriptorSetObj descriptorSet(m_device);
15159 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15162 nullptr,
15163 0,
15164 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15165 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15166 descriptorSet.GetPipelineLayout(),
15167 VK_NULL_HANDLE,
15168 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015169
15170 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015171 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015172
15173 m_errorMonitor->VerifyFound();
15174
15175 if (err == VK_SUCCESS) {
15176 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15177 }
15178}
15179
Chris Forbes22a9b092016-07-19 14:34:05 +120015180TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015181 TEST_DESCRIPTION(
15182 "Test that an error is produced for a pipeline consuming a "
15183 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15185 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015186
15187 ASSERT_NO_FATAL_FAILURE(InitState());
15188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15190 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015191 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015192 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015193 ASSERT_VK_SUCCESS(err);
15194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015196 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015197 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015198 ASSERT_VK_SUCCESS(err);
15199
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015200 char const *csSource =
15201 "#version 450\n"
15202 "\n"
15203 "layout(local_size_x=1) in;\n"
15204 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15205 "void main() {\n"
15206 " x.x = 1.0f;\n"
15207 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015208 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015210 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15211 nullptr,
15212 0,
15213 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15214 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15215 pl,
15216 VK_NULL_HANDLE,
15217 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015218
15219 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015220 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015221
15222 m_errorMonitor->VerifyFound();
15223
15224 if (err == VK_SUCCESS) {
15225 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15226 }
15227
15228 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15229 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15230}
15231
Chris Forbes50020592016-07-27 13:52:41 +120015232TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015233 TEST_DESCRIPTION(
15234 "Test that an error is produced when an image view type "
15235 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires an image view of type VK_IMAGE_VIEW_TYPE_3D");
Chris Forbes50020592016-07-27 13:52:41 +120015238
15239 ASSERT_NO_FATAL_FAILURE(InitState());
15240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015242 char const *vsSource =
15243 "#version 450\n"
15244 "\n"
15245 "out gl_PerVertex { vec4 gl_Position; };\n"
15246 "void main() { gl_Position = vec4(0); }\n";
15247 char const *fsSource =
15248 "#version 450\n"
15249 "\n"
15250 "layout(set=0, binding=0) uniform sampler3D s;\n"
15251 "layout(location=0) out vec4 color;\n"
15252 "void main() {\n"
15253 " color = texture(s, vec3(0));\n"
15254 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015255 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15256 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15257
15258 VkPipelineObj pipe(m_device);
15259 pipe.AddShader(&vs);
15260 pipe.AddShader(&fs);
15261 pipe.AddColorAttachment();
15262
15263 VkTextureObj texture(m_device, nullptr);
15264 VkSamplerObj sampler(m_device);
15265
15266 VkDescriptorSetObj descriptorSet(m_device);
15267 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15268 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15269
15270 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15271 ASSERT_VK_SUCCESS(err);
15272
Tony Barbour552f6c02016-12-21 14:34:07 -070015273 m_commandBuffer->BeginCommandBuffer();
15274 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015275
15276 m_commandBuffer->BindPipeline(pipe);
15277 m_commandBuffer->BindDescriptorSet(descriptorSet);
15278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015279 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015280 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015282 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15283
15284 // error produced here.
15285 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15286
15287 m_errorMonitor->VerifyFound();
15288
Tony Barbour552f6c02016-12-21 14:34:07 -070015289 m_commandBuffer->EndRenderPass();
15290 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015291}
15292
Chris Forbes5533bfc2016-07-27 14:12:34 +120015293TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015294 TEST_DESCRIPTION(
15295 "Test that an error is produced when a multisampled images "
15296 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015299
15300 ASSERT_NO_FATAL_FAILURE(InitState());
15301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15302
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015303 char const *vsSource =
15304 "#version 450\n"
15305 "\n"
15306 "out gl_PerVertex { vec4 gl_Position; };\n"
15307 "void main() { gl_Position = vec4(0); }\n";
15308 char const *fsSource =
15309 "#version 450\n"
15310 "\n"
15311 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15312 "layout(location=0) out vec4 color;\n"
15313 "void main() {\n"
15314 " color = texelFetch(s, ivec2(0), 0);\n"
15315 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15318
15319 VkPipelineObj pipe(m_device);
15320 pipe.AddShader(&vs);
15321 pipe.AddShader(&fs);
15322 pipe.AddColorAttachment();
15323
15324 VkTextureObj texture(m_device, nullptr);
15325 VkSamplerObj sampler(m_device);
15326
15327 VkDescriptorSetObj descriptorSet(m_device);
15328 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15329 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15330
15331 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15332 ASSERT_VK_SUCCESS(err);
15333
Tony Barbour552f6c02016-12-21 14:34:07 -070015334 m_commandBuffer->BeginCommandBuffer();
15335 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015336
15337 m_commandBuffer->BindPipeline(pipe);
15338 m_commandBuffer->BindDescriptorSet(descriptorSet);
15339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015340 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015341 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015342 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015343 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15344
15345 // error produced here.
15346 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15347
15348 m_errorMonitor->VerifyFound();
15349
Tony Barbour552f6c02016-12-21 14:34:07 -070015350 m_commandBuffer->EndRenderPass();
15351 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015352}
15353
Mark Youngc48c4c12016-04-11 14:26:49 -060015354TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015356
15357 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015358
15359 // Create an image
15360 VkImage image;
15361
Karl Schultz6addd812016-02-02 17:17:23 -070015362 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15363 const int32_t tex_width = 32;
15364 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015365
15366 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015367 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15368 image_create_info.pNext = NULL;
15369 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15370 image_create_info.format = tex_format;
15371 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015372 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015373 image_create_info.extent.depth = 1;
15374 image_create_info.mipLevels = 1;
15375 image_create_info.arrayLayers = 1;
15376 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15377 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15378 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15379 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015380
15381 // Introduce error by sending down a bogus width extent
15382 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015383 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015384
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015385 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015386}
15387
Mark Youngc48c4c12016-04-11 14:26:49 -060015388TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015390
15391 ASSERT_NO_FATAL_FAILURE(InitState());
15392
15393 // Create an image
15394 VkImage image;
15395
15396 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15397 const int32_t tex_width = 32;
15398 const int32_t tex_height = 32;
15399
15400 VkImageCreateInfo image_create_info = {};
15401 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15402 image_create_info.pNext = NULL;
15403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15404 image_create_info.format = tex_format;
15405 image_create_info.extent.width = tex_width;
15406 image_create_info.extent.height = tex_height;
15407 image_create_info.extent.depth = 1;
15408 image_create_info.mipLevels = 1;
15409 image_create_info.arrayLayers = 1;
15410 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15411 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15412 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15413 image_create_info.flags = 0;
15414
15415 // Introduce error by sending down a bogus width extent
15416 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015417 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015418 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15419
15420 m_errorMonitor->VerifyFound();
15421}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015422
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015423TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015424 TEST_DESCRIPTION(
15425 "Create a render pass with an attachment description "
15426 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015427
15428 ASSERT_NO_FATAL_FAILURE(InitState());
15429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15430
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015432
15433 VkAttachmentReference color_attach = {};
15434 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15435 color_attach.attachment = 0;
15436 VkSubpassDescription subpass = {};
15437 subpass.colorAttachmentCount = 1;
15438 subpass.pColorAttachments = &color_attach;
15439
15440 VkRenderPassCreateInfo rpci = {};
15441 rpci.subpassCount = 1;
15442 rpci.pSubpasses = &subpass;
15443 rpci.attachmentCount = 1;
15444 VkAttachmentDescription attach_desc = {};
15445 attach_desc.format = VK_FORMAT_UNDEFINED;
15446 rpci.pAttachments = &attach_desc;
15447 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15448 VkRenderPass rp;
15449 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15450
15451 m_errorMonitor->VerifyFound();
15452
15453 if (result == VK_SUCCESS) {
15454 vkDestroyRenderPass(m_device->device(), rp, NULL);
15455 }
15456}
15457
Karl Schultz6addd812016-02-02 17:17:23 -070015458TEST_F(VkLayerTest, InvalidImageView) {
15459 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015460
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015462
Tobin Ehliscde08892015-09-22 10:11:37 -060015463 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015464
Mike Stroyana3082432015-09-25 13:39:21 -060015465 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015466 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015467
Karl Schultz6addd812016-02-02 17:17:23 -070015468 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15469 const int32_t tex_width = 32;
15470 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015471
15472 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015473 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15474 image_create_info.pNext = NULL;
15475 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15476 image_create_info.format = tex_format;
15477 image_create_info.extent.width = tex_width;
15478 image_create_info.extent.height = tex_height;
15479 image_create_info.extent.depth = 1;
15480 image_create_info.mipLevels = 1;
15481 image_create_info.arrayLayers = 1;
15482 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15483 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15484 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15485 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015486
Chia-I Wuf7458c52015-10-26 21:10:41 +080015487 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015488 ASSERT_VK_SUCCESS(err);
15489
15490 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015491 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015492 image_view_create_info.image = image;
15493 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15494 image_view_create_info.format = tex_format;
15495 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015496 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015497 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015498 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015499
15500 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015501 m_errorMonitor->SetUnexpectedError(
15502 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015503 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015504
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015505 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015506 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015507}
Mike Stroyana3082432015-09-25 13:39:21 -060015508
Mark Youngd339ba32016-05-30 13:28:35 -060015509TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15510 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015512 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015513
15514 ASSERT_NO_FATAL_FAILURE(InitState());
15515
15516 // Create an image and try to create a view with no memory backing the image
15517 VkImage image;
15518
15519 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15520 const int32_t tex_width = 32;
15521 const int32_t tex_height = 32;
15522
15523 VkImageCreateInfo image_create_info = {};
15524 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15525 image_create_info.pNext = NULL;
15526 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15527 image_create_info.format = tex_format;
15528 image_create_info.extent.width = tex_width;
15529 image_create_info.extent.height = tex_height;
15530 image_create_info.extent.depth = 1;
15531 image_create_info.mipLevels = 1;
15532 image_create_info.arrayLayers = 1;
15533 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15534 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15536 image_create_info.flags = 0;
15537
15538 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15539 ASSERT_VK_SUCCESS(err);
15540
15541 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015542 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015543 image_view_create_info.image = image;
15544 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15545 image_view_create_info.format = tex_format;
15546 image_view_create_info.subresourceRange.layerCount = 1;
15547 image_view_create_info.subresourceRange.baseMipLevel = 0;
15548 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015549 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015550
15551 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015552 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015553
15554 m_errorMonitor->VerifyFound();
15555 vkDestroyImage(m_device->device(), image, NULL);
15556 // If last error is success, it still created the view, so delete it.
15557 if (err == VK_SUCCESS) {
15558 vkDestroyImageView(m_device->device(), view, NULL);
15559 }
Mark Youngd339ba32016-05-30 13:28:35 -060015560}
15561
Karl Schultz6addd812016-02-02 17:17:23 -070015562TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015563 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015565
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015566 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015567
Karl Schultz6addd812016-02-02 17:17:23 -070015568 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015569 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015570 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015571 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015572
15573 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015574 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015575 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015576 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15577 image_view_create_info.format = tex_format;
15578 image_view_create_info.subresourceRange.baseMipLevel = 0;
15579 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015580 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015581 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015583
15584 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015585 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015586
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015587 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015588}
15589
Mike Weiblena1e13f42017-02-09 21:25:59 -070015590TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15591 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15592
15593 ASSERT_NO_FATAL_FAILURE(InitState());
15594 VkSubresourceLayout subres_layout = {};
15595
15596 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15597 {
15598 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15599 VkImageObj img(m_device);
15600 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15601 ASSERT_TRUE(img.initialized());
15602
15603 VkImageSubresource subres = {};
15604 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15605 subres.mipLevel = 0;
15606 subres.arrayLayer = 0;
15607
15608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15609 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15610 m_errorMonitor->VerifyFound();
15611 }
15612
15613 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15614 {
15615 VkImageObj img(m_device);
15616 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15617 ASSERT_TRUE(img.initialized());
15618
15619 VkImageSubresource subres = {};
15620 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15621 subres.mipLevel = 0;
15622 subres.arrayLayer = 0;
15623
15624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15626 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15627 m_errorMonitor->VerifyFound();
15628 }
15629
15630 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15631 {
15632 VkImageObj img(m_device);
15633 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15634 ASSERT_TRUE(img.initialized());
15635
15636 VkImageSubresource subres = {};
15637 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15638 subres.mipLevel = 1; // ERROR: triggers VU 00739
15639 subres.arrayLayer = 0;
15640
15641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15642 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15643 m_errorMonitor->VerifyFound();
15644 }
15645
15646 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15647 {
15648 VkImageObj img(m_device);
15649 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15650 ASSERT_TRUE(img.initialized());
15651
15652 VkImageSubresource subres = {};
15653 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15654 subres.mipLevel = 0;
15655 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15656
15657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15658 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15659 m_errorMonitor->VerifyFound();
15660 }
15661}
15662
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015663TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015664 VkResult err;
15665 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015666
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015668
Mike Stroyana3082432015-09-25 13:39:21 -060015669 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015670
15671 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015672 VkImage srcImage;
15673 VkImage dstImage;
15674 VkDeviceMemory srcMem;
15675 VkDeviceMemory destMem;
15676 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015677
15678 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015679 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15680 image_create_info.pNext = NULL;
15681 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15682 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15683 image_create_info.extent.width = 32;
15684 image_create_info.extent.height = 32;
15685 image_create_info.extent.depth = 1;
15686 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015687 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015688 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15689 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15691 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015694 ASSERT_VK_SUCCESS(err);
15695
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015697 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015698 ASSERT_VK_SUCCESS(err);
15699
15700 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015701 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015702 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15703 memAlloc.pNext = NULL;
15704 memAlloc.allocationSize = 0;
15705 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015706
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015707 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015708 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015709 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015710 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015711 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015712 ASSERT_VK_SUCCESS(err);
15713
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015714 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015715 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015717 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015718 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015719 ASSERT_VK_SUCCESS(err);
15720
15721 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15722 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015723 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015724 ASSERT_VK_SUCCESS(err);
15725
Tony Barbour552f6c02016-12-21 14:34:07 -070015726 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015727 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015728 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015729 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015730 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015731 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015732 copyRegion.srcOffset.x = 0;
15733 copyRegion.srcOffset.y = 0;
15734 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015735 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015736 copyRegion.dstSubresource.mipLevel = 0;
15737 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015738 // Introduce failure by forcing the dst layerCount to differ from src
15739 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015740 copyRegion.dstOffset.x = 0;
15741 copyRegion.dstOffset.y = 0;
15742 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015743 copyRegion.extent.width = 1;
15744 copyRegion.extent.height = 1;
15745 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015746 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015747 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015748
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015749 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015750
Chia-I Wuf7458c52015-10-26 21:10:41 +080015751 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015752 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015753 vkFreeMemory(m_device->device(), srcMem, NULL);
15754 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015755}
15756
Tony Barbourd6673642016-05-05 14:46:39 -060015757TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015758 TEST_DESCRIPTION("Creating images with unsuported formats ");
15759
15760 ASSERT_NO_FATAL_FAILURE(InitState());
15761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15762 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015763 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060015764 VK_IMAGE_TILING_OPTIMAL, 0);
15765 ASSERT_TRUE(image.initialized());
15766
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015767 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015768 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015769 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015770 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15771 image_create_info.format = VK_FORMAT_UNDEFINED;
15772 image_create_info.extent.width = 32;
15773 image_create_info.extent.height = 32;
15774 image_create_info.extent.depth = 1;
15775 image_create_info.mipLevels = 1;
15776 image_create_info.arrayLayers = 1;
15777 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15778 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15779 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15782 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015783
15784 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015785 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15786 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15787 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15788 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015789 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15790 m_errorMonitor->VerifyFound();
15791
Tony Barbourd6673642016-05-05 14:46:39 -060015792 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015793 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015794 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15795 VkFormat format = static_cast<VkFormat>(f);
15796 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015797 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015798 unsupported = format;
15799 break;
15800 }
15801 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015802
Tony Barbourd6673642016-05-05 14:46:39 -060015803 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015804 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015806
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015807 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15808 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15809 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15810 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15811 m_errorMonitor->SetUnexpectedError(
15812 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15813 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15814 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015815 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015816 m_errorMonitor->VerifyFound();
15817 }
15818}
15819
15820TEST_F(VkLayerTest, ImageLayerViewTests) {
15821 VkResult ret;
15822 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15823
15824 ASSERT_NO_FATAL_FAILURE(InitState());
15825
15826 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015827 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060015828 VK_IMAGE_TILING_OPTIMAL, 0);
15829 ASSERT_TRUE(image.initialized());
15830
15831 VkImageView imgView;
15832 VkImageViewCreateInfo imgViewInfo = {};
15833 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15834 imgViewInfo.image = image.handle();
15835 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15836 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15837 imgViewInfo.subresourceRange.layerCount = 1;
15838 imgViewInfo.subresourceRange.baseMipLevel = 0;
15839 imgViewInfo.subresourceRange.levelCount = 1;
15840 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15841
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015843 // View can't have baseMipLevel >= image's mipLevels - Expect
15844 // VIEW_CREATE_ERROR
15845 imgViewInfo.subresourceRange.baseMipLevel = 1;
15846 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15847 m_errorMonitor->VerifyFound();
15848 imgViewInfo.subresourceRange.baseMipLevel = 0;
15849
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015851 // View can't have baseArrayLayer >= image's arraySize - Expect
15852 // VIEW_CREATE_ERROR
15853 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15854 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15855 m_errorMonitor->VerifyFound();
15856 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15857
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015859 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15860 imgViewInfo.subresourceRange.levelCount = 0;
15861 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15862 m_errorMonitor->VerifyFound();
15863 imgViewInfo.subresourceRange.levelCount = 1;
15864
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015865 m_errorMonitor->SetDesiredFailureMsg(
15866 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15867 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015868 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15869 imgViewInfo.subresourceRange.layerCount = 0;
15870 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15871 m_errorMonitor->VerifyFound();
15872 imgViewInfo.subresourceRange.layerCount = 1;
15873
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15875 "Formats MUST be IDENTICAL unless "
15876 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15877 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015878 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15879 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15880 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15881 m_errorMonitor->VerifyFound();
15882 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15883
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015885 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15886 // VIEW_CREATE_ERROR
15887 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15888 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15889 m_errorMonitor->VerifyFound();
15890 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15891
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015893 // TODO: Update framework to easily passing mutable flag into ImageObj init
15894 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015895 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15896 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15897 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015898 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15899 // VIEW_CREATE_ERROR
15900 VkImageCreateInfo mutImgInfo = image.create_info();
15901 VkImage mutImage;
15902 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015903 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015904 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15905 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15906 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15907 ASSERT_VK_SUCCESS(ret);
15908 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015909 m_errorMonitor->SetUnexpectedError(
15910 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Tony Barbourd6673642016-05-05 14:46:39 -060015911 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15912 m_errorMonitor->VerifyFound();
15913 imgViewInfo.image = image.handle();
15914 vkDestroyImage(m_device->handle(), mutImage, NULL);
15915}
15916
Dave Houlton75967fc2017-03-06 17:21:16 -070015917TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
15918 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
15919
15920 ASSERT_NO_FATAL_FAILURE(InitState());
15921
15922 VkPhysicalDeviceFeatures device_features;
15923 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
15924 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
15925 if (device_features.textureCompressionBC) {
15926 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
15927 } else if (device_features.textureCompressionETC2) {
15928 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
15929 } else if (device_features.textureCompressionASTC_LDR) {
15930 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
15931 } else {
15932 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
15933 return;
15934 }
15935
15936 VkImageCreateInfo ci;
15937 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15938 ci.pNext = NULL;
15939 ci.flags = 0;
15940 ci.imageType = VK_IMAGE_TYPE_2D;
15941 ci.format = compressed_format;
15942 ci.extent = {32, 32, 1};
15943 ci.mipLevels = 6;
15944 ci.arrayLayers = 1;
15945 ci.samples = VK_SAMPLE_COUNT_1_BIT;
15946 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
15947 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15948 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15949 ci.queueFamilyIndexCount = 0;
15950 ci.pQueueFamilyIndices = NULL;
15951 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15952
15953 VkImageObj image(m_device);
15954 image.init(&ci);
15955 ASSERT_TRUE(image.initialized());
15956
15957 VkImageObj odd_image(m_device);
15958 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
15959 odd_image.init(&ci);
15960 ASSERT_TRUE(odd_image.initialized());
15961
15962 // Allocate buffers
15963 VkMemoryPropertyFlags reqs = 0;
15964 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
15965 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
15966 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
15967 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
15968 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
15969
15970 VkBufferImageCopy region = {};
15971 region.bufferRowLength = 0;
15972 region.bufferImageHeight = 0;
15973 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15974 region.imageSubresource.layerCount = 1;
15975 region.imageOffset = {0, 0, 0};
15976 region.bufferOffset = 0;
15977
15978 // start recording
15979 m_commandBuffer->BeginCommandBuffer();
15980
15981 // Mip level copies that work - 5 levels
15982 m_errorMonitor->ExpectSuccess();
15983
15984 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
15985 region.imageExtent = {32, 32, 1};
15986 region.imageSubresource.mipLevel = 0;
15987 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
15988 &region);
15989 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15990 &region);
15991
15992 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
15993 region.imageExtent = {8, 8, 1};
15994 region.imageSubresource.mipLevel = 2;
15995 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
15996 &region);
15997 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
15998 &region);
15999
16000 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16001 region.imageExtent = {4, 4, 1};
16002 region.imageSubresource.mipLevel = 3;
16003 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16004 &region);
16005 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16006 &region);
16007
16008 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16009 region.imageExtent = {2, 2, 1};
16010 region.imageSubresource.mipLevel = 4;
16011 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16012 &region);
16013 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16014 &region);
16015
16016 region.imageExtent = {1, 1, 1};
16017 region.imageSubresource.mipLevel = 5;
16018 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16019 &region);
16020 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16021 &region);
16022 m_errorMonitor->VerifyNotFound();
16023
16024 // Buffer must accomodate a full compressed block, regardless of texel count
16025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16026 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16027 &region);
16028 m_errorMonitor->VerifyFound();
16029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16030 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16031 &region);
16032 m_errorMonitor->VerifyFound();
16033
16034 // Copy width < compressed block size, but not the full mip width
16035 region.imageExtent = {1, 2, 1};
16036 region.imageSubresource.mipLevel = 4;
16037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16038 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16039 &region);
16040 m_errorMonitor->VerifyFound();
16041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16042 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16043 &region);
16044 m_errorMonitor->VerifyFound();
16045
16046 // Copy height < compressed block size but not the full mip height
16047 region.imageExtent = {2, 1, 1};
16048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16049 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16050 &region);
16051 m_errorMonitor->VerifyFound();
16052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16053 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16054 &region);
16055 m_errorMonitor->VerifyFound();
16056
16057 // Offsets must be multiple of compressed block size
16058 region.imageOffset = {1, 1, 0};
16059 region.imageExtent = {1, 1, 1};
16060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16061 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16062 &region);
16063 m_errorMonitor->VerifyFound();
16064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16065 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16066 &region);
16067 m_errorMonitor->VerifyFound();
16068
16069 // Offset + extent width = mip width - should succeed
16070 region.imageOffset = {4, 4, 0};
16071 region.imageExtent = {3, 4, 1};
16072 region.imageSubresource.mipLevel = 2;
16073 m_errorMonitor->ExpectSuccess();
16074 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16075 &region);
16076 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16077 &region);
16078 m_errorMonitor->VerifyNotFound();
16079
16080 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16081 region.imageExtent = {4, 4, 1};
16082 m_errorMonitor->ExpectSuccess();
16083 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16084 &region);
16085 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16086 &region);
16087 m_errorMonitor->VerifyNotFound();
16088
16089 // Offset + extent width < mip width and not a multiple of block width - should fail
16090 region.imageExtent = {3, 3, 1};
16091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16092 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16093 &region);
16094 m_errorMonitor->VerifyFound();
16095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16096 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16097 &region);
16098 m_errorMonitor->VerifyFound();
16099}
16100
Dave Houlton59a20702017-02-02 17:26:23 -070016101TEST_F(VkLayerTest, ImageBufferCopyTests) {
16102 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16103
16104 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070016105
16106 // Bail if any dimension of transfer granularity is 0.
16107 auto index = m_device->graphics_queue_node_index_;
16108 auto queue_family_properties = m_device->phy().queue_properties();
16109 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16110 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16111 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16112 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16113 return;
16114 }
16115
Dave Houlton59a20702017-02-02 17:26:23 -070016116 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16117 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16118 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016119 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16120 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16121 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16122 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16123
Dave Houlton59a20702017-02-02 17:26:23 -070016124 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16125 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16126 VK_IMAGE_TILING_OPTIMAL, 0);
16127 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16128 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16129 VK_IMAGE_TILING_OPTIMAL, 0);
16130 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16131 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016132 ASSERT_TRUE(image_64k.initialized());
16133 ASSERT_TRUE(image_16k.initialized());
16134 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016135
Dave Houltonf3229d52017-02-21 15:59:08 -070016136 // Verify all needed Depth/Stencil formats are supported
16137 bool missing_ds_support = false;
16138 VkFormatProperties props = {0, 0, 0};
16139 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16140 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16141 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16142 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16143 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16144 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16145 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16146 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16147
16148 if (!missing_ds_support) {
16149 ds_image_4D_1S.init(
16150 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16151 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16152 VK_IMAGE_TILING_OPTIMAL, 0);
16153 ASSERT_TRUE(ds_image_4D_1S.initialized());
16154
16155 ds_image_3D_1S.init(
16156 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16157 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16158 VK_IMAGE_TILING_OPTIMAL, 0);
16159 ASSERT_TRUE(ds_image_3D_1S.initialized());
16160
16161 ds_image_2D.init(
16162 256, 256, VK_FORMAT_D16_UNORM,
16163 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16164 VK_IMAGE_TILING_OPTIMAL, 0);
16165 ASSERT_TRUE(ds_image_2D.initialized());
16166
16167 ds_image_1S.init(
16168 256, 256, VK_FORMAT_S8_UINT,
16169 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16170 VK_IMAGE_TILING_OPTIMAL, 0);
16171 ASSERT_TRUE(ds_image_1S.initialized());
16172 }
16173
16174 // Allocate buffers
16175 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016176 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016177 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16178 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16179 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16180 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016181
16182 VkBufferImageCopy region = {};
16183 region.bufferRowLength = 0;
16184 region.bufferImageHeight = 0;
16185 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16186 region.imageSubresource.layerCount = 1;
16187 region.imageOffset = {0, 0, 0};
16188 region.imageExtent = {64, 64, 1};
16189 region.bufferOffset = 0;
16190
16191 // attempt copies before putting command buffer in recording state
16192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16193 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16194 &region);
16195 m_errorMonitor->VerifyFound();
16196
16197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16198 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16199 &region);
16200 m_errorMonitor->VerifyFound();
16201
16202 // start recording
16203 m_commandBuffer->BeginCommandBuffer();
16204
16205 // successful copies
16206 m_errorMonitor->ExpectSuccess();
16207 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16208 &region);
16209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16210 &region);
16211 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16212 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16213 &region);
16214 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16215 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16216 &region);
16217 region.imageOffset.x = 0;
16218 region.imageExtent.height = 64;
16219 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16220 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16221 &region);
16222 m_errorMonitor->VerifyNotFound();
16223
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016224 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016225 region.imageExtent = {65, 64, 1};
16226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16227 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16228 &region);
16229 m_errorMonitor->VerifyFound();
16230
16231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16232 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16233 &region);
16234 m_errorMonitor->VerifyFound();
16235
16236 // image/buffer too small (offset) on copy to image
16237 region.imageExtent = {64, 64, 1};
16238 region.imageOffset = {0, 4, 0};
16239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16240 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16241 &region);
16242 m_errorMonitor->VerifyFound();
16243
16244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16245 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16246 &region);
16247 m_errorMonitor->VerifyFound();
16248
16249 // image/buffer too small on copy to buffer
16250 region.imageExtent = {64, 64, 1};
16251 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016252 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16254 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16255 &region);
16256 m_errorMonitor->VerifyFound();
16257
16258 region.imageExtent = {64, 65, 1};
16259 region.bufferOffset = 0;
16260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16261 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16262 &region);
16263 m_errorMonitor->VerifyFound();
16264
16265 // buffer size ok but rowlength causes loose packing
16266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16267 region.imageExtent = {64, 64, 1};
16268 region.bufferRowLength = 68;
16269 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16270 &region);
16271 m_errorMonitor->VerifyFound();
16272
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016273 // An extent with zero area should produce a warning, but no error
16274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16275 region.imageExtent.width = 0;
16276 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16277 &region);
16278 m_errorMonitor->VerifyFound();
16279
Dave Houlton59a20702017-02-02 17:26:23 -070016280 // aspect bits
16281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16282 region.imageExtent = {64, 64, 1};
16283 region.bufferRowLength = 0;
16284 region.bufferImageHeight = 0;
16285 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16286 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16287 buffer_16k.handle(), 1, &region);
16288 m_errorMonitor->VerifyFound();
16289
16290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16291 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16292 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16293 &region);
16294 m_errorMonitor->VerifyFound();
16295
16296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16297 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16298 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16299 buffer_16k.handle(), 1, &region);
16300 m_errorMonitor->VerifyFound();
16301
Dave Houltonf3229d52017-02-21 15:59:08 -070016302 // Test Depth/Stencil copies
16303 if (missing_ds_support) {
16304 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16305 } else {
16306 VkBufferImageCopy ds_region = {};
16307 ds_region.bufferOffset = 0;
16308 ds_region.bufferRowLength = 0;
16309 ds_region.bufferImageHeight = 0;
16310 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16311 ds_region.imageSubresource.mipLevel = 0;
16312 ds_region.imageSubresource.baseArrayLayer = 0;
16313 ds_region.imageSubresource.layerCount = 1;
16314 ds_region.imageOffset = {0, 0, 0};
16315 ds_region.imageExtent = {256, 256, 1};
16316
16317 // Depth copies that should succeed
16318 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16319 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16320 buffer_256k.handle(), 1, &ds_region);
16321 m_errorMonitor->VerifyNotFound();
16322
16323 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16324 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16325 buffer_256k.handle(), 1, &ds_region);
16326 m_errorMonitor->VerifyNotFound();
16327
16328 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16329 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16330 buffer_128k.handle(), 1, &ds_region);
16331 m_errorMonitor->VerifyNotFound();
16332
16333 // Depth copies that should fail
16334 ds_region.bufferOffset = 4;
16335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16336 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16337 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16338 buffer_256k.handle(), 1, &ds_region);
16339 m_errorMonitor->VerifyFound();
16340
16341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16342 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16343 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16344 buffer_256k.handle(), 1, &ds_region);
16345 m_errorMonitor->VerifyFound();
16346
16347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16348 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16349 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16350 buffer_128k.handle(), 1, &ds_region);
16351 m_errorMonitor->VerifyFound();
16352
16353 // Stencil copies that should succeed
16354 ds_region.bufferOffset = 0;
16355 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16356 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16357 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16358 buffer_64k.handle(), 1, &ds_region);
16359 m_errorMonitor->VerifyNotFound();
16360
16361 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16362 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16363 buffer_64k.handle(), 1, &ds_region);
16364 m_errorMonitor->VerifyNotFound();
16365
16366 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16367 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16368 buffer_64k.handle(), 1, &ds_region);
16369 m_errorMonitor->VerifyNotFound();
16370
16371 // Stencil copies that should fail
16372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16373 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16374 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16375 buffer_16k.handle(), 1, &ds_region);
16376 m_errorMonitor->VerifyFound();
16377
16378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16379 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16380 ds_region.bufferRowLength = 260;
16381 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16382 buffer_64k.handle(), 1, &ds_region);
16383 m_errorMonitor->VerifyFound();
16384
16385 ds_region.bufferRowLength = 0;
16386 ds_region.bufferOffset = 4;
16387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16388 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16389 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16390 buffer_64k.handle(), 1, &ds_region);
16391 m_errorMonitor->VerifyFound();
16392 }
16393
Dave Houlton584d51e2017-02-16 12:52:54 -070016394 // Test compressed formats, if supported
16395 VkPhysicalDeviceFeatures device_features;
16396 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016397 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16398 device_features.textureCompressionASTC_LDR)) {
16399 printf(" No compressed formats supported - block compression tests skipped.\n");
16400 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016401 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16402 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016403 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016404 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 -070016405 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16406 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016407 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016408 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 -070016409 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016410 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16411 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016412 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016413 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16414 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016415 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16416 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016417 }
16418 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016419
Dave Houlton584d51e2017-02-16 12:52:54 -070016420 // Just fits
16421 m_errorMonitor->ExpectSuccess();
16422 region.imageExtent = {128, 128, 1};
16423 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16424 buffer_16k.handle(), 1, &region);
16425 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016426
Dave Houlton584d51e2017-02-16 12:52:54 -070016427 // with offset, too big for buffer
16428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16429 region.bufferOffset = 16;
16430 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16431 buffer_16k.handle(), 1, &region);
16432 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016433 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016434
Dave Houlton67e9b532017-03-02 17:00:10 -070016435 // extents that are not a multiple of compressed block size
16436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16437 region.imageExtent.width = 66;
16438 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16439 buffer_16k.handle(), 1, &region);
16440 m_errorMonitor->VerifyFound();
16441 region.imageExtent.width = 128;
16442
16443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016444 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016445 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16446 buffer_16k.handle(), 1, &region);
16447 m_errorMonitor->VerifyFound();
16448 region.imageExtent.height = 128;
16449
16450 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16451
16452 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16453 m_errorMonitor->ExpectSuccess();
16454 region.imageExtent.width = 66;
16455 region.imageOffset.x = 64;
16456 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16457 buffer_16k.handle(), 1, &region);
16458 region.imageExtent.width = 16;
16459 region.imageOffset.x = 0;
16460 region.imageExtent.height = 2;
16461 region.imageOffset.y = 128;
16462 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016463 buffer_16k.handle(), 1, &region);
16464 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016465 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016466
Dave Houlton584d51e2017-02-16 12:52:54 -070016467 // buffer offset must be a multiple of texel block size (16)
16468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16470 region.imageExtent = {64, 64, 1};
16471 region.bufferOffset = 24;
16472 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16473 buffer_16k.handle(), 1, &region);
16474 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016475
Dave Houlton584d51e2017-02-16 12:52:54 -070016476 // rowlength not a multiple of block width (4)
16477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16478 region.bufferOffset = 0;
16479 region.bufferRowLength = 130;
16480 region.bufferImageHeight = 0;
16481 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16482 buffer_64k.handle(), 1, &region);
16483 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016484
Dave Houlton584d51e2017-02-16 12:52:54 -070016485 // imageheight not a multiple of block height (4)
16486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16487 region.bufferRowLength = 0;
16488 region.bufferImageHeight = 130;
16489 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16490 buffer_64k.handle(), 1, &region);
16491 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016492 }
Dave Houlton59a20702017-02-02 17:26:23 -070016493}
16494
Tony Barbourd6673642016-05-05 14:46:39 -060016495TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016496 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016497
16498 ASSERT_NO_FATAL_FAILURE(InitState());
16499
Rene Lindsay135204f2016-12-22 17:11:09 -070016500 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016501 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016502 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 -070016503 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016504 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016505 vk_testing::Buffer buffer;
16506 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016507 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016508 VkBufferImageCopy region = {};
16509 region.bufferRowLength = 128;
16510 region.bufferImageHeight = 128;
16511 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16512 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016513 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016514 region.imageExtent.height = 4;
16515 region.imageExtent.width = 4;
16516 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016517
16518 VkImageObj image2(m_device);
16519 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 -070016520 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016521 ASSERT_TRUE(image2.initialized());
16522 vk_testing::Buffer buffer2;
16523 VkMemoryPropertyFlags reqs2 = 0;
16524 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16525 VkBufferImageCopy region2 = {};
16526 region2.bufferRowLength = 128;
16527 region2.bufferImageHeight = 128;
16528 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16529 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16530 region2.imageSubresource.layerCount = 1;
16531 region2.imageExtent.height = 4;
16532 region2.imageExtent.width = 4;
16533 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016534 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016535
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016536 // Image must have offset.z of 0 and extent.depth of 1
16537 // Introduce failure by setting imageExtent.depth to 0
16538 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016540 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016541 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016542 m_errorMonitor->VerifyFound();
16543
16544 region.imageExtent.depth = 1;
16545
16546 // Image must have offset.z of 0 and extent.depth of 1
16547 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016548 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016549 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016552 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016553 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016554 m_errorMonitor->VerifyFound();
16555
16556 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016557 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16558 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016559 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016561 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16562 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016563 m_errorMonitor->VerifyFound();
16564
16565 // BufferOffset must be a multiple of 4
16566 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016567 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016569 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16570 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016571 m_errorMonitor->VerifyFound();
16572
16573 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16574 region.bufferOffset = 0;
16575 region.imageExtent.height = 128;
16576 region.imageExtent.width = 128;
16577 // Introduce failure by setting bufferRowLength > 0 but less than width
16578 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016580 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16581 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016582 m_errorMonitor->VerifyFound();
16583
16584 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16585 region.bufferRowLength = 128;
16586 // Introduce failure by setting bufferRowHeight > 0 but less than height
16587 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016589 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16590 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016591 m_errorMonitor->VerifyFound();
16592
16593 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016594 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016595 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16596 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016597 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016598 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16599 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016600 VkImageBlit blitRegion = {};
16601 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16602 blitRegion.srcSubresource.baseArrayLayer = 0;
16603 blitRegion.srcSubresource.layerCount = 1;
16604 blitRegion.srcSubresource.mipLevel = 0;
16605 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16606 blitRegion.dstSubresource.baseArrayLayer = 0;
16607 blitRegion.dstSubresource.layerCount = 1;
16608 blitRegion.dstSubresource.mipLevel = 0;
16609
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016610 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016612 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016613 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16614 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016615 m_errorMonitor->VerifyFound();
16616
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016618 VkImageMemoryBarrier img_barrier;
16619 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16620 img_barrier.pNext = NULL;
16621 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16622 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16623 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16624 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16625 img_barrier.image = image.handle();
16626 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16627 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16628 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16629 img_barrier.subresourceRange.baseArrayLayer = 0;
16630 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016631 img_barrier.subresourceRange.layerCount = 0;
16632 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016633 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16634 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016635 m_errorMonitor->VerifyFound();
16636 img_barrier.subresourceRange.layerCount = 1;
16637}
16638
16639TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016640 TEST_DESCRIPTION("Exceed the limits of image format ");
16641
Cody Northropc31a84f2016-08-22 10:41:47 -060016642 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016644 VkImageCreateInfo image_create_info = {};
16645 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16646 image_create_info.pNext = NULL;
16647 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16648 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16649 image_create_info.extent.width = 32;
16650 image_create_info.extent.height = 32;
16651 image_create_info.extent.depth = 1;
16652 image_create_info.mipLevels = 1;
16653 image_create_info.arrayLayers = 1;
16654 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16655 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16656 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16657 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16658 image_create_info.flags = 0;
16659
16660 VkImage nullImg;
16661 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016662 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16663 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016664 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016665 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16666 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16667 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016668 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016671 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16672 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16673 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16674 m_errorMonitor->VerifyFound();
16675 image_create_info.mipLevels = 1;
16676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016678 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16679 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16680 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16681 m_errorMonitor->VerifyFound();
16682 image_create_info.arrayLayers = 1;
16683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016685 int samples = imgFmtProps.sampleCounts >> 1;
16686 image_create_info.samples = (VkSampleCountFlagBits)samples;
16687 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16688 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16689 m_errorMonitor->VerifyFound();
16690 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16691
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16693 "pCreateInfo->initialLayout, must be "
16694 "VK_IMAGE_LAYOUT_UNDEFINED or "
16695 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016696 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16697 // Expect INVALID_LAYOUT
16698 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16699 m_errorMonitor->VerifyFound();
16700 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16701}
16702
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016703TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016704 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016706
16707 ASSERT_NO_FATAL_FAILURE(InitState());
16708
16709 VkImageObj src_image(m_device);
16710 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16711 VkImageObj dst_image(m_device);
16712 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16713
Tony Barbour552f6c02016-12-21 14:34:07 -070016714 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016715 VkImageCopy copy_region;
16716 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16717 copy_region.srcSubresource.mipLevel = 0;
16718 copy_region.srcSubresource.baseArrayLayer = 0;
16719 copy_region.srcSubresource.layerCount = 0;
16720 copy_region.srcOffset.x = 0;
16721 copy_region.srcOffset.y = 0;
16722 copy_region.srcOffset.z = 0;
16723 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16724 copy_region.dstSubresource.mipLevel = 0;
16725 copy_region.dstSubresource.baseArrayLayer = 0;
16726 copy_region.dstSubresource.layerCount = 0;
16727 copy_region.dstOffset.x = 0;
16728 copy_region.dstOffset.y = 0;
16729 copy_region.dstOffset.z = 0;
16730 copy_region.extent.width = 64;
16731 copy_region.extent.height = 64;
16732 copy_region.extent.depth = 1;
16733 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16734 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016735 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016736
16737 m_errorMonitor->VerifyFound();
16738}
16739
16740TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016741 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016743
16744 ASSERT_NO_FATAL_FAILURE(InitState());
16745
16746 VkImageObj src_image(m_device);
16747 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16748 VkImageObj dst_image(m_device);
16749 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16750
Tony Barbour552f6c02016-12-21 14:34:07 -070016751 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016752 VkImageCopy copy_region;
16753 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16754 copy_region.srcSubresource.mipLevel = 0;
16755 copy_region.srcSubresource.baseArrayLayer = 0;
16756 copy_region.srcSubresource.layerCount = 0;
16757 copy_region.srcOffset.x = 0;
16758 copy_region.srcOffset.y = 0;
16759 copy_region.srcOffset.z = 0;
16760 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16761 copy_region.dstSubresource.mipLevel = 0;
16762 copy_region.dstSubresource.baseArrayLayer = 0;
16763 copy_region.dstSubresource.layerCount = 0;
16764 copy_region.dstOffset.x = 0;
16765 copy_region.dstOffset.y = 0;
16766 copy_region.dstOffset.z = 0;
16767 copy_region.extent.width = 64;
16768 copy_region.extent.height = 64;
16769 copy_region.extent.depth = 1;
16770 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16771 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016772 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016773
16774 m_errorMonitor->VerifyFound();
16775}
16776
Karl Schultz6addd812016-02-02 17:17:23 -070016777TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016778 VkResult err;
16779 bool pass;
16780
16781 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016783
16784 ASSERT_NO_FATAL_FAILURE(InitState());
16785
16786 // Create two images of different types and try to copy between them
16787 VkImage srcImage;
16788 VkImage dstImage;
16789 VkDeviceMemory srcMem;
16790 VkDeviceMemory destMem;
16791 VkMemoryRequirements memReqs;
16792
16793 VkImageCreateInfo image_create_info = {};
16794 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16795 image_create_info.pNext = NULL;
16796 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16797 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16798 image_create_info.extent.width = 32;
16799 image_create_info.extent.height = 32;
16800 image_create_info.extent.depth = 1;
16801 image_create_info.mipLevels = 1;
16802 image_create_info.arrayLayers = 1;
16803 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16804 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16805 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16806 image_create_info.flags = 0;
16807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016808 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016809 ASSERT_VK_SUCCESS(err);
16810
16811 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16812 // Introduce failure by creating second image with a different-sized format.
16813 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016815 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016816 ASSERT_VK_SUCCESS(err);
16817
16818 // Allocate memory
16819 VkMemoryAllocateInfo memAlloc = {};
16820 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16821 memAlloc.pNext = NULL;
16822 memAlloc.allocationSize = 0;
16823 memAlloc.memoryTypeIndex = 0;
16824
16825 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16826 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016827 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016828 ASSERT_TRUE(pass);
16829 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16830 ASSERT_VK_SUCCESS(err);
16831
16832 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16833 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016834 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016835 ASSERT_TRUE(pass);
16836 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16837 ASSERT_VK_SUCCESS(err);
16838
16839 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16840 ASSERT_VK_SUCCESS(err);
16841 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16842 ASSERT_VK_SUCCESS(err);
16843
Tony Barbour552f6c02016-12-21 14:34:07 -070016844 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016845 VkImageCopy copyRegion;
16846 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16847 copyRegion.srcSubresource.mipLevel = 0;
16848 copyRegion.srcSubresource.baseArrayLayer = 0;
16849 copyRegion.srcSubresource.layerCount = 0;
16850 copyRegion.srcOffset.x = 0;
16851 copyRegion.srcOffset.y = 0;
16852 copyRegion.srcOffset.z = 0;
16853 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16854 copyRegion.dstSubresource.mipLevel = 0;
16855 copyRegion.dstSubresource.baseArrayLayer = 0;
16856 copyRegion.dstSubresource.layerCount = 0;
16857 copyRegion.dstOffset.x = 0;
16858 copyRegion.dstOffset.y = 0;
16859 copyRegion.dstOffset.z = 0;
16860 copyRegion.extent.width = 1;
16861 copyRegion.extent.height = 1;
16862 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016863 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016864 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016865
16866 m_errorMonitor->VerifyFound();
16867
16868 vkDestroyImage(m_device->device(), srcImage, NULL);
16869 vkDestroyImage(m_device->device(), dstImage, NULL);
16870 vkFreeMemory(m_device->device(), srcMem, NULL);
16871 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016872}
16873
Karl Schultz6addd812016-02-02 17:17:23 -070016874TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16875 VkResult err;
16876 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016877
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016878 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16880 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016881
Mike Stroyana3082432015-09-25 13:39:21 -060016882 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016883
16884 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016885 VkImage srcImage;
16886 VkImage dstImage;
16887 VkDeviceMemory srcMem;
16888 VkDeviceMemory destMem;
16889 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016890
16891 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016892 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16893 image_create_info.pNext = NULL;
16894 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16895 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16896 image_create_info.extent.width = 32;
16897 image_create_info.extent.height = 32;
16898 image_create_info.extent.depth = 1;
16899 image_create_info.mipLevels = 1;
16900 image_create_info.arrayLayers = 1;
16901 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16902 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16903 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16904 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016905
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016906 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016907 ASSERT_VK_SUCCESS(err);
16908
Karl Schultzbdb75952016-04-19 11:36:49 -060016909 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16910
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016911 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016912 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016913 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016914 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016916 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016917 ASSERT_VK_SUCCESS(err);
16918
16919 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016920 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016921 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16922 memAlloc.pNext = NULL;
16923 memAlloc.allocationSize = 0;
16924 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016925
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016926 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016927 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016928 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016929 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016930 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016931 ASSERT_VK_SUCCESS(err);
16932
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016933 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016934 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016935 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016936 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016937 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016938 ASSERT_VK_SUCCESS(err);
16939
16940 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16941 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016942 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016943 ASSERT_VK_SUCCESS(err);
16944
Tony Barbour552f6c02016-12-21 14:34:07 -070016945 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016946 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016947 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016948 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016949 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016950 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016951 copyRegion.srcOffset.x = 0;
16952 copyRegion.srcOffset.y = 0;
16953 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016954 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016955 copyRegion.dstSubresource.mipLevel = 0;
16956 copyRegion.dstSubresource.baseArrayLayer = 0;
16957 copyRegion.dstSubresource.layerCount = 0;
16958 copyRegion.dstOffset.x = 0;
16959 copyRegion.dstOffset.y = 0;
16960 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016961 copyRegion.extent.width = 1;
16962 copyRegion.extent.height = 1;
16963 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016964 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016965 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016966
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016967 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016968
Chia-I Wuf7458c52015-10-26 21:10:41 +080016969 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016970 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016971 vkFreeMemory(m_device->device(), srcMem, NULL);
16972 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016973}
16974
Karl Schultz6addd812016-02-02 17:17:23 -070016975TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16976 VkResult err;
16977 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16980 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016981
Mike Stroyana3082432015-09-25 13:39:21 -060016982 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016983
16984 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016985 VkImage srcImage;
16986 VkImage dstImage;
16987 VkDeviceMemory srcMem;
16988 VkDeviceMemory destMem;
16989 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016990
16991 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016992 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16993 image_create_info.pNext = NULL;
16994 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16995 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16996 image_create_info.extent.width = 32;
16997 image_create_info.extent.height = 1;
16998 image_create_info.extent.depth = 1;
16999 image_create_info.mipLevels = 1;
17000 image_create_info.arrayLayers = 1;
17001 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17002 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17003 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17004 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017006 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017007 ASSERT_VK_SUCCESS(err);
17008
Karl Schultz6addd812016-02-02 17:17:23 -070017009 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017011 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017012 ASSERT_VK_SUCCESS(err);
17013
17014 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017015 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017016 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17017 memAlloc.pNext = NULL;
17018 memAlloc.allocationSize = 0;
17019 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017020
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017021 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017022 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017023 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017024 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017025 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017026 ASSERT_VK_SUCCESS(err);
17027
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017028 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017029 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017030 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017031 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017032 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017033 ASSERT_VK_SUCCESS(err);
17034
17035 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17036 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017037 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017038 ASSERT_VK_SUCCESS(err);
17039
Tony Barbour552f6c02016-12-21 14:34:07 -070017040 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017041 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017042 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17043 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017044 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017045 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017046 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017047 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017048 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017049 resolveRegion.srcOffset.x = 0;
17050 resolveRegion.srcOffset.y = 0;
17051 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017052 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017053 resolveRegion.dstSubresource.mipLevel = 0;
17054 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017055 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017056 resolveRegion.dstOffset.x = 0;
17057 resolveRegion.dstOffset.y = 0;
17058 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017059 resolveRegion.extent.width = 1;
17060 resolveRegion.extent.height = 1;
17061 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017062 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017063 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017065 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017066
Chia-I Wuf7458c52015-10-26 21:10:41 +080017067 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017068 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017069 vkFreeMemory(m_device->device(), srcMem, NULL);
17070 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017071}
17072
Karl Schultz6addd812016-02-02 17:17:23 -070017073TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17074 VkResult err;
17075 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017076
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17078 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017079
Mike Stroyana3082432015-09-25 13:39:21 -060017080 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017081
Chris Forbesa7530692016-05-08 12:35:39 +120017082 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017083 VkImage srcImage;
17084 VkImage dstImage;
17085 VkDeviceMemory srcMem;
17086 VkDeviceMemory destMem;
17087 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017088
17089 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017090 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17091 image_create_info.pNext = NULL;
17092 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17093 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17094 image_create_info.extent.width = 32;
17095 image_create_info.extent.height = 1;
17096 image_create_info.extent.depth = 1;
17097 image_create_info.mipLevels = 1;
17098 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017099 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017100 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17101 // Note: Some implementations expect color attachment usage for any
17102 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017103 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017104 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017106 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017107 ASSERT_VK_SUCCESS(err);
17108
Karl Schultz6addd812016-02-02 17:17:23 -070017109 // Note: Some implementations expect color attachment usage for any
17110 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017111 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017113 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017114 ASSERT_VK_SUCCESS(err);
17115
17116 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017117 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017118 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17119 memAlloc.pNext = NULL;
17120 memAlloc.allocationSize = 0;
17121 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017122
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017123 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017124 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017125 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017126 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017127 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017128 ASSERT_VK_SUCCESS(err);
17129
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017130 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017131 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017132 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017133 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017134 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017135 ASSERT_VK_SUCCESS(err);
17136
17137 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17138 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017139 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017140 ASSERT_VK_SUCCESS(err);
17141
Tony Barbour552f6c02016-12-21 14:34:07 -070017142 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017143 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017144 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17145 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017146 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017147 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017148 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017149 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017150 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017151 resolveRegion.srcOffset.x = 0;
17152 resolveRegion.srcOffset.y = 0;
17153 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017154 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017155 resolveRegion.dstSubresource.mipLevel = 0;
17156 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017157 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017158 resolveRegion.dstOffset.x = 0;
17159 resolveRegion.dstOffset.y = 0;
17160 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017161 resolveRegion.extent.width = 1;
17162 resolveRegion.extent.height = 1;
17163 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017164 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017165 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017166
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017167 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017168
Chia-I Wuf7458c52015-10-26 21:10:41 +080017169 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017170 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017171 vkFreeMemory(m_device->device(), srcMem, NULL);
17172 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017173}
17174
Karl Schultz6addd812016-02-02 17:17:23 -070017175TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17176 VkResult err;
17177 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017178
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017180 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017181
Mike Stroyana3082432015-09-25 13:39:21 -060017182 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017183
17184 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017185 VkImage srcImage;
17186 VkImage dstImage;
17187 VkDeviceMemory srcMem;
17188 VkDeviceMemory destMem;
17189 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017190
17191 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17193 image_create_info.pNext = NULL;
17194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17195 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17196 image_create_info.extent.width = 32;
17197 image_create_info.extent.height = 1;
17198 image_create_info.extent.depth = 1;
17199 image_create_info.mipLevels = 1;
17200 image_create_info.arrayLayers = 1;
17201 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17202 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17203 // Note: Some implementations expect color attachment usage for any
17204 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017205 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017206 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017208 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017209 ASSERT_VK_SUCCESS(err);
17210
Karl Schultz6addd812016-02-02 17:17:23 -070017211 // Set format to something other than source image
17212 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17213 // Note: Some implementations expect color attachment usage for any
17214 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017215 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017216 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017218 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017219 ASSERT_VK_SUCCESS(err);
17220
17221 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017222 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017223 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17224 memAlloc.pNext = NULL;
17225 memAlloc.allocationSize = 0;
17226 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017227
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017228 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017229 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017230 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017231 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017232 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017233 ASSERT_VK_SUCCESS(err);
17234
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017235 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017236 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017237 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017238 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017239 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017240 ASSERT_VK_SUCCESS(err);
17241
17242 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17243 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017244 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017245 ASSERT_VK_SUCCESS(err);
17246
Tony Barbour552f6c02016-12-21 14:34:07 -070017247 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017248 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017249 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17250 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017251 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017252 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017253 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017254 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017255 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017256 resolveRegion.srcOffset.x = 0;
17257 resolveRegion.srcOffset.y = 0;
17258 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017259 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017260 resolveRegion.dstSubresource.mipLevel = 0;
17261 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017262 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017263 resolveRegion.dstOffset.x = 0;
17264 resolveRegion.dstOffset.y = 0;
17265 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017266 resolveRegion.extent.width = 1;
17267 resolveRegion.extent.height = 1;
17268 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017269 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017270 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017271
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017272 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017273
Chia-I Wuf7458c52015-10-26 21:10:41 +080017274 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017275 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017276 vkFreeMemory(m_device->device(), srcMem, NULL);
17277 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017278}
17279
Karl Schultz6addd812016-02-02 17:17:23 -070017280TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17281 VkResult err;
17282 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017283
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017285 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017286
Mike Stroyana3082432015-09-25 13:39:21 -060017287 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017288
17289 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017290 VkImage srcImage;
17291 VkImage dstImage;
17292 VkDeviceMemory srcMem;
17293 VkDeviceMemory destMem;
17294 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017295
17296 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017297 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17298 image_create_info.pNext = NULL;
17299 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17300 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17301 image_create_info.extent.width = 32;
17302 image_create_info.extent.height = 1;
17303 image_create_info.extent.depth = 1;
17304 image_create_info.mipLevels = 1;
17305 image_create_info.arrayLayers = 1;
17306 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17307 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17308 // Note: Some implementations expect color attachment usage for any
17309 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017310 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017311 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017313 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017314 ASSERT_VK_SUCCESS(err);
17315
Karl Schultz6addd812016-02-02 17:17:23 -070017316 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17317 // Note: Some implementations expect color attachment usage for any
17318 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017319 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017322 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017323 ASSERT_VK_SUCCESS(err);
17324
17325 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017326 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017327 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17328 memAlloc.pNext = NULL;
17329 memAlloc.allocationSize = 0;
17330 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017331
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017332 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017333 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017334 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017335 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017336 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017337 ASSERT_VK_SUCCESS(err);
17338
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017339 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017340 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017341 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017342 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017343 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017344 ASSERT_VK_SUCCESS(err);
17345
17346 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17347 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017348 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017349 ASSERT_VK_SUCCESS(err);
17350
Tony Barbour552f6c02016-12-21 14:34:07 -070017351 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017352 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017353 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17354 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017355 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017356 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017357 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017358 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017359 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017360 resolveRegion.srcOffset.x = 0;
17361 resolveRegion.srcOffset.y = 0;
17362 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017363 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017364 resolveRegion.dstSubresource.mipLevel = 0;
17365 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017366 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017367 resolveRegion.dstOffset.x = 0;
17368 resolveRegion.dstOffset.y = 0;
17369 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017370 resolveRegion.extent.width = 1;
17371 resolveRegion.extent.height = 1;
17372 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017373 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017374 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017375
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017376 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017377
Chia-I Wuf7458c52015-10-26 21:10:41 +080017378 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017379 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017380 vkFreeMemory(m_device->device(), srcMem, NULL);
17381 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017382}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017383
Karl Schultz6addd812016-02-02 17:17:23 -070017384TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017385 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017386 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17387 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017388 // The image format check comes 2nd in validation so we trigger it first,
17389 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017390 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17393 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017394
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017395 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017396
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017397 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017398 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17399 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017400
17401 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017402 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17403 ds_pool_ci.pNext = NULL;
17404 ds_pool_ci.maxSets = 1;
17405 ds_pool_ci.poolSizeCount = 1;
17406 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017407
17408 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017409 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017410 ASSERT_VK_SUCCESS(err);
17411
17412 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017413 dsl_binding.binding = 0;
17414 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17415 dsl_binding.descriptorCount = 1;
17416 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17417 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017418
17419 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017420 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17421 ds_layout_ci.pNext = NULL;
17422 ds_layout_ci.bindingCount = 1;
17423 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017424 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017426 ASSERT_VK_SUCCESS(err);
17427
17428 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017429 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017431 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017432 alloc_info.descriptorPool = ds_pool;
17433 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017435 ASSERT_VK_SUCCESS(err);
17436
Karl Schultz6addd812016-02-02 17:17:23 -070017437 VkImage image_bad;
17438 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017439 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017440 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017441 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017442 const int32_t tex_width = 32;
17443 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017444
17445 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017446 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17447 image_create_info.pNext = NULL;
17448 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17449 image_create_info.format = tex_format_bad;
17450 image_create_info.extent.width = tex_width;
17451 image_create_info.extent.height = tex_height;
17452 image_create_info.extent.depth = 1;
17453 image_create_info.mipLevels = 1;
17454 image_create_info.arrayLayers = 1;
17455 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17456 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017457 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017458 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017460 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017461 ASSERT_VK_SUCCESS(err);
17462 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017463 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17464 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017465 ASSERT_VK_SUCCESS(err);
17466
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017467 // ---Bind image memory---
17468 VkMemoryRequirements img_mem_reqs;
17469 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17470 VkMemoryAllocateInfo image_alloc_info = {};
17471 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17472 image_alloc_info.pNext = NULL;
17473 image_alloc_info.memoryTypeIndex = 0;
17474 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017475 bool pass =
17476 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 -070017477 ASSERT_TRUE(pass);
17478 VkDeviceMemory mem;
17479 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17480 ASSERT_VK_SUCCESS(err);
17481 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17482 ASSERT_VK_SUCCESS(err);
17483 // -----------------------
17484
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017485 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017486 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017487 image_view_create_info.image = image_bad;
17488 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17489 image_view_create_info.format = tex_format_bad;
17490 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17491 image_view_create_info.subresourceRange.baseMipLevel = 0;
17492 image_view_create_info.subresourceRange.layerCount = 1;
17493 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017494 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017495
17496 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017497 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017498
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017499 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017500
Chia-I Wuf7458c52015-10-26 21:10:41 +080017501 vkDestroyImage(m_device->device(), image_bad, NULL);
17502 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17504 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017505
17506 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017507}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017508
17509TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017510 TEST_DESCRIPTION(
17511 "Call ClearColorImage w/ a depth|stencil image and "
17512 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017513
17514 ASSERT_NO_FATAL_FAILURE(InitState());
17515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17516
Tony Barbour552f6c02016-12-21 14:34:07 -070017517 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017518
17519 // Color image
17520 VkClearColorValue clear_color;
17521 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17522 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17523 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17524 const int32_t img_width = 32;
17525 const int32_t img_height = 32;
17526 VkImageCreateInfo image_create_info = {};
17527 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17528 image_create_info.pNext = NULL;
17529 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17530 image_create_info.format = color_format;
17531 image_create_info.extent.width = img_width;
17532 image_create_info.extent.height = img_height;
17533 image_create_info.extent.depth = 1;
17534 image_create_info.mipLevels = 1;
17535 image_create_info.arrayLayers = 1;
17536 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17537 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17538 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17539
17540 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017541 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017543 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017544
17545 // Depth/Stencil image
17546 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017547 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017548 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17549 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17550 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17551 ds_image_create_info.extent.width = 64;
17552 ds_image_create_info.extent.height = 64;
17553 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017554 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 -060017555
17556 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017557 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017559 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 -060017560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017563 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017564 &color_range);
17565
17566 m_errorMonitor->VerifyFound();
17567
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17569 "vkCmdClearColorImage called with "
17570 "image created without "
17571 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017572
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017573 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017574 &color_range);
17575
17576 m_errorMonitor->VerifyFound();
17577
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017578 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17580 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017581
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017582 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17583 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017584
17585 m_errorMonitor->VerifyFound();
17586}
Tobin Ehliscde08892015-09-22 10:11:37 -060017587
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017588// WSI Enabled Tests
17589//
Chris Forbes09368e42016-10-13 11:59:22 +130017590#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017591TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17592
17593#if defined(VK_USE_PLATFORM_XCB_KHR)
17594 VkSurfaceKHR surface = VK_NULL_HANDLE;
17595
17596 VkResult err;
17597 bool pass;
17598 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17599 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17600 // uint32_t swapchain_image_count = 0;
17601 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17602 // uint32_t image_index = 0;
17603 // VkPresentInfoKHR present_info = {};
17604
17605 ASSERT_NO_FATAL_FAILURE(InitState());
17606
17607 // Use the create function from one of the VK_KHR_*_surface extension in
17608 // order to create a surface, testing all known errors in the process,
17609 // before successfully creating a surface:
17610 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17612 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17613 pass = (err != VK_SUCCESS);
17614 ASSERT_TRUE(pass);
17615 m_errorMonitor->VerifyFound();
17616
17617 // Next, try to create a surface with the wrong
17618 // VkXcbSurfaceCreateInfoKHR::sType:
17619 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17620 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17622 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17623 pass = (err != VK_SUCCESS);
17624 ASSERT_TRUE(pass);
17625 m_errorMonitor->VerifyFound();
17626
17627 // Create a native window, and then correctly create a surface:
17628 xcb_connection_t *connection;
17629 xcb_screen_t *screen;
17630 xcb_window_t xcb_window;
17631 xcb_intern_atom_reply_t *atom_wm_delete_window;
17632
17633 const xcb_setup_t *setup;
17634 xcb_screen_iterator_t iter;
17635 int scr;
17636 uint32_t value_mask, value_list[32];
17637 int width = 1;
17638 int height = 1;
17639
17640 connection = xcb_connect(NULL, &scr);
17641 ASSERT_TRUE(connection != NULL);
17642 setup = xcb_get_setup(connection);
17643 iter = xcb_setup_roots_iterator(setup);
17644 while (scr-- > 0)
17645 xcb_screen_next(&iter);
17646 screen = iter.data;
17647
17648 xcb_window = xcb_generate_id(connection);
17649
17650 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17651 value_list[0] = screen->black_pixel;
17652 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17653
17654 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17655 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17656
17657 /* Magic code that will send notification when window is destroyed */
17658 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17659 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17660
17661 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17662 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17663 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17664 free(reply);
17665
17666 xcb_map_window(connection, xcb_window);
17667
17668 // Force the x/y coordinates to 100,100 results are identical in consecutive
17669 // runs
17670 const uint32_t coords[] = { 100, 100 };
17671 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17672
17673 // Finally, try to correctly create a surface:
17674 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17675 xcb_create_info.pNext = NULL;
17676 xcb_create_info.flags = 0;
17677 xcb_create_info.connection = connection;
17678 xcb_create_info.window = xcb_window;
17679 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17680 pass = (err == VK_SUCCESS);
17681 ASSERT_TRUE(pass);
17682
17683 // Check if surface supports presentation:
17684
17685 // 1st, do so without having queried the queue families:
17686 VkBool32 supported = false;
17687 // TODO: Get the following error to come out:
17688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17689 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17690 "function");
17691 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17692 pass = (err != VK_SUCCESS);
17693 // ASSERT_TRUE(pass);
17694 // m_errorMonitor->VerifyFound();
17695
17696 // Next, query a queue family index that's too large:
17697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17698 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17699 pass = (err != VK_SUCCESS);
17700 ASSERT_TRUE(pass);
17701 m_errorMonitor->VerifyFound();
17702
17703 // Finally, do so correctly:
17704 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17705 // SUPPORTED
17706 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17707 pass = (err == VK_SUCCESS);
17708 ASSERT_TRUE(pass);
17709
17710 // Before proceeding, try to create a swapchain without having called
17711 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17712 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17713 swapchain_create_info.pNext = NULL;
17714 swapchain_create_info.flags = 0;
17715 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17716 swapchain_create_info.surface = surface;
17717 swapchain_create_info.imageArrayLayers = 1;
17718 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17719 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17721 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17722 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17723 pass = (err != VK_SUCCESS);
17724 ASSERT_TRUE(pass);
17725 m_errorMonitor->VerifyFound();
17726
17727 // Get the surface capabilities:
17728 VkSurfaceCapabilitiesKHR surface_capabilities;
17729
17730 // Do so correctly (only error logged by this entrypoint is if the
17731 // extension isn't enabled):
17732 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17733 pass = (err == VK_SUCCESS);
17734 ASSERT_TRUE(pass);
17735
17736 // Get the surface formats:
17737 uint32_t surface_format_count;
17738
17739 // First, try without a pointer to surface_format_count:
17740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17741 "specified as NULL");
17742 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17743 pass = (err == VK_SUCCESS);
17744 ASSERT_TRUE(pass);
17745 m_errorMonitor->VerifyFound();
17746
17747 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17748 // correctly done a 1st try (to get the count):
17749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17750 surface_format_count = 0;
17751 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17752 pass = (err == VK_SUCCESS);
17753 ASSERT_TRUE(pass);
17754 m_errorMonitor->VerifyFound();
17755
17756 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17757 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17758 pass = (err == VK_SUCCESS);
17759 ASSERT_TRUE(pass);
17760
17761 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17762 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17763
17764 // Next, do a 2nd try with surface_format_count being set too high:
17765 surface_format_count += 5;
17766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17767 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17768 pass = (err == VK_SUCCESS);
17769 ASSERT_TRUE(pass);
17770 m_errorMonitor->VerifyFound();
17771
17772 // Finally, do a correct 1st and 2nd try:
17773 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17774 pass = (err == VK_SUCCESS);
17775 ASSERT_TRUE(pass);
17776 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17777 pass = (err == VK_SUCCESS);
17778 ASSERT_TRUE(pass);
17779
17780 // Get the surface present modes:
17781 uint32_t surface_present_mode_count;
17782
17783 // First, try without a pointer to surface_format_count:
17784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17785 "specified as NULL");
17786
17787 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17788 pass = (err == VK_SUCCESS);
17789 ASSERT_TRUE(pass);
17790 m_errorMonitor->VerifyFound();
17791
17792 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17793 // correctly done a 1st try (to get the count):
17794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17795 surface_present_mode_count = 0;
17796 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17797 (VkPresentModeKHR *)&surface_present_mode_count);
17798 pass = (err == VK_SUCCESS);
17799 ASSERT_TRUE(pass);
17800 m_errorMonitor->VerifyFound();
17801
17802 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17803 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17804 pass = (err == VK_SUCCESS);
17805 ASSERT_TRUE(pass);
17806
17807 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17808 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17809
17810 // Next, do a 2nd try with surface_format_count being set too high:
17811 surface_present_mode_count += 5;
17812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17813 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17814 pass = (err == VK_SUCCESS);
17815 ASSERT_TRUE(pass);
17816 m_errorMonitor->VerifyFound();
17817
17818 // Finally, do a correct 1st and 2nd try:
17819 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17820 pass = (err == VK_SUCCESS);
17821 ASSERT_TRUE(pass);
17822 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17823 pass = (err == VK_SUCCESS);
17824 ASSERT_TRUE(pass);
17825
17826 // Create a swapchain:
17827
17828 // First, try without a pointer to swapchain_create_info:
17829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17830 "specified as NULL");
17831
17832 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17833 pass = (err != VK_SUCCESS);
17834 ASSERT_TRUE(pass);
17835 m_errorMonitor->VerifyFound();
17836
17837 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17838 // sType:
17839 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17841
17842 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17843 pass = (err != VK_SUCCESS);
17844 ASSERT_TRUE(pass);
17845 m_errorMonitor->VerifyFound();
17846
17847 // Next, call with a NULL swapchain pointer:
17848 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17849 swapchain_create_info.pNext = NULL;
17850 swapchain_create_info.flags = 0;
17851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17852 "specified as NULL");
17853
17854 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17855 pass = (err != VK_SUCCESS);
17856 ASSERT_TRUE(pass);
17857 m_errorMonitor->VerifyFound();
17858
17859 // TODO: Enhance swapchain layer so that
17860 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17861
17862 // Next, call with a queue family index that's too large:
17863 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17864 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17865 swapchain_create_info.queueFamilyIndexCount = 2;
17866 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17868 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17869 pass = (err != VK_SUCCESS);
17870 ASSERT_TRUE(pass);
17871 m_errorMonitor->VerifyFound();
17872
17873 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17874 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17875 swapchain_create_info.queueFamilyIndexCount = 1;
17876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17877 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17878 "pCreateInfo->pQueueFamilyIndices).");
17879 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17880 pass = (err != VK_SUCCESS);
17881 ASSERT_TRUE(pass);
17882 m_errorMonitor->VerifyFound();
17883
17884 // Next, call with an invalid imageSharingMode:
17885 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17886 swapchain_create_info.queueFamilyIndexCount = 1;
17887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17888 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17889 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17890 pass = (err != VK_SUCCESS);
17891 ASSERT_TRUE(pass);
17892 m_errorMonitor->VerifyFound();
17893 // Fix for the future:
17894 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17895 // SUPPORTED
17896 swapchain_create_info.queueFamilyIndexCount = 0;
17897 queueFamilyIndex[0] = 0;
17898 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17899
17900 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17901 // Get the images from a swapchain:
17902 // Acquire an image from a swapchain:
17903 // Present an image to a swapchain:
17904 // Destroy the swapchain:
17905
17906 // TODOs:
17907 //
17908 // - Try destroying the device without first destroying the swapchain
17909 //
17910 // - Try destroying the device without first destroying the surface
17911 //
17912 // - Try destroying the surface without first destroying the swapchain
17913
17914 // Destroy the surface:
17915 vkDestroySurfaceKHR(instance(), surface, NULL);
17916
17917 // Tear down the window:
17918 xcb_destroy_window(connection, xcb_window);
17919 xcb_disconnect(connection);
17920
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017921#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017922 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017923#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017924}
Chris Forbes09368e42016-10-13 11:59:22 +130017925#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017926
17927//
17928// POSITIVE VALIDATION TESTS
17929//
17930// These tests do not expect to encounter ANY validation errors pass only if this is true
17931
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017932TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17933 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17934 ASSERT_NO_FATAL_FAILURE(InitState());
17935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17936
17937 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17938 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17939 command_buffer_allocate_info.commandPool = m_commandPool;
17940 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17941 command_buffer_allocate_info.commandBufferCount = 1;
17942
17943 VkCommandBuffer secondary_command_buffer;
17944 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17945 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17946 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17947 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17948 command_buffer_inheritance_info.renderPass = m_renderPass;
17949 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17950
17951 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17952 command_buffer_begin_info.flags =
17953 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17954 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17955
17956 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17957 VkClearAttachment color_attachment;
17958 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17959 color_attachment.clearValue.color.float32[0] = 0;
17960 color_attachment.clearValue.color.float32[1] = 0;
17961 color_attachment.clearValue.color.float32[2] = 0;
17962 color_attachment.clearValue.color.float32[3] = 0;
17963 color_attachment.colorAttachment = 0;
17964 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17965 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17966}
17967
Tobin Ehlise0006882016-11-03 10:14:28 -060017968TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017969 TEST_DESCRIPTION(
17970 "Perform an image layout transition in a secondary command buffer followed "
17971 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017972 VkResult err;
17973 m_errorMonitor->ExpectSuccess();
17974 ASSERT_NO_FATAL_FAILURE(InitState());
17975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17976 // Allocate a secondary and primary cmd buffer
17977 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17978 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17979 command_buffer_allocate_info.commandPool = m_commandPool;
17980 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17981 command_buffer_allocate_info.commandBufferCount = 1;
17982
17983 VkCommandBuffer secondary_command_buffer;
17984 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17985 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17986 VkCommandBuffer primary_command_buffer;
17987 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17988 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17989 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17990 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17991 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17992 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17993 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17994
17995 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17996 ASSERT_VK_SUCCESS(err);
17997 VkImageObj image(m_device);
17998 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17999 ASSERT_TRUE(image.initialized());
18000 VkImageMemoryBarrier img_barrier = {};
18001 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18002 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18003 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18004 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18005 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18006 img_barrier.image = image.handle();
18007 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18008 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18009 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18010 img_barrier.subresourceRange.baseArrayLayer = 0;
18011 img_barrier.subresourceRange.baseMipLevel = 0;
18012 img_barrier.subresourceRange.layerCount = 1;
18013 img_barrier.subresourceRange.levelCount = 1;
18014 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18015 0, nullptr, 1, &img_barrier);
18016 err = vkEndCommandBuffer(secondary_command_buffer);
18017 ASSERT_VK_SUCCESS(err);
18018
18019 // Now update primary cmd buffer to execute secondary and transitions image
18020 command_buffer_begin_info.pInheritanceInfo = nullptr;
18021 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18022 ASSERT_VK_SUCCESS(err);
18023 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18024 VkImageMemoryBarrier img_barrier2 = {};
18025 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18026 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18027 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18028 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18029 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18030 img_barrier2.image = image.handle();
18031 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18032 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18033 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18034 img_barrier2.subresourceRange.baseArrayLayer = 0;
18035 img_barrier2.subresourceRange.baseMipLevel = 0;
18036 img_barrier2.subresourceRange.layerCount = 1;
18037 img_barrier2.subresourceRange.levelCount = 1;
18038 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18039 nullptr, 1, &img_barrier2);
18040 err = vkEndCommandBuffer(primary_command_buffer);
18041 ASSERT_VK_SUCCESS(err);
18042 VkSubmitInfo submit_info = {};
18043 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18044 submit_info.commandBufferCount = 1;
18045 submit_info.pCommandBuffers = &primary_command_buffer;
18046 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18047 ASSERT_VK_SUCCESS(err);
18048 m_errorMonitor->VerifyNotFound();
18049 err = vkDeviceWaitIdle(m_device->device());
18050 ASSERT_VK_SUCCESS(err);
18051 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18052 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18053}
18054
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018055// This is a positive test. No failures are expected.
18056TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018057 TEST_DESCRIPTION(
18058 "Ensure that the vkUpdateDescriptorSets validation code "
18059 "is ignoring VkWriteDescriptorSet members that are not "
18060 "related to the descriptor type specified by "
18061 "VkWriteDescriptorSet::descriptorType. Correct "
18062 "validation behavior will result in the test running to "
18063 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018064
18065 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18066
18067 ASSERT_NO_FATAL_FAILURE(InitState());
18068
18069 // Image Case
18070 {
18071 m_errorMonitor->ExpectSuccess();
18072
18073 VkImage image;
18074 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18075 const int32_t tex_width = 32;
18076 const int32_t tex_height = 32;
18077 VkImageCreateInfo image_create_info = {};
18078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18079 image_create_info.pNext = NULL;
18080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18081 image_create_info.format = tex_format;
18082 image_create_info.extent.width = tex_width;
18083 image_create_info.extent.height = tex_height;
18084 image_create_info.extent.depth = 1;
18085 image_create_info.mipLevels = 1;
18086 image_create_info.arrayLayers = 1;
18087 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18088 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18089 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18090 image_create_info.flags = 0;
18091 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18092 ASSERT_VK_SUCCESS(err);
18093
18094 VkMemoryRequirements memory_reqs;
18095 VkDeviceMemory image_memory;
18096 bool pass;
18097 VkMemoryAllocateInfo memory_info = {};
18098 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18099 memory_info.pNext = NULL;
18100 memory_info.allocationSize = 0;
18101 memory_info.memoryTypeIndex = 0;
18102 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18103 memory_info.allocationSize = memory_reqs.size;
18104 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18105 ASSERT_TRUE(pass);
18106 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18107 ASSERT_VK_SUCCESS(err);
18108 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18109 ASSERT_VK_SUCCESS(err);
18110
18111 VkImageViewCreateInfo image_view_create_info = {};
18112 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18113 image_view_create_info.image = image;
18114 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18115 image_view_create_info.format = tex_format;
18116 image_view_create_info.subresourceRange.layerCount = 1;
18117 image_view_create_info.subresourceRange.baseMipLevel = 0;
18118 image_view_create_info.subresourceRange.levelCount = 1;
18119 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18120
18121 VkImageView view;
18122 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18123 ASSERT_VK_SUCCESS(err);
18124
18125 VkDescriptorPoolSize ds_type_count = {};
18126 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18127 ds_type_count.descriptorCount = 1;
18128
18129 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18130 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18131 ds_pool_ci.pNext = NULL;
18132 ds_pool_ci.maxSets = 1;
18133 ds_pool_ci.poolSizeCount = 1;
18134 ds_pool_ci.pPoolSizes = &ds_type_count;
18135
18136 VkDescriptorPool ds_pool;
18137 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18138 ASSERT_VK_SUCCESS(err);
18139
18140 VkDescriptorSetLayoutBinding dsl_binding = {};
18141 dsl_binding.binding = 0;
18142 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18143 dsl_binding.descriptorCount = 1;
18144 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18145 dsl_binding.pImmutableSamplers = NULL;
18146
18147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18149 ds_layout_ci.pNext = NULL;
18150 ds_layout_ci.bindingCount = 1;
18151 ds_layout_ci.pBindings = &dsl_binding;
18152 VkDescriptorSetLayout ds_layout;
18153 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18154 ASSERT_VK_SUCCESS(err);
18155
18156 VkDescriptorSet descriptor_set;
18157 VkDescriptorSetAllocateInfo alloc_info = {};
18158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18159 alloc_info.descriptorSetCount = 1;
18160 alloc_info.descriptorPool = ds_pool;
18161 alloc_info.pSetLayouts = &ds_layout;
18162 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18163 ASSERT_VK_SUCCESS(err);
18164
18165 VkDescriptorImageInfo image_info = {};
18166 image_info.imageView = view;
18167 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18168
18169 VkWriteDescriptorSet descriptor_write;
18170 memset(&descriptor_write, 0, sizeof(descriptor_write));
18171 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18172 descriptor_write.dstSet = descriptor_set;
18173 descriptor_write.dstBinding = 0;
18174 descriptor_write.descriptorCount = 1;
18175 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18176 descriptor_write.pImageInfo = &image_info;
18177
18178 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18179 // be
18180 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18181 // This will most likely produce a crash if the parameter_validation
18182 // layer
18183 // does not correctly ignore pBufferInfo.
18184 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18185 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18186
18187 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18188
18189 m_errorMonitor->VerifyNotFound();
18190
18191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18192 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18193 vkDestroyImageView(m_device->device(), view, NULL);
18194 vkDestroyImage(m_device->device(), image, NULL);
18195 vkFreeMemory(m_device->device(), image_memory, NULL);
18196 }
18197
18198 // Buffer Case
18199 {
18200 m_errorMonitor->ExpectSuccess();
18201
18202 VkBuffer buffer;
18203 uint32_t queue_family_index = 0;
18204 VkBufferCreateInfo buffer_create_info = {};
18205 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18206 buffer_create_info.size = 1024;
18207 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18208 buffer_create_info.queueFamilyIndexCount = 1;
18209 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18210
18211 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18212 ASSERT_VK_SUCCESS(err);
18213
18214 VkMemoryRequirements memory_reqs;
18215 VkDeviceMemory buffer_memory;
18216 bool pass;
18217 VkMemoryAllocateInfo memory_info = {};
18218 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18219 memory_info.pNext = NULL;
18220 memory_info.allocationSize = 0;
18221 memory_info.memoryTypeIndex = 0;
18222
18223 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18224 memory_info.allocationSize = memory_reqs.size;
18225 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18226 ASSERT_TRUE(pass);
18227
18228 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18229 ASSERT_VK_SUCCESS(err);
18230 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18231 ASSERT_VK_SUCCESS(err);
18232
18233 VkDescriptorPoolSize ds_type_count = {};
18234 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18235 ds_type_count.descriptorCount = 1;
18236
18237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18239 ds_pool_ci.pNext = NULL;
18240 ds_pool_ci.maxSets = 1;
18241 ds_pool_ci.poolSizeCount = 1;
18242 ds_pool_ci.pPoolSizes = &ds_type_count;
18243
18244 VkDescriptorPool ds_pool;
18245 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18246 ASSERT_VK_SUCCESS(err);
18247
18248 VkDescriptorSetLayoutBinding dsl_binding = {};
18249 dsl_binding.binding = 0;
18250 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18251 dsl_binding.descriptorCount = 1;
18252 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18253 dsl_binding.pImmutableSamplers = NULL;
18254
18255 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18256 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18257 ds_layout_ci.pNext = NULL;
18258 ds_layout_ci.bindingCount = 1;
18259 ds_layout_ci.pBindings = &dsl_binding;
18260 VkDescriptorSetLayout ds_layout;
18261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18262 ASSERT_VK_SUCCESS(err);
18263
18264 VkDescriptorSet descriptor_set;
18265 VkDescriptorSetAllocateInfo alloc_info = {};
18266 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18267 alloc_info.descriptorSetCount = 1;
18268 alloc_info.descriptorPool = ds_pool;
18269 alloc_info.pSetLayouts = &ds_layout;
18270 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18271 ASSERT_VK_SUCCESS(err);
18272
18273 VkDescriptorBufferInfo buffer_info = {};
18274 buffer_info.buffer = buffer;
18275 buffer_info.offset = 0;
18276 buffer_info.range = 1024;
18277
18278 VkWriteDescriptorSet descriptor_write;
18279 memset(&descriptor_write, 0, sizeof(descriptor_write));
18280 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18281 descriptor_write.dstSet = descriptor_set;
18282 descriptor_write.dstBinding = 0;
18283 descriptor_write.descriptorCount = 1;
18284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18285 descriptor_write.pBufferInfo = &buffer_info;
18286
18287 // Set pImageInfo and pTexelBufferView to invalid values, which should
18288 // be
18289 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18290 // This will most likely produce a crash if the parameter_validation
18291 // layer
18292 // does not correctly ignore pImageInfo.
18293 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18294 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18295
18296 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18297
18298 m_errorMonitor->VerifyNotFound();
18299
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18302 vkDestroyBuffer(m_device->device(), buffer, NULL);
18303 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18304 }
18305
18306 // Texel Buffer Case
18307 {
18308 m_errorMonitor->ExpectSuccess();
18309
18310 VkBuffer buffer;
18311 uint32_t queue_family_index = 0;
18312 VkBufferCreateInfo buffer_create_info = {};
18313 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18314 buffer_create_info.size = 1024;
18315 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18316 buffer_create_info.queueFamilyIndexCount = 1;
18317 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18318
18319 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18320 ASSERT_VK_SUCCESS(err);
18321
18322 VkMemoryRequirements memory_reqs;
18323 VkDeviceMemory buffer_memory;
18324 bool pass;
18325 VkMemoryAllocateInfo memory_info = {};
18326 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18327 memory_info.pNext = NULL;
18328 memory_info.allocationSize = 0;
18329 memory_info.memoryTypeIndex = 0;
18330
18331 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18332 memory_info.allocationSize = memory_reqs.size;
18333 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18334 ASSERT_TRUE(pass);
18335
18336 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18337 ASSERT_VK_SUCCESS(err);
18338 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18339 ASSERT_VK_SUCCESS(err);
18340
18341 VkBufferViewCreateInfo buff_view_ci = {};
18342 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18343 buff_view_ci.buffer = buffer;
18344 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18345 buff_view_ci.range = VK_WHOLE_SIZE;
18346 VkBufferView buffer_view;
18347 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18348
18349 VkDescriptorPoolSize ds_type_count = {};
18350 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18351 ds_type_count.descriptorCount = 1;
18352
18353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18355 ds_pool_ci.pNext = NULL;
18356 ds_pool_ci.maxSets = 1;
18357 ds_pool_ci.poolSizeCount = 1;
18358 ds_pool_ci.pPoolSizes = &ds_type_count;
18359
18360 VkDescriptorPool ds_pool;
18361 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18362 ASSERT_VK_SUCCESS(err);
18363
18364 VkDescriptorSetLayoutBinding dsl_binding = {};
18365 dsl_binding.binding = 0;
18366 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18367 dsl_binding.descriptorCount = 1;
18368 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18369 dsl_binding.pImmutableSamplers = NULL;
18370
18371 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18372 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18373 ds_layout_ci.pNext = NULL;
18374 ds_layout_ci.bindingCount = 1;
18375 ds_layout_ci.pBindings = &dsl_binding;
18376 VkDescriptorSetLayout ds_layout;
18377 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18378 ASSERT_VK_SUCCESS(err);
18379
18380 VkDescriptorSet descriptor_set;
18381 VkDescriptorSetAllocateInfo alloc_info = {};
18382 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18383 alloc_info.descriptorSetCount = 1;
18384 alloc_info.descriptorPool = ds_pool;
18385 alloc_info.pSetLayouts = &ds_layout;
18386 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18387 ASSERT_VK_SUCCESS(err);
18388
18389 VkWriteDescriptorSet descriptor_write;
18390 memset(&descriptor_write, 0, sizeof(descriptor_write));
18391 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18392 descriptor_write.dstSet = descriptor_set;
18393 descriptor_write.dstBinding = 0;
18394 descriptor_write.descriptorCount = 1;
18395 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18396 descriptor_write.pTexelBufferView = &buffer_view;
18397
18398 // Set pImageInfo and pBufferInfo to invalid values, which should be
18399 // ignored for descriptorType ==
18400 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18401 // This will most likely produce a crash if the parameter_validation
18402 // layer
18403 // does not correctly ignore pImageInfo and pBufferInfo.
18404 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18405 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18406
18407 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18408
18409 m_errorMonitor->VerifyNotFound();
18410
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18413 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18414 vkDestroyBuffer(m_device->device(), buffer, NULL);
18415 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18416 }
18417}
18418
Tobin Ehlisf7428442016-10-25 07:58:24 -060018419TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18420 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18421
18422 ASSERT_NO_FATAL_FAILURE(InitState());
18423 // Create layout where two binding #s are "1"
18424 static const uint32_t NUM_BINDINGS = 3;
18425 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18426 dsl_binding[0].binding = 1;
18427 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18428 dsl_binding[0].descriptorCount = 1;
18429 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18430 dsl_binding[0].pImmutableSamplers = NULL;
18431 dsl_binding[1].binding = 0;
18432 dsl_binding[1].descriptorCount = 1;
18433 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18434 dsl_binding[1].descriptorCount = 1;
18435 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18436 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018437 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018438 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18439 dsl_binding[2].descriptorCount = 1;
18440 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18441 dsl_binding[2].pImmutableSamplers = NULL;
18442
18443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18445 ds_layout_ci.pNext = NULL;
18446 ds_layout_ci.bindingCount = NUM_BINDINGS;
18447 ds_layout_ci.pBindings = dsl_binding;
18448 VkDescriptorSetLayout ds_layout;
18449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18450 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18451 m_errorMonitor->VerifyFound();
18452}
18453
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018454TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018455 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18456
18457 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018458
Tony Barbour552f6c02016-12-21 14:34:07 -070018459 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018460
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018461 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18462
18463 {
18464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18465 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18466 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18467 m_errorMonitor->VerifyFound();
18468 }
18469
18470 {
18471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18472 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18473 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18474 m_errorMonitor->VerifyFound();
18475 }
18476
18477 {
18478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18479 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18480 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18481 m_errorMonitor->VerifyFound();
18482 }
18483
18484 {
18485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18486 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18487 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18488 m_errorMonitor->VerifyFound();
18489 }
18490
18491 {
18492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18493 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18494 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18495 m_errorMonitor->VerifyFound();
18496 }
18497
18498 {
18499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18500 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18501 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18502 m_errorMonitor->VerifyFound();
18503 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018504
18505 {
18506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18507 VkRect2D scissor = {{-1, 0}, {16, 16}};
18508 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18509 m_errorMonitor->VerifyFound();
18510 }
18511
18512 {
18513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18514 VkRect2D scissor = {{0, -2}, {16, 16}};
18515 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18516 m_errorMonitor->VerifyFound();
18517 }
18518
18519 {
18520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18521 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18522 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18523 m_errorMonitor->VerifyFound();
18524 }
18525
18526 {
18527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18528 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18529 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18530 m_errorMonitor->VerifyFound();
18531 }
18532
Tony Barbour552f6c02016-12-21 14:34:07 -070018533 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018534}
18535
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018536// This is a positive test. No failures are expected.
18537TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18538 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18539 VkResult err;
18540
18541 ASSERT_NO_FATAL_FAILURE(InitState());
18542 m_errorMonitor->ExpectSuccess();
18543 VkDescriptorPoolSize ds_type_count = {};
18544 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18545 ds_type_count.descriptorCount = 2;
18546
18547 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18548 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18549 ds_pool_ci.pNext = NULL;
18550 ds_pool_ci.maxSets = 1;
18551 ds_pool_ci.poolSizeCount = 1;
18552 ds_pool_ci.pPoolSizes = &ds_type_count;
18553
18554 VkDescriptorPool ds_pool;
18555 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18556 ASSERT_VK_SUCCESS(err);
18557
18558 // Create layout with two uniform buffer descriptors w/ empty binding between them
18559 static const uint32_t NUM_BINDINGS = 3;
18560 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18561 dsl_binding[0].binding = 0;
18562 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18563 dsl_binding[0].descriptorCount = 1;
18564 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18565 dsl_binding[0].pImmutableSamplers = NULL;
18566 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018567 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018568 dsl_binding[2].binding = 2;
18569 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18570 dsl_binding[2].descriptorCount = 1;
18571 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18572 dsl_binding[2].pImmutableSamplers = NULL;
18573
18574 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18575 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18576 ds_layout_ci.pNext = NULL;
18577 ds_layout_ci.bindingCount = NUM_BINDINGS;
18578 ds_layout_ci.pBindings = dsl_binding;
18579 VkDescriptorSetLayout ds_layout;
18580 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18581 ASSERT_VK_SUCCESS(err);
18582
18583 VkDescriptorSet descriptor_set = {};
18584 VkDescriptorSetAllocateInfo alloc_info = {};
18585 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18586 alloc_info.descriptorSetCount = 1;
18587 alloc_info.descriptorPool = ds_pool;
18588 alloc_info.pSetLayouts = &ds_layout;
18589 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18590 ASSERT_VK_SUCCESS(err);
18591
18592 // Create a buffer to be used for update
18593 VkBufferCreateInfo buff_ci = {};
18594 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18595 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18596 buff_ci.size = 256;
18597 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18598 VkBuffer buffer;
18599 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18600 ASSERT_VK_SUCCESS(err);
18601 // Have to bind memory to buffer before descriptor update
18602 VkMemoryAllocateInfo mem_alloc = {};
18603 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18604 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018605 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018606 mem_alloc.memoryTypeIndex = 0;
18607
18608 VkMemoryRequirements mem_reqs;
18609 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18610 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18611 if (!pass) {
18612 vkDestroyBuffer(m_device->device(), buffer, NULL);
18613 return;
18614 }
18615
18616 VkDeviceMemory mem;
18617 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18618 ASSERT_VK_SUCCESS(err);
18619 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18620 ASSERT_VK_SUCCESS(err);
18621
18622 // Only update the descriptor at binding 2
18623 VkDescriptorBufferInfo buff_info = {};
18624 buff_info.buffer = buffer;
18625 buff_info.offset = 0;
18626 buff_info.range = VK_WHOLE_SIZE;
18627 VkWriteDescriptorSet descriptor_write = {};
18628 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18629 descriptor_write.dstBinding = 2;
18630 descriptor_write.descriptorCount = 1;
18631 descriptor_write.pTexelBufferView = nullptr;
18632 descriptor_write.pBufferInfo = &buff_info;
18633 descriptor_write.pImageInfo = nullptr;
18634 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18635 descriptor_write.dstSet = descriptor_set;
18636
18637 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18638
18639 m_errorMonitor->VerifyNotFound();
18640 // Cleanup
18641 vkFreeMemory(m_device->device(), mem, NULL);
18642 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18643 vkDestroyBuffer(m_device->device(), buffer, NULL);
18644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18645}
18646
18647// This is a positive test. No failures are expected.
18648TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18649 VkResult err;
18650 bool pass;
18651
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018652 TEST_DESCRIPTION(
18653 "Create a buffer, allocate memory, bind memory, destroy "
18654 "the buffer, create an image, and bind the same memory to "
18655 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018656
18657 m_errorMonitor->ExpectSuccess();
18658
18659 ASSERT_NO_FATAL_FAILURE(InitState());
18660
18661 VkBuffer buffer;
18662 VkImage image;
18663 VkDeviceMemory mem;
18664 VkMemoryRequirements mem_reqs;
18665
18666 VkBufferCreateInfo buf_info = {};
18667 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18668 buf_info.pNext = NULL;
18669 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18670 buf_info.size = 256;
18671 buf_info.queueFamilyIndexCount = 0;
18672 buf_info.pQueueFamilyIndices = NULL;
18673 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18674 buf_info.flags = 0;
18675 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18676 ASSERT_VK_SUCCESS(err);
18677
18678 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18679
18680 VkMemoryAllocateInfo alloc_info = {};
18681 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18682 alloc_info.pNext = NULL;
18683 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018684
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018685 // Ensure memory is big enough for both bindings
18686 alloc_info.allocationSize = 0x10000;
18687
18688 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18689 if (!pass) {
18690 vkDestroyBuffer(m_device->device(), buffer, NULL);
18691 return;
18692 }
18693
18694 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18695 ASSERT_VK_SUCCESS(err);
18696
18697 uint8_t *pData;
18698 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18699 ASSERT_VK_SUCCESS(err);
18700
18701 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18702
18703 vkUnmapMemory(m_device->device(), mem);
18704
18705 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18706 ASSERT_VK_SUCCESS(err);
18707
18708 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18709 // memory. In fact, it was never used by the GPU.
18710 // Just be be sure, wait for idle.
18711 vkDestroyBuffer(m_device->device(), buffer, NULL);
18712 vkDeviceWaitIdle(m_device->device());
18713
Tobin Ehlis6a005702016-12-28 15:25:56 -070018714 // Use optimal as some platforms report linear support but then fail image creation
18715 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18716 VkImageFormatProperties image_format_properties;
18717 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18718 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18719 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018720 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018721 vkFreeMemory(m_device->device(), mem, NULL);
18722 return;
18723 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018724 VkImageCreateInfo image_create_info = {};
18725 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18726 image_create_info.pNext = NULL;
18727 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18728 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18729 image_create_info.extent.width = 64;
18730 image_create_info.extent.height = 64;
18731 image_create_info.extent.depth = 1;
18732 image_create_info.mipLevels = 1;
18733 image_create_info.arrayLayers = 1;
18734 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018735 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018736 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18737 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18738 image_create_info.queueFamilyIndexCount = 0;
18739 image_create_info.pQueueFamilyIndices = NULL;
18740 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18741 image_create_info.flags = 0;
18742
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018743 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018744 * to be textures or it will be the staging image if they are not.
18745 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018746 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18747 ASSERT_VK_SUCCESS(err);
18748
18749 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18750
Tobin Ehlis6a005702016-12-28 15:25:56 -070018751 VkMemoryAllocateInfo mem_alloc = {};
18752 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18753 mem_alloc.pNext = NULL;
18754 mem_alloc.allocationSize = 0;
18755 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018756 mem_alloc.allocationSize = mem_reqs.size;
18757
18758 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18759 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018760 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018761 vkDestroyImage(m_device->device(), image, NULL);
18762 return;
18763 }
18764
18765 // VALIDATION FAILURE:
18766 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18767 ASSERT_VK_SUCCESS(err);
18768
18769 m_errorMonitor->VerifyNotFound();
18770
18771 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018772 vkDestroyImage(m_device->device(), image, NULL);
18773}
18774
Tony Barbourab713912017-02-02 14:17:35 -070018775// This is a positive test. No failures are expected.
18776TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18777 VkResult err;
18778
18779 TEST_DESCRIPTION(
18780 "Call all applicable destroy and free routines with NULL"
18781 "handles, expecting no validation errors");
18782
18783 m_errorMonitor->ExpectSuccess();
18784
18785 ASSERT_NO_FATAL_FAILURE(InitState());
18786 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18787 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18788 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18789 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18790 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18791 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18792 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18793 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18794 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18795 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18796 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18797 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18798 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18799 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18800 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18801 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18802 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18803 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18804 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18805 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18806
18807 VkCommandPool command_pool;
18808 VkCommandPoolCreateInfo pool_create_info{};
18809 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18810 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18811 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18812 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18813 VkCommandBuffer command_buffers[3] = {};
18814 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18815 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18816 command_buffer_allocate_info.commandPool = command_pool;
18817 command_buffer_allocate_info.commandBufferCount = 1;
18818 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18819 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18820 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18821 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18822
18823 VkDescriptorPoolSize ds_type_count = {};
18824 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18825 ds_type_count.descriptorCount = 1;
18826
18827 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18828 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18829 ds_pool_ci.pNext = NULL;
18830 ds_pool_ci.maxSets = 1;
18831 ds_pool_ci.poolSizeCount = 1;
18832 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18833 ds_pool_ci.pPoolSizes = &ds_type_count;
18834
18835 VkDescriptorPool ds_pool;
18836 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18837 ASSERT_VK_SUCCESS(err);
18838
18839 VkDescriptorSetLayoutBinding dsl_binding = {};
18840 dsl_binding.binding = 2;
18841 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18842 dsl_binding.descriptorCount = 1;
18843 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18844 dsl_binding.pImmutableSamplers = NULL;
18845 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18846 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18847 ds_layout_ci.pNext = NULL;
18848 ds_layout_ci.bindingCount = 1;
18849 ds_layout_ci.pBindings = &dsl_binding;
18850 VkDescriptorSetLayout ds_layout;
18851 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18852 ASSERT_VK_SUCCESS(err);
18853
18854 VkDescriptorSet descriptor_sets[3] = {};
18855 VkDescriptorSetAllocateInfo alloc_info = {};
18856 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18857 alloc_info.descriptorSetCount = 1;
18858 alloc_info.descriptorPool = ds_pool;
18859 alloc_info.pSetLayouts = &ds_layout;
18860 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18861 ASSERT_VK_SUCCESS(err);
18862 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18863 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18864 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18865
18866 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18867
18868 m_errorMonitor->VerifyNotFound();
18869}
18870
Tony Barbour626994c2017-02-08 15:29:37 -070018871TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018872 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018873
18874 m_errorMonitor->ExpectSuccess();
18875
18876 ASSERT_NO_FATAL_FAILURE(InitState());
18877 VkCommandBuffer cmd_bufs[4];
18878 VkCommandBufferAllocateInfo alloc_info;
18879 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18880 alloc_info.pNext = NULL;
18881 alloc_info.commandBufferCount = 4;
18882 alloc_info.commandPool = m_commandPool;
18883 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18884 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18885 VkImageObj image(m_device);
18886 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18887 ASSERT_TRUE(image.initialized());
18888 VkCommandBufferBeginInfo cb_binfo;
18889 cb_binfo.pNext = NULL;
18890 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18891 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18892 cb_binfo.flags = 0;
18893 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18894 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18895 VkImageMemoryBarrier img_barrier = {};
18896 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18897 img_barrier.pNext = NULL;
18898 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18899 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18900 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18901 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18902 img_barrier.image = image.handle();
18903 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18904 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18905 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18906 img_barrier.subresourceRange.baseArrayLayer = 0;
18907 img_barrier.subresourceRange.baseMipLevel = 0;
18908 img_barrier.subresourceRange.layerCount = 1;
18909 img_barrier.subresourceRange.levelCount = 1;
18910 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18911 &img_barrier);
18912 vkEndCommandBuffer(cmd_bufs[0]);
18913 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18914 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18915 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18916 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18917 &img_barrier);
18918 vkEndCommandBuffer(cmd_bufs[1]);
18919 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18920 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18921 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18922 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18923 &img_barrier);
18924 vkEndCommandBuffer(cmd_bufs[2]);
18925 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18926 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18927 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18928 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18929 &img_barrier);
18930 vkEndCommandBuffer(cmd_bufs[3]);
18931
18932 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18933 VkSemaphore semaphore1, semaphore2;
18934 VkSemaphoreCreateInfo semaphore_create_info{};
18935 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18936 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18937 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18938 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18939 VkSubmitInfo submit_info[3];
18940 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18941 submit_info[0].pNext = nullptr;
18942 submit_info[0].commandBufferCount = 1;
18943 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18944 submit_info[0].signalSemaphoreCount = 1;
18945 submit_info[0].pSignalSemaphores = &semaphore1;
18946 submit_info[0].waitSemaphoreCount = 0;
18947 submit_info[0].pWaitDstStageMask = nullptr;
18948 submit_info[0].pWaitDstStageMask = flags;
18949 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18950 submit_info[1].pNext = nullptr;
18951 submit_info[1].commandBufferCount = 1;
18952 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18953 submit_info[1].waitSemaphoreCount = 1;
18954 submit_info[1].pWaitSemaphores = &semaphore1;
18955 submit_info[1].signalSemaphoreCount = 1;
18956 submit_info[1].pSignalSemaphores = &semaphore2;
18957 submit_info[1].pWaitDstStageMask = flags;
18958 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18959 submit_info[2].pNext = nullptr;
18960 submit_info[2].commandBufferCount = 2;
18961 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18962 submit_info[2].waitSemaphoreCount = 1;
18963 submit_info[2].pWaitSemaphores = &semaphore2;
18964 submit_info[2].signalSemaphoreCount = 0;
18965 submit_info[2].pSignalSemaphores = nullptr;
18966 submit_info[2].pWaitDstStageMask = flags;
18967 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18968 vkQueueWaitIdle(m_device->m_queue);
18969
18970 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18971 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18972 m_errorMonitor->VerifyNotFound();
18973}
18974
Tobin Ehlis953e8392016-11-17 10:54:13 -070018975TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18976 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18977 // We previously had a bug where dynamic offset of inactive bindings was still being used
18978 VkResult err;
18979 m_errorMonitor->ExpectSuccess();
18980
18981 ASSERT_NO_FATAL_FAILURE(InitState());
18982 ASSERT_NO_FATAL_FAILURE(InitViewport());
18983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18984
18985 VkDescriptorPoolSize ds_type_count = {};
18986 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18987 ds_type_count.descriptorCount = 3;
18988
18989 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18990 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18991 ds_pool_ci.pNext = NULL;
18992 ds_pool_ci.maxSets = 1;
18993 ds_pool_ci.poolSizeCount = 1;
18994 ds_pool_ci.pPoolSizes = &ds_type_count;
18995
18996 VkDescriptorPool ds_pool;
18997 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18998 ASSERT_VK_SUCCESS(err);
18999
19000 const uint32_t BINDING_COUNT = 3;
19001 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019002 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019003 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19004 dsl_binding[0].descriptorCount = 1;
19005 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19006 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019007 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019008 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19009 dsl_binding[1].descriptorCount = 1;
19010 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19011 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019012 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019013 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19014 dsl_binding[2].descriptorCount = 1;
19015 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19016 dsl_binding[2].pImmutableSamplers = NULL;
19017
19018 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19019 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19020 ds_layout_ci.pNext = NULL;
19021 ds_layout_ci.bindingCount = BINDING_COUNT;
19022 ds_layout_ci.pBindings = dsl_binding;
19023 VkDescriptorSetLayout ds_layout;
19024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19025 ASSERT_VK_SUCCESS(err);
19026
19027 VkDescriptorSet descriptor_set;
19028 VkDescriptorSetAllocateInfo alloc_info = {};
19029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19030 alloc_info.descriptorSetCount = 1;
19031 alloc_info.descriptorPool = ds_pool;
19032 alloc_info.pSetLayouts = &ds_layout;
19033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19034 ASSERT_VK_SUCCESS(err);
19035
19036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19038 pipeline_layout_ci.pNext = NULL;
19039 pipeline_layout_ci.setLayoutCount = 1;
19040 pipeline_layout_ci.pSetLayouts = &ds_layout;
19041
19042 VkPipelineLayout pipeline_layout;
19043 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19044 ASSERT_VK_SUCCESS(err);
19045
19046 // Create two buffers to update the descriptors with
19047 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19048 uint32_t qfi = 0;
19049 VkBufferCreateInfo buffCI = {};
19050 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19051 buffCI.size = 2048;
19052 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19053 buffCI.queueFamilyIndexCount = 1;
19054 buffCI.pQueueFamilyIndices = &qfi;
19055
19056 VkBuffer dyub1;
19057 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19058 ASSERT_VK_SUCCESS(err);
19059 // buffer2
19060 buffCI.size = 1024;
19061 VkBuffer dyub2;
19062 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19063 ASSERT_VK_SUCCESS(err);
19064 // Allocate memory and bind to buffers
19065 VkMemoryAllocateInfo mem_alloc[2] = {};
19066 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19067 mem_alloc[0].pNext = NULL;
19068 mem_alloc[0].memoryTypeIndex = 0;
19069 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19070 mem_alloc[1].pNext = NULL;
19071 mem_alloc[1].memoryTypeIndex = 0;
19072
19073 VkMemoryRequirements mem_reqs1;
19074 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19075 VkMemoryRequirements mem_reqs2;
19076 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19077 mem_alloc[0].allocationSize = mem_reqs1.size;
19078 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19079 mem_alloc[1].allocationSize = mem_reqs2.size;
19080 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19081 if (!pass) {
19082 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19083 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19084 return;
19085 }
19086
19087 VkDeviceMemory mem1;
19088 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19089 ASSERT_VK_SUCCESS(err);
19090 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19091 ASSERT_VK_SUCCESS(err);
19092 VkDeviceMemory mem2;
19093 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19094 ASSERT_VK_SUCCESS(err);
19095 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19096 ASSERT_VK_SUCCESS(err);
19097 // Update descriptors
19098 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19099 buff_info[0].buffer = dyub1;
19100 buff_info[0].offset = 0;
19101 buff_info[0].range = 256;
19102 buff_info[1].buffer = dyub1;
19103 buff_info[1].offset = 256;
19104 buff_info[1].range = 512;
19105 buff_info[2].buffer = dyub2;
19106 buff_info[2].offset = 0;
19107 buff_info[2].range = 512;
19108
19109 VkWriteDescriptorSet descriptor_write;
19110 memset(&descriptor_write, 0, sizeof(descriptor_write));
19111 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19112 descriptor_write.dstSet = descriptor_set;
19113 descriptor_write.dstBinding = 0;
19114 descriptor_write.descriptorCount = BINDING_COUNT;
19115 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19116 descriptor_write.pBufferInfo = buff_info;
19117
19118 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19119
Tony Barbour552f6c02016-12-21 14:34:07 -070019120 m_commandBuffer->BeginCommandBuffer();
19121 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019122
19123 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019124 char const *vsSource =
19125 "#version 450\n"
19126 "\n"
19127 "out gl_PerVertex { \n"
19128 " vec4 gl_Position;\n"
19129 "};\n"
19130 "void main(){\n"
19131 " gl_Position = vec4(1);\n"
19132 "}\n";
19133 char const *fsSource =
19134 "#version 450\n"
19135 "\n"
19136 "layout(location=0) out vec4 x;\n"
19137 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19138 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19139 "void main(){\n"
19140 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19141 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19143 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19144 VkPipelineObj pipe(m_device);
19145 pipe.SetViewport(m_viewports);
19146 pipe.SetScissor(m_scissors);
19147 pipe.AddShader(&vs);
19148 pipe.AddShader(&fs);
19149 pipe.AddColorAttachment();
19150 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19151
19152 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19153 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19154 // we used to have a bug in this case.
19155 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19156 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19157 &descriptor_set, BINDING_COUNT, dyn_off);
19158 Draw(1, 0, 0, 0);
19159 m_errorMonitor->VerifyNotFound();
19160
19161 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19162 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19163 vkFreeMemory(m_device->device(), mem1, NULL);
19164 vkFreeMemory(m_device->device(), mem2, NULL);
19165
19166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19168 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19169}
19170
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019171TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019172 TEST_DESCRIPTION(
19173 "Ensure that validations handling of non-coherent memory "
19174 "mapping while using VK_WHOLE_SIZE does not cause access "
19175 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019176 VkResult err;
19177 uint8_t *pData;
19178 ASSERT_NO_FATAL_FAILURE(InitState());
19179
19180 VkDeviceMemory mem;
19181 VkMemoryRequirements mem_reqs;
19182 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019183 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019184 VkMemoryAllocateInfo alloc_info = {};
19185 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19186 alloc_info.pNext = NULL;
19187 alloc_info.memoryTypeIndex = 0;
19188
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019189 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019190 alloc_info.allocationSize = allocation_size;
19191
19192 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19193 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 -070019194 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019195 if (!pass) {
19196 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019197 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19198 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019199 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019200 pass = m_device->phy().set_memory_type(
19201 mem_reqs.memoryTypeBits, &alloc_info,
19202 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19203 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019204 if (!pass) {
19205 return;
19206 }
19207 }
19208 }
19209
19210 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19211 ASSERT_VK_SUCCESS(err);
19212
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019213 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019214 m_errorMonitor->ExpectSuccess();
19215 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19216 ASSERT_VK_SUCCESS(err);
19217 VkMappedMemoryRange mmr = {};
19218 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19219 mmr.memory = mem;
19220 mmr.offset = 0;
19221 mmr.size = VK_WHOLE_SIZE;
19222 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19223 ASSERT_VK_SUCCESS(err);
19224 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19225 ASSERT_VK_SUCCESS(err);
19226 m_errorMonitor->VerifyNotFound();
19227 vkUnmapMemory(m_device->device(), mem);
19228
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019229 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019230 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019231 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019232 ASSERT_VK_SUCCESS(err);
19233 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19234 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019235 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019236 mmr.size = VK_WHOLE_SIZE;
19237 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19238 ASSERT_VK_SUCCESS(err);
19239 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19240 ASSERT_VK_SUCCESS(err);
19241 m_errorMonitor->VerifyNotFound();
19242 vkUnmapMemory(m_device->device(), mem);
19243
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019244 // Map with offset and size
19245 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019246 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019247 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019248 ASSERT_VK_SUCCESS(err);
19249 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19250 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019251 mmr.offset = 4 * atom_size;
19252 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019253 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19254 ASSERT_VK_SUCCESS(err);
19255 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19256 ASSERT_VK_SUCCESS(err);
19257 m_errorMonitor->VerifyNotFound();
19258 vkUnmapMemory(m_device->device(), mem);
19259
19260 // Map without offset and flush WHOLE_SIZE with two separate offsets
19261 m_errorMonitor->ExpectSuccess();
19262 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19263 ASSERT_VK_SUCCESS(err);
19264 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19265 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019266 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019267 mmr.size = VK_WHOLE_SIZE;
19268 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19269 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019270 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019271 mmr.size = VK_WHOLE_SIZE;
19272 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19273 ASSERT_VK_SUCCESS(err);
19274 m_errorMonitor->VerifyNotFound();
19275 vkUnmapMemory(m_device->device(), mem);
19276
19277 vkFreeMemory(m_device->device(), mem, NULL);
19278}
19279
19280// This is a positive test. We used to expect error in this case but spec now allows it
19281TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19282 m_errorMonitor->ExpectSuccess();
19283 vk_testing::Fence testFence;
19284 VkFenceCreateInfo fenceInfo = {};
19285 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19286 fenceInfo.pNext = NULL;
19287
19288 ASSERT_NO_FATAL_FAILURE(InitState());
19289 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019290 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019291 VkResult result = vkResetFences(m_device->device(), 1, fences);
19292 ASSERT_VK_SUCCESS(result);
19293
19294 m_errorMonitor->VerifyNotFound();
19295}
19296
19297TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19298 m_errorMonitor->ExpectSuccess();
19299
19300 ASSERT_NO_FATAL_FAILURE(InitState());
19301 VkResult err;
19302
19303 // Record (empty!) command buffer that can be submitted multiple times
19304 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019305 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19306 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019307 m_commandBuffer->BeginCommandBuffer(&cbbi);
19308 m_commandBuffer->EndCommandBuffer();
19309
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019310 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019311 VkFence fence;
19312 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19313 ASSERT_VK_SUCCESS(err);
19314
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019315 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019316 VkSemaphore s1, s2;
19317 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19318 ASSERT_VK_SUCCESS(err);
19319 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19320 ASSERT_VK_SUCCESS(err);
19321
19322 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019323 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019324 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19325 ASSERT_VK_SUCCESS(err);
19326
19327 // Submit CB again, signaling s2.
19328 si.pSignalSemaphores = &s2;
19329 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19330 ASSERT_VK_SUCCESS(err);
19331
19332 // Wait for fence.
19333 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19334 ASSERT_VK_SUCCESS(err);
19335
19336 // CB is still in flight from second submission, but semaphore s1 is no
19337 // longer in flight. delete it.
19338 vkDestroySemaphore(m_device->device(), s1, nullptr);
19339
19340 m_errorMonitor->VerifyNotFound();
19341
19342 // Force device idle and clean up remaining objects
19343 vkDeviceWaitIdle(m_device->device());
19344 vkDestroySemaphore(m_device->device(), s2, nullptr);
19345 vkDestroyFence(m_device->device(), fence, nullptr);
19346}
19347
19348TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19349 m_errorMonitor->ExpectSuccess();
19350
19351 ASSERT_NO_FATAL_FAILURE(InitState());
19352 VkResult err;
19353
19354 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019355 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019356 VkFence f1;
19357 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19358 ASSERT_VK_SUCCESS(err);
19359
19360 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019361 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362 VkFence f2;
19363 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19364 ASSERT_VK_SUCCESS(err);
19365
19366 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019367 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019368 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19369
19370 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019371 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019372 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19373
19374 // Should have both retired!
19375 vkDestroyFence(m_device->device(), f1, nullptr);
19376 vkDestroyFence(m_device->device(), f2, nullptr);
19377
19378 m_errorMonitor->VerifyNotFound();
19379}
19380
19381TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019382 TEST_DESCRIPTION(
19383 "Verify that creating an image view from an image with valid usage "
19384 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385
19386 ASSERT_NO_FATAL_FAILURE(InitState());
19387
19388 m_errorMonitor->ExpectSuccess();
19389 // Verify that we can create a view with usage INPUT_ATTACHMENT
19390 VkImageObj image(m_device);
19391 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19392 ASSERT_TRUE(image.initialized());
19393 VkImageView imageView;
19394 VkImageViewCreateInfo ivci = {};
19395 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19396 ivci.image = image.handle();
19397 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19398 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19399 ivci.subresourceRange.layerCount = 1;
19400 ivci.subresourceRange.baseMipLevel = 0;
19401 ivci.subresourceRange.levelCount = 1;
19402 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19403
19404 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19405 m_errorMonitor->VerifyNotFound();
19406 vkDestroyImageView(m_device->device(), imageView, NULL);
19407}
19408
19409// This is a positive test. No failures are expected.
19410TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019411 TEST_DESCRIPTION(
19412 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19413 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019414
19415 ASSERT_NO_FATAL_FAILURE(InitState());
19416
19417 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019418 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019419
19420 m_errorMonitor->ExpectSuccess();
19421
19422 VkImage image;
19423 VkImageCreateInfo image_create_info = {};
19424 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19425 image_create_info.pNext = NULL;
19426 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19427 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19428 image_create_info.extent.width = 64;
19429 image_create_info.extent.height = 64;
19430 image_create_info.extent.depth = 1;
19431 image_create_info.mipLevels = 1;
19432 image_create_info.arrayLayers = 1;
19433 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19434 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19435 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19436 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19437 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19438 ASSERT_VK_SUCCESS(err);
19439
19440 VkMemoryRequirements memory_reqs;
19441 VkDeviceMemory memory_one, memory_two;
19442 bool pass;
19443 VkMemoryAllocateInfo memory_info = {};
19444 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19445 memory_info.pNext = NULL;
19446 memory_info.allocationSize = 0;
19447 memory_info.memoryTypeIndex = 0;
19448 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19449 // Find an image big enough to allow sparse mapping of 2 memory regions
19450 // Increase the image size until it is at least twice the
19451 // size of the required alignment, to ensure we can bind both
19452 // allocated memory blocks to the image on aligned offsets.
19453 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19454 vkDestroyImage(m_device->device(), image, nullptr);
19455 image_create_info.extent.width *= 2;
19456 image_create_info.extent.height *= 2;
19457 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19458 ASSERT_VK_SUCCESS(err);
19459 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19460 }
19461 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19462 // at the end of the first
19463 memory_info.allocationSize = memory_reqs.alignment;
19464 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19465 ASSERT_TRUE(pass);
19466 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19467 ASSERT_VK_SUCCESS(err);
19468 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19469 ASSERT_VK_SUCCESS(err);
19470 VkSparseMemoryBind binds[2];
19471 binds[0].flags = 0;
19472 binds[0].memory = memory_one;
19473 binds[0].memoryOffset = 0;
19474 binds[0].resourceOffset = 0;
19475 binds[0].size = memory_info.allocationSize;
19476 binds[1].flags = 0;
19477 binds[1].memory = memory_two;
19478 binds[1].memoryOffset = 0;
19479 binds[1].resourceOffset = memory_info.allocationSize;
19480 binds[1].size = memory_info.allocationSize;
19481
19482 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19483 opaqueBindInfo.image = image;
19484 opaqueBindInfo.bindCount = 2;
19485 opaqueBindInfo.pBinds = binds;
19486
19487 VkFence fence = VK_NULL_HANDLE;
19488 VkBindSparseInfo bindSparseInfo = {};
19489 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19490 bindSparseInfo.imageOpaqueBindCount = 1;
19491 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19492
19493 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19494 vkQueueWaitIdle(m_device->m_queue);
19495 vkDestroyImage(m_device->device(), image, NULL);
19496 vkFreeMemory(m_device->device(), memory_one, NULL);
19497 vkFreeMemory(m_device->device(), memory_two, NULL);
19498 m_errorMonitor->VerifyNotFound();
19499}
19500
19501TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019502 TEST_DESCRIPTION(
19503 "Ensure that CmdBeginRenderPass with an attachment's "
19504 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19505 "the command buffer has prior knowledge of that "
19506 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019507
19508 m_errorMonitor->ExpectSuccess();
19509
19510 ASSERT_NO_FATAL_FAILURE(InitState());
19511
19512 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019513 VkAttachmentDescription attachment = {0,
19514 VK_FORMAT_R8G8B8A8_UNORM,
19515 VK_SAMPLE_COUNT_1_BIT,
19516 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19517 VK_ATTACHMENT_STORE_OP_STORE,
19518 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19519 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19520 VK_IMAGE_LAYOUT_UNDEFINED,
19521 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019522
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019523 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019524
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019525 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019526
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019527 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019528
19529 VkRenderPass rp;
19530 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19531 ASSERT_VK_SUCCESS(err);
19532
19533 // A compatible framebuffer.
19534 VkImageObj image(m_device);
19535 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19536 ASSERT_TRUE(image.initialized());
19537
19538 VkImageViewCreateInfo ivci = {
19539 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19540 nullptr,
19541 0,
19542 image.handle(),
19543 VK_IMAGE_VIEW_TYPE_2D,
19544 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019545 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19546 VK_COMPONENT_SWIZZLE_IDENTITY},
19547 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019548 };
19549 VkImageView view;
19550 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19551 ASSERT_VK_SUCCESS(err);
19552
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019553 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019554 VkFramebuffer fb;
19555 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19556 ASSERT_VK_SUCCESS(err);
19557
19558 // Record a single command buffer which uses this renderpass twice. The
19559 // bug is triggered at the beginning of the second renderpass, when the
19560 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019561 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 -070019562 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019563 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19564 vkCmdEndRenderPass(m_commandBuffer->handle());
19565 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19566
19567 m_errorMonitor->VerifyNotFound();
19568
19569 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019570 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019571
19572 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19573 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19574 vkDestroyImageView(m_device->device(), view, nullptr);
19575}
19576
19577TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019578 TEST_DESCRIPTION(
19579 "This test should pass. Create a Framebuffer and "
19580 "command buffer, bind them together, then destroy "
19581 "command pool and framebuffer and verify there are no "
19582 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019583
19584 m_errorMonitor->ExpectSuccess();
19585
19586 ASSERT_NO_FATAL_FAILURE(InitState());
19587
19588 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019589 VkAttachmentDescription attachment = {0,
19590 VK_FORMAT_R8G8B8A8_UNORM,
19591 VK_SAMPLE_COUNT_1_BIT,
19592 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19593 VK_ATTACHMENT_STORE_OP_STORE,
19594 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19595 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19596 VK_IMAGE_LAYOUT_UNDEFINED,
19597 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019598
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019599 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019600
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019601 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019602
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019603 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019604
19605 VkRenderPass rp;
19606 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19607 ASSERT_VK_SUCCESS(err);
19608
19609 // A compatible framebuffer.
19610 VkImageObj image(m_device);
19611 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19612 ASSERT_TRUE(image.initialized());
19613
19614 VkImageViewCreateInfo ivci = {
19615 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19616 nullptr,
19617 0,
19618 image.handle(),
19619 VK_IMAGE_VIEW_TYPE_2D,
19620 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019621 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19622 VK_COMPONENT_SWIZZLE_IDENTITY},
19623 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019624 };
19625 VkImageView view;
19626 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19627 ASSERT_VK_SUCCESS(err);
19628
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019629 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019630 VkFramebuffer fb;
19631 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19632 ASSERT_VK_SUCCESS(err);
19633
19634 // Explicitly create a command buffer to bind the FB to so that we can then
19635 // destroy the command pool in order to implicitly free command buffer
19636 VkCommandPool command_pool;
19637 VkCommandPoolCreateInfo pool_create_info{};
19638 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19639 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19640 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19641 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19642
19643 VkCommandBuffer command_buffer;
19644 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19645 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19646 command_buffer_allocate_info.commandPool = command_pool;
19647 command_buffer_allocate_info.commandBufferCount = 1;
19648 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19649 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19650
19651 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019652 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 -060019653 VkCommandBufferBeginInfo begin_info{};
19654 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19655 vkBeginCommandBuffer(command_buffer, &begin_info);
19656
19657 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19658 vkCmdEndRenderPass(command_buffer);
19659 vkEndCommandBuffer(command_buffer);
19660 vkDestroyImageView(m_device->device(), view, nullptr);
19661 // Destroy command pool to implicitly free command buffer
19662 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19663 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19664 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19665 m_errorMonitor->VerifyNotFound();
19666}
19667
19668TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019669 TEST_DESCRIPTION(
19670 "Ensure that CmdBeginRenderPass applies the layout "
19671 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019672
19673 m_errorMonitor->ExpectSuccess();
19674
19675 ASSERT_NO_FATAL_FAILURE(InitState());
19676
19677 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019678 VkAttachmentDescription attachment = {0,
19679 VK_FORMAT_R8G8B8A8_UNORM,
19680 VK_SAMPLE_COUNT_1_BIT,
19681 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19682 VK_ATTACHMENT_STORE_OP_STORE,
19683 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19684 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19685 VK_IMAGE_LAYOUT_UNDEFINED,
19686 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019687
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019688 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019689
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019690 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019691
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019692 VkSubpassDependency dep = {0,
19693 0,
19694 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19695 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19696 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19697 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19698 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019699
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019700 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019701
19702 VkResult err;
19703 VkRenderPass rp;
19704 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19705 ASSERT_VK_SUCCESS(err);
19706
19707 // A compatible framebuffer.
19708 VkImageObj image(m_device);
19709 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19710 ASSERT_TRUE(image.initialized());
19711
19712 VkImageViewCreateInfo ivci = {
19713 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19714 nullptr,
19715 0,
19716 image.handle(),
19717 VK_IMAGE_VIEW_TYPE_2D,
19718 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019719 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19720 VK_COMPONENT_SWIZZLE_IDENTITY},
19721 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019722 };
19723 VkImageView view;
19724 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19725 ASSERT_VK_SUCCESS(err);
19726
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019727 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019728 VkFramebuffer fb;
19729 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19730 ASSERT_VK_SUCCESS(err);
19731
19732 // Record a single command buffer which issues a pipeline barrier w/
19733 // image memory barrier for the attachment. This detects the previously
19734 // missing tracking of the subpass layout by throwing a validation error
19735 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019736 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 -070019737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019738 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19739
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019740 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19741 nullptr,
19742 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19743 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19744 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19745 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19746 VK_QUEUE_FAMILY_IGNORED,
19747 VK_QUEUE_FAMILY_IGNORED,
19748 image.handle(),
19749 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019750 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019751 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19752 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019753
19754 vkCmdEndRenderPass(m_commandBuffer->handle());
19755 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019756 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019757
19758 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19759 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19760 vkDestroyImageView(m_device->device(), view, nullptr);
19761}
19762
19763TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019764 TEST_DESCRIPTION(
19765 "Validate that when an imageView of a depth/stencil image "
19766 "is used as a depth/stencil framebuffer attachment, the "
19767 "aspectMask is ignored and both depth and stencil image "
19768 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769
19770 VkFormatProperties format_properties;
19771 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19772 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19773 return;
19774 }
19775
19776 m_errorMonitor->ExpectSuccess();
19777
19778 ASSERT_NO_FATAL_FAILURE(InitState());
19779
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019780 VkAttachmentDescription attachment = {0,
19781 VK_FORMAT_D32_SFLOAT_S8_UINT,
19782 VK_SAMPLE_COUNT_1_BIT,
19783 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19784 VK_ATTACHMENT_STORE_OP_STORE,
19785 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19786 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19787 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19788 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019789
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019790 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019791
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019792 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019793
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019794 VkSubpassDependency dep = {0,
19795 0,
19796 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19797 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19798 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19799 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19800 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019801
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019802 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019803
19804 VkResult err;
19805 VkRenderPass rp;
19806 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19807 ASSERT_VK_SUCCESS(err);
19808
19809 VkImageObj image(m_device);
19810 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019811 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019812 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019813 ASSERT_TRUE(image.initialized());
19814 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19815
19816 VkImageViewCreateInfo ivci = {
19817 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19818 nullptr,
19819 0,
19820 image.handle(),
19821 VK_IMAGE_VIEW_TYPE_2D,
19822 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019823 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19824 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019825 };
19826 VkImageView view;
19827 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19828 ASSERT_VK_SUCCESS(err);
19829
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019830 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019831 VkFramebuffer fb;
19832 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19833 ASSERT_VK_SUCCESS(err);
19834
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019835 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 -070019836 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019837 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19838
19839 VkImageMemoryBarrier imb = {};
19840 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19841 imb.pNext = nullptr;
19842 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19843 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19844 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19845 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19846 imb.srcQueueFamilyIndex = 0;
19847 imb.dstQueueFamilyIndex = 0;
19848 imb.image = image.handle();
19849 imb.subresourceRange.aspectMask = 0x6;
19850 imb.subresourceRange.baseMipLevel = 0;
19851 imb.subresourceRange.levelCount = 0x1;
19852 imb.subresourceRange.baseArrayLayer = 0;
19853 imb.subresourceRange.layerCount = 0x1;
19854
19855 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019856 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19857 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019858
19859 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019860 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019861 QueueCommandBuffer(false);
19862 m_errorMonitor->VerifyNotFound();
19863
19864 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19865 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19866 vkDestroyImageView(m_device->device(), view, nullptr);
19867}
19868
19869TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019870 TEST_DESCRIPTION(
19871 "Ensure that layout transitions work correctly without "
19872 "errors, when an attachment reference is "
19873 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019874
19875 m_errorMonitor->ExpectSuccess();
19876
19877 ASSERT_NO_FATAL_FAILURE(InitState());
19878
19879 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019880 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019881
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019882 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019883
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019884 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019885
19886 VkRenderPass rp;
19887 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19888 ASSERT_VK_SUCCESS(err);
19889
19890 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019891 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019892 VkFramebuffer fb;
19893 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19894 ASSERT_VK_SUCCESS(err);
19895
19896 // Record a command buffer which just begins and ends the renderpass. The
19897 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019898 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 -070019899 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019900 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19901 vkCmdEndRenderPass(m_commandBuffer->handle());
19902 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019903 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019904
19905 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19906 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19907}
19908
19909// This is a positive test. No errors are expected.
19910TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019911 TEST_DESCRIPTION(
19912 "Create a stencil-only attachment with a LOAD_OP set to "
19913 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019914 VkResult result = VK_SUCCESS;
19915 VkImageFormatProperties formatProps;
19916 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019917 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19918 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019919 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19920 return;
19921 }
19922
19923 ASSERT_NO_FATAL_FAILURE(InitState());
19924 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19925 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019926 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019927 VkAttachmentDescription att = {};
19928 VkAttachmentReference ref = {};
19929 att.format = depth_stencil_fmt;
19930 att.samples = VK_SAMPLE_COUNT_1_BIT;
19931 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19932 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19933 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19934 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19935 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19936 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19937
19938 VkClearValue clear;
19939 clear.depthStencil.depth = 1.0;
19940 clear.depthStencil.stencil = 0;
19941 ref.attachment = 0;
19942 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19943
19944 VkSubpassDescription subpass = {};
19945 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19946 subpass.flags = 0;
19947 subpass.inputAttachmentCount = 0;
19948 subpass.pInputAttachments = NULL;
19949 subpass.colorAttachmentCount = 0;
19950 subpass.pColorAttachments = NULL;
19951 subpass.pResolveAttachments = NULL;
19952 subpass.pDepthStencilAttachment = &ref;
19953 subpass.preserveAttachmentCount = 0;
19954 subpass.pPreserveAttachments = NULL;
19955
19956 VkRenderPass rp;
19957 VkRenderPassCreateInfo rp_info = {};
19958 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19959 rp_info.attachmentCount = 1;
19960 rp_info.pAttachments = &att;
19961 rp_info.subpassCount = 1;
19962 rp_info.pSubpasses = &subpass;
19963 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19964 ASSERT_VK_SUCCESS(result);
19965
19966 VkImageView *depthView = m_depthStencil->BindInfo();
19967 VkFramebufferCreateInfo fb_info = {};
19968 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19969 fb_info.pNext = NULL;
19970 fb_info.renderPass = rp;
19971 fb_info.attachmentCount = 1;
19972 fb_info.pAttachments = depthView;
19973 fb_info.width = 100;
19974 fb_info.height = 100;
19975 fb_info.layers = 1;
19976 VkFramebuffer fb;
19977 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19978 ASSERT_VK_SUCCESS(result);
19979
19980 VkRenderPassBeginInfo rpbinfo = {};
19981 rpbinfo.clearValueCount = 1;
19982 rpbinfo.pClearValues = &clear;
19983 rpbinfo.pNext = NULL;
19984 rpbinfo.renderPass = rp;
19985 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19986 rpbinfo.renderArea.extent.width = 100;
19987 rpbinfo.renderArea.extent.height = 100;
19988 rpbinfo.renderArea.offset.x = 0;
19989 rpbinfo.renderArea.offset.y = 0;
19990 rpbinfo.framebuffer = fb;
19991
19992 VkFence fence = {};
19993 VkFenceCreateInfo fence_ci = {};
19994 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19995 fence_ci.pNext = nullptr;
19996 fence_ci.flags = 0;
19997 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19998 ASSERT_VK_SUCCESS(result);
19999
20000 m_commandBuffer->BeginCommandBuffer();
20001 m_commandBuffer->BeginRenderPass(rpbinfo);
20002 m_commandBuffer->EndRenderPass();
20003 m_commandBuffer->EndCommandBuffer();
20004 m_commandBuffer->QueueCommandBuffer(fence);
20005
20006 VkImageObj destImage(m_device);
20007 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 -070020008 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020009 VkImageMemoryBarrier barrier = {};
20010 VkImageSubresourceRange range;
20011 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20012 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20013 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20014 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20015 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20016 barrier.image = m_depthStencil->handle();
20017 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20018 range.baseMipLevel = 0;
20019 range.levelCount = 1;
20020 range.baseArrayLayer = 0;
20021 range.layerCount = 1;
20022 barrier.subresourceRange = range;
20023 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20024 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20025 cmdbuf.BeginCommandBuffer();
20026 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 -070020027 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020028 barrier.srcAccessMask = 0;
20029 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20030 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20031 barrier.image = destImage.handle();
20032 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20033 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 -070020034 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020035 VkImageCopy cregion;
20036 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20037 cregion.srcSubresource.mipLevel = 0;
20038 cregion.srcSubresource.baseArrayLayer = 0;
20039 cregion.srcSubresource.layerCount = 1;
20040 cregion.srcOffset.x = 0;
20041 cregion.srcOffset.y = 0;
20042 cregion.srcOffset.z = 0;
20043 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20044 cregion.dstSubresource.mipLevel = 0;
20045 cregion.dstSubresource.baseArrayLayer = 0;
20046 cregion.dstSubresource.layerCount = 1;
20047 cregion.dstOffset.x = 0;
20048 cregion.dstOffset.y = 0;
20049 cregion.dstOffset.z = 0;
20050 cregion.extent.width = 100;
20051 cregion.extent.height = 100;
20052 cregion.extent.depth = 1;
20053 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020054 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020055 cmdbuf.EndCommandBuffer();
20056
20057 VkSubmitInfo submit_info;
20058 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20059 submit_info.pNext = NULL;
20060 submit_info.waitSemaphoreCount = 0;
20061 submit_info.pWaitSemaphores = NULL;
20062 submit_info.pWaitDstStageMask = NULL;
20063 submit_info.commandBufferCount = 1;
20064 submit_info.pCommandBuffers = &cmdbuf.handle();
20065 submit_info.signalSemaphoreCount = 0;
20066 submit_info.pSignalSemaphores = NULL;
20067
20068 m_errorMonitor->ExpectSuccess();
20069 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20070 m_errorMonitor->VerifyNotFound();
20071
20072 vkQueueWaitIdle(m_device->m_queue);
20073 vkDestroyFence(m_device->device(), fence, nullptr);
20074 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20075 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20076}
20077
20078// This is a positive test. No errors should be generated.
20079TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20080 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20081
20082 m_errorMonitor->ExpectSuccess();
20083 ASSERT_NO_FATAL_FAILURE(InitState());
20084
20085 VkEvent event;
20086 VkEventCreateInfo event_create_info{};
20087 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20088 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20089
20090 VkCommandPool command_pool;
20091 VkCommandPoolCreateInfo pool_create_info{};
20092 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20093 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20094 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20095 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20096
20097 VkCommandBuffer command_buffer;
20098 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20099 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20100 command_buffer_allocate_info.commandPool = command_pool;
20101 command_buffer_allocate_info.commandBufferCount = 1;
20102 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20103 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20104
20105 VkQueue queue = VK_NULL_HANDLE;
20106 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20107
20108 {
20109 VkCommandBufferBeginInfo begin_info{};
20110 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20111 vkBeginCommandBuffer(command_buffer, &begin_info);
20112
20113 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 -070020114 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020115 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20116 vkEndCommandBuffer(command_buffer);
20117 }
20118 {
20119 VkSubmitInfo submit_info{};
20120 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20121 submit_info.commandBufferCount = 1;
20122 submit_info.pCommandBuffers = &command_buffer;
20123 submit_info.signalSemaphoreCount = 0;
20124 submit_info.pSignalSemaphores = nullptr;
20125 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20126 }
20127 { vkSetEvent(m_device->device(), event); }
20128
20129 vkQueueWaitIdle(queue);
20130
20131 vkDestroyEvent(m_device->device(), event, nullptr);
20132 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20133 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20134
20135 m_errorMonitor->VerifyNotFound();
20136}
20137// This is a positive test. No errors should be generated.
20138TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20139 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20140
20141 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020142 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020143
20144 m_errorMonitor->ExpectSuccess();
20145
20146 VkQueryPool query_pool;
20147 VkQueryPoolCreateInfo query_pool_create_info{};
20148 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20149 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20150 query_pool_create_info.queryCount = 1;
20151 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20152
20153 VkCommandPool command_pool;
20154 VkCommandPoolCreateInfo pool_create_info{};
20155 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20156 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20157 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20158 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20159
20160 VkCommandBuffer command_buffer;
20161 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20162 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20163 command_buffer_allocate_info.commandPool = command_pool;
20164 command_buffer_allocate_info.commandBufferCount = 1;
20165 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20166 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20167
20168 VkCommandBuffer secondary_command_buffer;
20169 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20170 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20171
20172 VkQueue queue = VK_NULL_HANDLE;
20173 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20174
20175 uint32_t qfi = 0;
20176 VkBufferCreateInfo buff_create_info = {};
20177 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20178 buff_create_info.size = 1024;
20179 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20180 buff_create_info.queueFamilyIndexCount = 1;
20181 buff_create_info.pQueueFamilyIndices = &qfi;
20182
20183 VkResult err;
20184 VkBuffer buffer;
20185 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20186 ASSERT_VK_SUCCESS(err);
20187 VkMemoryAllocateInfo mem_alloc = {};
20188 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20189 mem_alloc.pNext = NULL;
20190 mem_alloc.allocationSize = 1024;
20191 mem_alloc.memoryTypeIndex = 0;
20192
20193 VkMemoryRequirements memReqs;
20194 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20195 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20196 if (!pass) {
20197 vkDestroyBuffer(m_device->device(), buffer, NULL);
20198 return;
20199 }
20200
20201 VkDeviceMemory mem;
20202 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20203 ASSERT_VK_SUCCESS(err);
20204 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20205 ASSERT_VK_SUCCESS(err);
20206
20207 VkCommandBufferInheritanceInfo hinfo = {};
20208 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20209 hinfo.renderPass = VK_NULL_HANDLE;
20210 hinfo.subpass = 0;
20211 hinfo.framebuffer = VK_NULL_HANDLE;
20212 hinfo.occlusionQueryEnable = VK_FALSE;
20213 hinfo.queryFlags = 0;
20214 hinfo.pipelineStatistics = 0;
20215
20216 {
20217 VkCommandBufferBeginInfo begin_info{};
20218 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20219 begin_info.pInheritanceInfo = &hinfo;
20220 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20221
20222 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20223 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20224
20225 vkEndCommandBuffer(secondary_command_buffer);
20226
20227 begin_info.pInheritanceInfo = nullptr;
20228 vkBeginCommandBuffer(command_buffer, &begin_info);
20229
20230 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20231 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20232
20233 vkEndCommandBuffer(command_buffer);
20234 }
20235 {
20236 VkSubmitInfo submit_info{};
20237 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20238 submit_info.commandBufferCount = 1;
20239 submit_info.pCommandBuffers = &command_buffer;
20240 submit_info.signalSemaphoreCount = 0;
20241 submit_info.pSignalSemaphores = nullptr;
20242 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20243 }
20244
20245 vkQueueWaitIdle(queue);
20246
20247 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20248 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20249 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20250 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20251 vkDestroyBuffer(m_device->device(), buffer, NULL);
20252 vkFreeMemory(m_device->device(), mem, NULL);
20253
20254 m_errorMonitor->VerifyNotFound();
20255}
20256
20257// This is a positive test. No errors should be generated.
20258TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20259 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20260
20261 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020262 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020263
20264 m_errorMonitor->ExpectSuccess();
20265
20266 VkQueryPool query_pool;
20267 VkQueryPoolCreateInfo query_pool_create_info{};
20268 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20269 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20270 query_pool_create_info.queryCount = 1;
20271 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20272
20273 VkCommandPool command_pool;
20274 VkCommandPoolCreateInfo pool_create_info{};
20275 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20276 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20277 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20278 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20279
20280 VkCommandBuffer command_buffer[2];
20281 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20282 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20283 command_buffer_allocate_info.commandPool = command_pool;
20284 command_buffer_allocate_info.commandBufferCount = 2;
20285 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20286 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20287
20288 VkQueue queue = VK_NULL_HANDLE;
20289 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20290
20291 uint32_t qfi = 0;
20292 VkBufferCreateInfo buff_create_info = {};
20293 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20294 buff_create_info.size = 1024;
20295 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20296 buff_create_info.queueFamilyIndexCount = 1;
20297 buff_create_info.pQueueFamilyIndices = &qfi;
20298
20299 VkResult err;
20300 VkBuffer buffer;
20301 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20302 ASSERT_VK_SUCCESS(err);
20303 VkMemoryAllocateInfo mem_alloc = {};
20304 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20305 mem_alloc.pNext = NULL;
20306 mem_alloc.allocationSize = 1024;
20307 mem_alloc.memoryTypeIndex = 0;
20308
20309 VkMemoryRequirements memReqs;
20310 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20311 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20312 if (!pass) {
20313 vkDestroyBuffer(m_device->device(), buffer, NULL);
20314 return;
20315 }
20316
20317 VkDeviceMemory mem;
20318 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20319 ASSERT_VK_SUCCESS(err);
20320 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20321 ASSERT_VK_SUCCESS(err);
20322
20323 {
20324 VkCommandBufferBeginInfo begin_info{};
20325 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20326 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20327
20328 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20329 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20330
20331 vkEndCommandBuffer(command_buffer[0]);
20332
20333 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20334
20335 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20336
20337 vkEndCommandBuffer(command_buffer[1]);
20338 }
20339 {
20340 VkSubmitInfo submit_info{};
20341 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20342 submit_info.commandBufferCount = 2;
20343 submit_info.pCommandBuffers = command_buffer;
20344 submit_info.signalSemaphoreCount = 0;
20345 submit_info.pSignalSemaphores = nullptr;
20346 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20347 }
20348
20349 vkQueueWaitIdle(queue);
20350
20351 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20352 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20353 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20354 vkDestroyBuffer(m_device->device(), buffer, NULL);
20355 vkFreeMemory(m_device->device(), mem, NULL);
20356
20357 m_errorMonitor->VerifyNotFound();
20358}
20359
Tony Barbourc46924f2016-11-04 11:49:52 -060020360TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020361 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20362
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020363 ASSERT_NO_FATAL_FAILURE(InitState());
20364 VkEvent event;
20365 VkEventCreateInfo event_create_info{};
20366 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20367 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20368
20369 VkCommandPool command_pool;
20370 VkCommandPoolCreateInfo pool_create_info{};
20371 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20372 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20373 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20374 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20375
20376 VkCommandBuffer command_buffer;
20377 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20378 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20379 command_buffer_allocate_info.commandPool = command_pool;
20380 command_buffer_allocate_info.commandBufferCount = 1;
20381 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20382 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20383
20384 VkQueue queue = VK_NULL_HANDLE;
20385 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20386
20387 {
20388 VkCommandBufferBeginInfo begin_info{};
20389 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20390 vkBeginCommandBuffer(command_buffer, &begin_info);
20391
20392 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020393 vkEndCommandBuffer(command_buffer);
20394 }
20395 {
20396 VkSubmitInfo submit_info{};
20397 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20398 submit_info.commandBufferCount = 1;
20399 submit_info.pCommandBuffers = &command_buffer;
20400 submit_info.signalSemaphoreCount = 0;
20401 submit_info.pSignalSemaphores = nullptr;
20402 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20403 }
20404 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20406 "that is already in use by a "
20407 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020408 vkSetEvent(m_device->device(), event);
20409 m_errorMonitor->VerifyFound();
20410 }
20411
20412 vkQueueWaitIdle(queue);
20413
20414 vkDestroyEvent(m_device->device(), event, nullptr);
20415 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20416 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20417}
20418
20419// This is a positive test. No errors should be generated.
20420TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020421 TEST_DESCRIPTION(
20422 "Two command buffers with two separate fences are each "
20423 "run through a Submit & WaitForFences cycle 3 times. This "
20424 "previously revealed a bug so running this positive test "
20425 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020426 m_errorMonitor->ExpectSuccess();
20427
20428 ASSERT_NO_FATAL_FAILURE(InitState());
20429 VkQueue queue = VK_NULL_HANDLE;
20430 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20431
20432 static const uint32_t NUM_OBJECTS = 2;
20433 static const uint32_t NUM_FRAMES = 3;
20434 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20435 VkFence fences[NUM_OBJECTS] = {};
20436
20437 VkCommandPool cmd_pool;
20438 VkCommandPoolCreateInfo cmd_pool_ci = {};
20439 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20440 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20441 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20442 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20443 ASSERT_VK_SUCCESS(err);
20444
20445 VkCommandBufferAllocateInfo cmd_buf_info = {};
20446 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20447 cmd_buf_info.commandPool = cmd_pool;
20448 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20449 cmd_buf_info.commandBufferCount = 1;
20450
20451 VkFenceCreateInfo fence_ci = {};
20452 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20453 fence_ci.pNext = nullptr;
20454 fence_ci.flags = 0;
20455
20456 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20457 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20458 ASSERT_VK_SUCCESS(err);
20459 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20460 ASSERT_VK_SUCCESS(err);
20461 }
20462
20463 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20464 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20465 // Create empty cmd buffer
20466 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20467 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20468
20469 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20470 ASSERT_VK_SUCCESS(err);
20471 err = vkEndCommandBuffer(cmd_buffers[obj]);
20472 ASSERT_VK_SUCCESS(err);
20473
20474 VkSubmitInfo submit_info = {};
20475 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20476 submit_info.commandBufferCount = 1;
20477 submit_info.pCommandBuffers = &cmd_buffers[obj];
20478 // Submit cmd buffer and wait for fence
20479 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20480 ASSERT_VK_SUCCESS(err);
20481 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20482 ASSERT_VK_SUCCESS(err);
20483 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20484 ASSERT_VK_SUCCESS(err);
20485 }
20486 }
20487 m_errorMonitor->VerifyNotFound();
20488 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20489 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20490 vkDestroyFence(m_device->device(), fences[i], nullptr);
20491 }
20492}
20493// This is a positive test. No errors should be generated.
20494TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020495 TEST_DESCRIPTION(
20496 "Two command buffers, each in a separate QueueSubmit call "
20497 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020498
20499 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020500 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020501
20502 m_errorMonitor->ExpectSuccess();
20503
20504 VkSemaphore semaphore;
20505 VkSemaphoreCreateInfo semaphore_create_info{};
20506 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20507 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20508
20509 VkCommandPool command_pool;
20510 VkCommandPoolCreateInfo pool_create_info{};
20511 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20512 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20513 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20514 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20515
20516 VkCommandBuffer command_buffer[2];
20517 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20518 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20519 command_buffer_allocate_info.commandPool = command_pool;
20520 command_buffer_allocate_info.commandBufferCount = 2;
20521 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20522 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20523
20524 VkQueue queue = VK_NULL_HANDLE;
20525 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20526
20527 {
20528 VkCommandBufferBeginInfo begin_info{};
20529 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20530 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20531
20532 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 -070020533 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020534
20535 VkViewport viewport{};
20536 viewport.maxDepth = 1.0f;
20537 viewport.minDepth = 0.0f;
20538 viewport.width = 512;
20539 viewport.height = 512;
20540 viewport.x = 0;
20541 viewport.y = 0;
20542 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20543 vkEndCommandBuffer(command_buffer[0]);
20544 }
20545 {
20546 VkCommandBufferBeginInfo begin_info{};
20547 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20548 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20549
20550 VkViewport viewport{};
20551 viewport.maxDepth = 1.0f;
20552 viewport.minDepth = 0.0f;
20553 viewport.width = 512;
20554 viewport.height = 512;
20555 viewport.x = 0;
20556 viewport.y = 0;
20557 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20558 vkEndCommandBuffer(command_buffer[1]);
20559 }
20560 {
20561 VkSubmitInfo submit_info{};
20562 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20563 submit_info.commandBufferCount = 1;
20564 submit_info.pCommandBuffers = &command_buffer[0];
20565 submit_info.signalSemaphoreCount = 1;
20566 submit_info.pSignalSemaphores = &semaphore;
20567 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20568 }
20569 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020570 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020571 VkSubmitInfo submit_info{};
20572 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20573 submit_info.commandBufferCount = 1;
20574 submit_info.pCommandBuffers = &command_buffer[1];
20575 submit_info.waitSemaphoreCount = 1;
20576 submit_info.pWaitSemaphores = &semaphore;
20577 submit_info.pWaitDstStageMask = flags;
20578 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20579 }
20580
20581 vkQueueWaitIdle(m_device->m_queue);
20582
20583 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20584 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20585 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20586
20587 m_errorMonitor->VerifyNotFound();
20588}
20589
20590// This is a positive test. No errors should be generated.
20591TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020592 TEST_DESCRIPTION(
20593 "Two command buffers, each in a separate QueueSubmit call "
20594 "submitted on separate queues, the second having a fence"
20595 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020596
20597 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020598 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020599
20600 m_errorMonitor->ExpectSuccess();
20601
20602 VkFence fence;
20603 VkFenceCreateInfo fence_create_info{};
20604 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20605 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20606
20607 VkSemaphore semaphore;
20608 VkSemaphoreCreateInfo semaphore_create_info{};
20609 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20610 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20611
20612 VkCommandPool command_pool;
20613 VkCommandPoolCreateInfo pool_create_info{};
20614 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20615 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20616 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20617 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20618
20619 VkCommandBuffer command_buffer[2];
20620 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20621 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20622 command_buffer_allocate_info.commandPool = command_pool;
20623 command_buffer_allocate_info.commandBufferCount = 2;
20624 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20625 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20626
20627 VkQueue queue = VK_NULL_HANDLE;
20628 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20629
20630 {
20631 VkCommandBufferBeginInfo begin_info{};
20632 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20633 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20634
20635 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 -070020636 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020637
20638 VkViewport viewport{};
20639 viewport.maxDepth = 1.0f;
20640 viewport.minDepth = 0.0f;
20641 viewport.width = 512;
20642 viewport.height = 512;
20643 viewport.x = 0;
20644 viewport.y = 0;
20645 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20646 vkEndCommandBuffer(command_buffer[0]);
20647 }
20648 {
20649 VkCommandBufferBeginInfo begin_info{};
20650 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20651 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20652
20653 VkViewport viewport{};
20654 viewport.maxDepth = 1.0f;
20655 viewport.minDepth = 0.0f;
20656 viewport.width = 512;
20657 viewport.height = 512;
20658 viewport.x = 0;
20659 viewport.y = 0;
20660 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20661 vkEndCommandBuffer(command_buffer[1]);
20662 }
20663 {
20664 VkSubmitInfo submit_info{};
20665 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20666 submit_info.commandBufferCount = 1;
20667 submit_info.pCommandBuffers = &command_buffer[0];
20668 submit_info.signalSemaphoreCount = 1;
20669 submit_info.pSignalSemaphores = &semaphore;
20670 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20671 }
20672 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020673 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020674 VkSubmitInfo submit_info{};
20675 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20676 submit_info.commandBufferCount = 1;
20677 submit_info.pCommandBuffers = &command_buffer[1];
20678 submit_info.waitSemaphoreCount = 1;
20679 submit_info.pWaitSemaphores = &semaphore;
20680 submit_info.pWaitDstStageMask = flags;
20681 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20682 }
20683
20684 vkQueueWaitIdle(m_device->m_queue);
20685
20686 vkDestroyFence(m_device->device(), fence, nullptr);
20687 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20688 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20689 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20690
20691 m_errorMonitor->VerifyNotFound();
20692}
20693
20694// This is a positive test. No errors should be generated.
20695TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020696 TEST_DESCRIPTION(
20697 "Two command buffers, each in a separate QueueSubmit call "
20698 "submitted on separate queues, the second having a fence"
20699 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020700
20701 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020702 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020703
20704 m_errorMonitor->ExpectSuccess();
20705
20706 VkFence fence;
20707 VkFenceCreateInfo fence_create_info{};
20708 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20709 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20710
20711 VkSemaphore semaphore;
20712 VkSemaphoreCreateInfo semaphore_create_info{};
20713 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20714 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20715
20716 VkCommandPool command_pool;
20717 VkCommandPoolCreateInfo pool_create_info{};
20718 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20719 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20720 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20721 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20722
20723 VkCommandBuffer command_buffer[2];
20724 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20725 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20726 command_buffer_allocate_info.commandPool = command_pool;
20727 command_buffer_allocate_info.commandBufferCount = 2;
20728 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20729 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20730
20731 VkQueue queue = VK_NULL_HANDLE;
20732 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20733
20734 {
20735 VkCommandBufferBeginInfo begin_info{};
20736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20737 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20738
20739 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 -070020740 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020741
20742 VkViewport viewport{};
20743 viewport.maxDepth = 1.0f;
20744 viewport.minDepth = 0.0f;
20745 viewport.width = 512;
20746 viewport.height = 512;
20747 viewport.x = 0;
20748 viewport.y = 0;
20749 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20750 vkEndCommandBuffer(command_buffer[0]);
20751 }
20752 {
20753 VkCommandBufferBeginInfo begin_info{};
20754 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20755 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20756
20757 VkViewport viewport{};
20758 viewport.maxDepth = 1.0f;
20759 viewport.minDepth = 0.0f;
20760 viewport.width = 512;
20761 viewport.height = 512;
20762 viewport.x = 0;
20763 viewport.y = 0;
20764 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20765 vkEndCommandBuffer(command_buffer[1]);
20766 }
20767 {
20768 VkSubmitInfo submit_info{};
20769 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20770 submit_info.commandBufferCount = 1;
20771 submit_info.pCommandBuffers = &command_buffer[0];
20772 submit_info.signalSemaphoreCount = 1;
20773 submit_info.pSignalSemaphores = &semaphore;
20774 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20775 }
20776 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020777 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020778 VkSubmitInfo submit_info{};
20779 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20780 submit_info.commandBufferCount = 1;
20781 submit_info.pCommandBuffers = &command_buffer[1];
20782 submit_info.waitSemaphoreCount = 1;
20783 submit_info.pWaitSemaphores = &semaphore;
20784 submit_info.pWaitDstStageMask = flags;
20785 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20786 }
20787
20788 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20789 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20790
20791 vkDestroyFence(m_device->device(), fence, nullptr);
20792 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20793 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20794 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20795
20796 m_errorMonitor->VerifyNotFound();
20797}
20798
20799TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020800 ASSERT_NO_FATAL_FAILURE(InitState());
20801 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020802 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020803 return;
20804 }
20805
20806 VkResult err;
20807
20808 m_errorMonitor->ExpectSuccess();
20809
20810 VkQueue q0 = m_device->m_queue;
20811 VkQueue q1 = nullptr;
20812 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20813 ASSERT_NE(q1, nullptr);
20814
20815 // An (empty) command buffer. We must have work in the first submission --
20816 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020817 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020818 VkCommandPool pool;
20819 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20820 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020821 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20822 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020823 VkCommandBuffer cb;
20824 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20825 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020826 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020827 err = vkBeginCommandBuffer(cb, &cbbi);
20828 ASSERT_VK_SUCCESS(err);
20829 err = vkEndCommandBuffer(cb);
20830 ASSERT_VK_SUCCESS(err);
20831
20832 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020833 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020834 VkSemaphore s;
20835 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20836 ASSERT_VK_SUCCESS(err);
20837
20838 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020839 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020840
20841 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20842 ASSERT_VK_SUCCESS(err);
20843
20844 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020845 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020846 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020847
20848 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20849 ASSERT_VK_SUCCESS(err);
20850
20851 // Wait for q0 idle
20852 err = vkQueueWaitIdle(q0);
20853 ASSERT_VK_SUCCESS(err);
20854
20855 // Command buffer should have been completed (it was on q0); reset the pool.
20856 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20857
20858 m_errorMonitor->VerifyNotFound();
20859
20860 // Force device completely idle and clean up resources
20861 vkDeviceWaitIdle(m_device->device());
20862 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20863 vkDestroySemaphore(m_device->device(), s, nullptr);
20864}
20865
20866// This is a positive test. No errors should be generated.
20867TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020868 TEST_DESCRIPTION(
20869 "Two command buffers, each in a separate QueueSubmit call "
20870 "submitted on separate queues, the second having a fence, "
20871 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020872
20873 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020874 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020875
20876 m_errorMonitor->ExpectSuccess();
20877
20878 ASSERT_NO_FATAL_FAILURE(InitState());
20879 VkFence fence;
20880 VkFenceCreateInfo fence_create_info{};
20881 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20882 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20883
20884 VkSemaphore semaphore;
20885 VkSemaphoreCreateInfo semaphore_create_info{};
20886 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20887 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20888
20889 VkCommandPool command_pool;
20890 VkCommandPoolCreateInfo pool_create_info{};
20891 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20892 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20893 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20894 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20895
20896 VkCommandBuffer command_buffer[2];
20897 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20898 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20899 command_buffer_allocate_info.commandPool = command_pool;
20900 command_buffer_allocate_info.commandBufferCount = 2;
20901 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20902 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20903
20904 VkQueue queue = VK_NULL_HANDLE;
20905 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20906
20907 {
20908 VkCommandBufferBeginInfo begin_info{};
20909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20910 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20911
20912 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 -070020913 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020914
20915 VkViewport viewport{};
20916 viewport.maxDepth = 1.0f;
20917 viewport.minDepth = 0.0f;
20918 viewport.width = 512;
20919 viewport.height = 512;
20920 viewport.x = 0;
20921 viewport.y = 0;
20922 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20923 vkEndCommandBuffer(command_buffer[0]);
20924 }
20925 {
20926 VkCommandBufferBeginInfo begin_info{};
20927 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20928 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20929
20930 VkViewport viewport{};
20931 viewport.maxDepth = 1.0f;
20932 viewport.minDepth = 0.0f;
20933 viewport.width = 512;
20934 viewport.height = 512;
20935 viewport.x = 0;
20936 viewport.y = 0;
20937 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20938 vkEndCommandBuffer(command_buffer[1]);
20939 }
20940 {
20941 VkSubmitInfo submit_info{};
20942 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20943 submit_info.commandBufferCount = 1;
20944 submit_info.pCommandBuffers = &command_buffer[0];
20945 submit_info.signalSemaphoreCount = 1;
20946 submit_info.pSignalSemaphores = &semaphore;
20947 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20948 }
20949 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020950 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020951 VkSubmitInfo submit_info{};
20952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20953 submit_info.commandBufferCount = 1;
20954 submit_info.pCommandBuffers = &command_buffer[1];
20955 submit_info.waitSemaphoreCount = 1;
20956 submit_info.pWaitSemaphores = &semaphore;
20957 submit_info.pWaitDstStageMask = flags;
20958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20959 }
20960
20961 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20962
20963 vkDestroyFence(m_device->device(), fence, nullptr);
20964 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20965 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20966 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20967
20968 m_errorMonitor->VerifyNotFound();
20969}
20970
20971// This is a positive test. No errors should be generated.
20972TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020973 TEST_DESCRIPTION(
20974 "Two command buffers, each in a separate QueueSubmit call "
20975 "on the same queue, sharing a signal/wait semaphore, the "
20976 "second having a fence, "
20977 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020978
20979 m_errorMonitor->ExpectSuccess();
20980
20981 ASSERT_NO_FATAL_FAILURE(InitState());
20982 VkFence fence;
20983 VkFenceCreateInfo fence_create_info{};
20984 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20985 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20986
20987 VkSemaphore semaphore;
20988 VkSemaphoreCreateInfo semaphore_create_info{};
20989 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20990 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20991
20992 VkCommandPool command_pool;
20993 VkCommandPoolCreateInfo pool_create_info{};
20994 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20995 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20996 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20997 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20998
20999 VkCommandBuffer command_buffer[2];
21000 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21001 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21002 command_buffer_allocate_info.commandPool = command_pool;
21003 command_buffer_allocate_info.commandBufferCount = 2;
21004 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21005 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21006
21007 {
21008 VkCommandBufferBeginInfo begin_info{};
21009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21010 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21011
21012 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 -070021013 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021014
21015 VkViewport viewport{};
21016 viewport.maxDepth = 1.0f;
21017 viewport.minDepth = 0.0f;
21018 viewport.width = 512;
21019 viewport.height = 512;
21020 viewport.x = 0;
21021 viewport.y = 0;
21022 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21023 vkEndCommandBuffer(command_buffer[0]);
21024 }
21025 {
21026 VkCommandBufferBeginInfo begin_info{};
21027 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21028 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21029
21030 VkViewport viewport{};
21031 viewport.maxDepth = 1.0f;
21032 viewport.minDepth = 0.0f;
21033 viewport.width = 512;
21034 viewport.height = 512;
21035 viewport.x = 0;
21036 viewport.y = 0;
21037 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21038 vkEndCommandBuffer(command_buffer[1]);
21039 }
21040 {
21041 VkSubmitInfo submit_info{};
21042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21043 submit_info.commandBufferCount = 1;
21044 submit_info.pCommandBuffers = &command_buffer[0];
21045 submit_info.signalSemaphoreCount = 1;
21046 submit_info.pSignalSemaphores = &semaphore;
21047 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21048 }
21049 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021050 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021051 VkSubmitInfo submit_info{};
21052 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21053 submit_info.commandBufferCount = 1;
21054 submit_info.pCommandBuffers = &command_buffer[1];
21055 submit_info.waitSemaphoreCount = 1;
21056 submit_info.pWaitSemaphores = &semaphore;
21057 submit_info.pWaitDstStageMask = flags;
21058 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21059 }
21060
21061 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21062
21063 vkDestroyFence(m_device->device(), fence, nullptr);
21064 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21065 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21066 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21067
21068 m_errorMonitor->VerifyNotFound();
21069}
21070
21071// This is a positive test. No errors should be generated.
21072TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021073 TEST_DESCRIPTION(
21074 "Two command buffers, each in a separate QueueSubmit call "
21075 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21076 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021077
21078 m_errorMonitor->ExpectSuccess();
21079
21080 ASSERT_NO_FATAL_FAILURE(InitState());
21081 VkFence fence;
21082 VkFenceCreateInfo fence_create_info{};
21083 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21084 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21085
21086 VkCommandPool command_pool;
21087 VkCommandPoolCreateInfo pool_create_info{};
21088 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21089 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21090 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21091 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21092
21093 VkCommandBuffer command_buffer[2];
21094 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21095 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21096 command_buffer_allocate_info.commandPool = command_pool;
21097 command_buffer_allocate_info.commandBufferCount = 2;
21098 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21099 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21100
21101 {
21102 VkCommandBufferBeginInfo begin_info{};
21103 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21104 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21105
21106 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 -070021107 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021108
21109 VkViewport viewport{};
21110 viewport.maxDepth = 1.0f;
21111 viewport.minDepth = 0.0f;
21112 viewport.width = 512;
21113 viewport.height = 512;
21114 viewport.x = 0;
21115 viewport.y = 0;
21116 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21117 vkEndCommandBuffer(command_buffer[0]);
21118 }
21119 {
21120 VkCommandBufferBeginInfo begin_info{};
21121 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21122 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21123
21124 VkViewport viewport{};
21125 viewport.maxDepth = 1.0f;
21126 viewport.minDepth = 0.0f;
21127 viewport.width = 512;
21128 viewport.height = 512;
21129 viewport.x = 0;
21130 viewport.y = 0;
21131 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21132 vkEndCommandBuffer(command_buffer[1]);
21133 }
21134 {
21135 VkSubmitInfo submit_info{};
21136 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21137 submit_info.commandBufferCount = 1;
21138 submit_info.pCommandBuffers = &command_buffer[0];
21139 submit_info.signalSemaphoreCount = 0;
21140 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21142 }
21143 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021144 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021145 VkSubmitInfo submit_info{};
21146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21147 submit_info.commandBufferCount = 1;
21148 submit_info.pCommandBuffers = &command_buffer[1];
21149 submit_info.waitSemaphoreCount = 0;
21150 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21151 submit_info.pWaitDstStageMask = flags;
21152 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21153 }
21154
21155 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21156
21157 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21158 ASSERT_VK_SUCCESS(err);
21159
21160 vkDestroyFence(m_device->device(), fence, nullptr);
21161 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21162 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21163
21164 m_errorMonitor->VerifyNotFound();
21165}
21166
21167// This is a positive test. No errors should be generated.
21168TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021169 TEST_DESCRIPTION(
21170 "Two command buffers, each in a separate QueueSubmit call "
21171 "on the same queue, the second having a fence, followed "
21172 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021173
21174 m_errorMonitor->ExpectSuccess();
21175
21176 ASSERT_NO_FATAL_FAILURE(InitState());
21177 VkFence fence;
21178 VkFenceCreateInfo fence_create_info{};
21179 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21180 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21181
21182 VkCommandPool command_pool;
21183 VkCommandPoolCreateInfo pool_create_info{};
21184 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21185 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21186 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21187 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21188
21189 VkCommandBuffer command_buffer[2];
21190 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21191 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21192 command_buffer_allocate_info.commandPool = command_pool;
21193 command_buffer_allocate_info.commandBufferCount = 2;
21194 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21195 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21196
21197 {
21198 VkCommandBufferBeginInfo begin_info{};
21199 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21200 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21201
21202 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 -070021203 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021204
21205 VkViewport viewport{};
21206 viewport.maxDepth = 1.0f;
21207 viewport.minDepth = 0.0f;
21208 viewport.width = 512;
21209 viewport.height = 512;
21210 viewport.x = 0;
21211 viewport.y = 0;
21212 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21213 vkEndCommandBuffer(command_buffer[0]);
21214 }
21215 {
21216 VkCommandBufferBeginInfo begin_info{};
21217 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21218 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21219
21220 VkViewport viewport{};
21221 viewport.maxDepth = 1.0f;
21222 viewport.minDepth = 0.0f;
21223 viewport.width = 512;
21224 viewport.height = 512;
21225 viewport.x = 0;
21226 viewport.y = 0;
21227 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21228 vkEndCommandBuffer(command_buffer[1]);
21229 }
21230 {
21231 VkSubmitInfo submit_info{};
21232 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21233 submit_info.commandBufferCount = 1;
21234 submit_info.pCommandBuffers = &command_buffer[0];
21235 submit_info.signalSemaphoreCount = 0;
21236 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21238 }
21239 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021240 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021241 VkSubmitInfo submit_info{};
21242 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21243 submit_info.commandBufferCount = 1;
21244 submit_info.pCommandBuffers = &command_buffer[1];
21245 submit_info.waitSemaphoreCount = 0;
21246 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21247 submit_info.pWaitDstStageMask = flags;
21248 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21249 }
21250
21251 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21252
21253 vkDestroyFence(m_device->device(), fence, nullptr);
21254 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21255 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21256
21257 m_errorMonitor->VerifyNotFound();
21258}
21259
21260// This is a positive test. No errors should be generated.
21261TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021262 TEST_DESCRIPTION(
21263 "Two command buffers each in a separate SubmitInfo sent in a single "
21264 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021265 ASSERT_NO_FATAL_FAILURE(InitState());
21266
21267 m_errorMonitor->ExpectSuccess();
21268
21269 VkFence fence;
21270 VkFenceCreateInfo fence_create_info{};
21271 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21272 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21273
21274 VkSemaphore semaphore;
21275 VkSemaphoreCreateInfo semaphore_create_info{};
21276 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21277 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21278
21279 VkCommandPool command_pool;
21280 VkCommandPoolCreateInfo pool_create_info{};
21281 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21282 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21283 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21284 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21285
21286 VkCommandBuffer command_buffer[2];
21287 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21288 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21289 command_buffer_allocate_info.commandPool = command_pool;
21290 command_buffer_allocate_info.commandBufferCount = 2;
21291 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21292 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21293
21294 {
21295 VkCommandBufferBeginInfo begin_info{};
21296 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21297 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21298
21299 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021300 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021301
21302 VkViewport viewport{};
21303 viewport.maxDepth = 1.0f;
21304 viewport.minDepth = 0.0f;
21305 viewport.width = 512;
21306 viewport.height = 512;
21307 viewport.x = 0;
21308 viewport.y = 0;
21309 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21310 vkEndCommandBuffer(command_buffer[0]);
21311 }
21312 {
21313 VkCommandBufferBeginInfo begin_info{};
21314 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21315 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21316
21317 VkViewport viewport{};
21318 viewport.maxDepth = 1.0f;
21319 viewport.minDepth = 0.0f;
21320 viewport.width = 512;
21321 viewport.height = 512;
21322 viewport.x = 0;
21323 viewport.y = 0;
21324 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21325 vkEndCommandBuffer(command_buffer[1]);
21326 }
21327 {
21328 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021329 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021330
21331 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21332 submit_info[0].pNext = NULL;
21333 submit_info[0].commandBufferCount = 1;
21334 submit_info[0].pCommandBuffers = &command_buffer[0];
21335 submit_info[0].signalSemaphoreCount = 1;
21336 submit_info[0].pSignalSemaphores = &semaphore;
21337 submit_info[0].waitSemaphoreCount = 0;
21338 submit_info[0].pWaitSemaphores = NULL;
21339 submit_info[0].pWaitDstStageMask = 0;
21340
21341 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21342 submit_info[1].pNext = NULL;
21343 submit_info[1].commandBufferCount = 1;
21344 submit_info[1].pCommandBuffers = &command_buffer[1];
21345 submit_info[1].waitSemaphoreCount = 1;
21346 submit_info[1].pWaitSemaphores = &semaphore;
21347 submit_info[1].pWaitDstStageMask = flags;
21348 submit_info[1].signalSemaphoreCount = 0;
21349 submit_info[1].pSignalSemaphores = NULL;
21350 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21351 }
21352
21353 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21354
21355 vkDestroyFence(m_device->device(), fence, nullptr);
21356 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21357 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21358 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21359
21360 m_errorMonitor->VerifyNotFound();
21361}
21362
21363TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21364 m_errorMonitor->ExpectSuccess();
21365
21366 ASSERT_NO_FATAL_FAILURE(InitState());
21367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21368
Tony Barbour552f6c02016-12-21 14:34:07 -070021369 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021370
21371 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21372 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21373 m_errorMonitor->VerifyNotFound();
21374 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21375 m_errorMonitor->VerifyNotFound();
21376 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21377 m_errorMonitor->VerifyNotFound();
21378
21379 m_commandBuffer->EndCommandBuffer();
21380 m_errorMonitor->VerifyNotFound();
21381}
21382
21383TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021384 TEST_DESCRIPTION(
21385 "Positive test where we create a renderpass with an "
21386 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21387 "has a valid layout, and a second subpass then uses a "
21388 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021389 m_errorMonitor->ExpectSuccess();
21390 ASSERT_NO_FATAL_FAILURE(InitState());
21391
21392 VkAttachmentReference attach[2] = {};
21393 attach[0].attachment = 0;
21394 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21395 attach[1].attachment = 0;
21396 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21397 VkSubpassDescription subpasses[2] = {};
21398 // First subpass clears DS attach on load
21399 subpasses[0].pDepthStencilAttachment = &attach[0];
21400 // 2nd subpass reads in DS as input attachment
21401 subpasses[1].inputAttachmentCount = 1;
21402 subpasses[1].pInputAttachments = &attach[1];
21403 VkAttachmentDescription attach_desc = {};
21404 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21405 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21406 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21407 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21408 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21409 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21410 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21411 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21412 VkRenderPassCreateInfo rpci = {};
21413 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21414 rpci.attachmentCount = 1;
21415 rpci.pAttachments = &attach_desc;
21416 rpci.subpassCount = 2;
21417 rpci.pSubpasses = subpasses;
21418
21419 // Now create RenderPass and verify no errors
21420 VkRenderPass rp;
21421 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21422 m_errorMonitor->VerifyNotFound();
21423
21424 vkDestroyRenderPass(m_device->device(), rp, NULL);
21425}
21426
Tobin Ehlis01103de2017-02-16 13:22:47 -070021427TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21428 TEST_DESCRIPTION(
21429 "Create a render pass with depth-stencil attachment where layout transition "
21430 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21431 "transition has correctly occurred at queue submit time with no validation errors.");
21432
21433 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21434 VkImageFormatProperties format_props;
21435 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21436 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21437 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21438 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21439 return;
21440 }
21441
21442 m_errorMonitor->ExpectSuccess();
21443 ASSERT_NO_FATAL_FAILURE(InitState());
21444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21445
21446 // A renderpass with one depth/stencil attachment.
21447 VkAttachmentDescription attachment = {0,
21448 ds_format,
21449 VK_SAMPLE_COUNT_1_BIT,
21450 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21451 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21452 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21453 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21454 VK_IMAGE_LAYOUT_UNDEFINED,
21455 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21456
21457 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21458
21459 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21460
21461 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21462
21463 VkRenderPass rp;
21464 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21465 ASSERT_VK_SUCCESS(err);
21466 // A compatible ds image.
21467 VkImageObj image(m_device);
21468 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21469 ASSERT_TRUE(image.initialized());
21470
21471 VkImageViewCreateInfo ivci = {
21472 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21473 nullptr,
21474 0,
21475 image.handle(),
21476 VK_IMAGE_VIEW_TYPE_2D,
21477 ds_format,
21478 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21479 VK_COMPONENT_SWIZZLE_IDENTITY},
21480 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21481 };
21482 VkImageView view;
21483 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21484 ASSERT_VK_SUCCESS(err);
21485
21486 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21487 VkFramebuffer fb;
21488 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21489 ASSERT_VK_SUCCESS(err);
21490
21491 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21492 m_commandBuffer->BeginCommandBuffer();
21493 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21494 vkCmdEndRenderPass(m_commandBuffer->handle());
21495 m_commandBuffer->EndCommandBuffer();
21496 QueueCommandBuffer(false);
21497 m_errorMonitor->VerifyNotFound();
21498
21499 // Cleanup
21500 vkDestroyImageView(m_device->device(), view, NULL);
21501 vkDestroyRenderPass(m_device->device(), rp, NULL);
21502 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21503}
21504
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021505TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021506 TEST_DESCRIPTION(
21507 "Test that pipeline validation accepts matrices passed "
21508 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021509 m_errorMonitor->ExpectSuccess();
21510
21511 ASSERT_NO_FATAL_FAILURE(InitState());
21512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21513
21514 VkVertexInputBindingDescription input_binding;
21515 memset(&input_binding, 0, sizeof(input_binding));
21516
21517 VkVertexInputAttributeDescription input_attribs[2];
21518 memset(input_attribs, 0, sizeof(input_attribs));
21519
21520 for (int i = 0; i < 2; i++) {
21521 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21522 input_attribs[i].location = i;
21523 }
21524
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021525 char const *vsSource =
21526 "#version 450\n"
21527 "\n"
21528 "layout(location=0) in mat2x4 x;\n"
21529 "out gl_PerVertex {\n"
21530 " vec4 gl_Position;\n"
21531 "};\n"
21532 "void main(){\n"
21533 " gl_Position = x[0] + x[1];\n"
21534 "}\n";
21535 char const *fsSource =
21536 "#version 450\n"
21537 "\n"
21538 "layout(location=0) out vec4 color;\n"
21539 "void main(){\n"
21540 " color = vec4(1);\n"
21541 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021542
21543 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21544 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21545
21546 VkPipelineObj pipe(m_device);
21547 pipe.AddColorAttachment();
21548 pipe.AddShader(&vs);
21549 pipe.AddShader(&fs);
21550
21551 pipe.AddVertexInputBindings(&input_binding, 1);
21552 pipe.AddVertexInputAttribs(input_attribs, 2);
21553
21554 VkDescriptorSetObj descriptorSet(m_device);
21555 descriptorSet.AppendDummy();
21556 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21557
21558 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21559
21560 /* expect success */
21561 m_errorMonitor->VerifyNotFound();
21562}
21563
21564TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21565 m_errorMonitor->ExpectSuccess();
21566
21567 ASSERT_NO_FATAL_FAILURE(InitState());
21568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21569
21570 VkVertexInputBindingDescription input_binding;
21571 memset(&input_binding, 0, sizeof(input_binding));
21572
21573 VkVertexInputAttributeDescription input_attribs[2];
21574 memset(input_attribs, 0, sizeof(input_attribs));
21575
21576 for (int i = 0; i < 2; i++) {
21577 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21578 input_attribs[i].location = i;
21579 }
21580
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021581 char const *vsSource =
21582 "#version 450\n"
21583 "\n"
21584 "layout(location=0) in vec4 x[2];\n"
21585 "out gl_PerVertex {\n"
21586 " vec4 gl_Position;\n"
21587 "};\n"
21588 "void main(){\n"
21589 " gl_Position = x[0] + x[1];\n"
21590 "}\n";
21591 char const *fsSource =
21592 "#version 450\n"
21593 "\n"
21594 "layout(location=0) out vec4 color;\n"
21595 "void main(){\n"
21596 " color = vec4(1);\n"
21597 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021598
21599 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21601
21602 VkPipelineObj pipe(m_device);
21603 pipe.AddColorAttachment();
21604 pipe.AddShader(&vs);
21605 pipe.AddShader(&fs);
21606
21607 pipe.AddVertexInputBindings(&input_binding, 1);
21608 pipe.AddVertexInputAttribs(input_attribs, 2);
21609
21610 VkDescriptorSetObj descriptorSet(m_device);
21611 descriptorSet.AppendDummy();
21612 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21613
21614 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21615
21616 m_errorMonitor->VerifyNotFound();
21617}
21618
21619TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021620 TEST_DESCRIPTION(
21621 "Test that pipeline validation accepts consuming a vertex attribute "
21622 "through multiple vertex shader inputs, each consuming a different "
21623 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021624 m_errorMonitor->ExpectSuccess();
21625
21626 ASSERT_NO_FATAL_FAILURE(InitState());
21627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21628
21629 VkVertexInputBindingDescription input_binding;
21630 memset(&input_binding, 0, sizeof(input_binding));
21631
21632 VkVertexInputAttributeDescription input_attribs[3];
21633 memset(input_attribs, 0, sizeof(input_attribs));
21634
21635 for (int i = 0; i < 3; i++) {
21636 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21637 input_attribs[i].location = i;
21638 }
21639
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021640 char const *vsSource =
21641 "#version 450\n"
21642 "\n"
21643 "layout(location=0) in vec4 x;\n"
21644 "layout(location=1) in vec3 y1;\n"
21645 "layout(location=1, component=3) in float y2;\n"
21646 "layout(location=2) in vec4 z;\n"
21647 "out gl_PerVertex {\n"
21648 " vec4 gl_Position;\n"
21649 "};\n"
21650 "void main(){\n"
21651 " gl_Position = x + vec4(y1, y2) + z;\n"
21652 "}\n";
21653 char const *fsSource =
21654 "#version 450\n"
21655 "\n"
21656 "layout(location=0) out vec4 color;\n"
21657 "void main(){\n"
21658 " color = vec4(1);\n"
21659 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021660
21661 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21662 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21663
21664 VkPipelineObj pipe(m_device);
21665 pipe.AddColorAttachment();
21666 pipe.AddShader(&vs);
21667 pipe.AddShader(&fs);
21668
21669 pipe.AddVertexInputBindings(&input_binding, 1);
21670 pipe.AddVertexInputAttribs(input_attribs, 3);
21671
21672 VkDescriptorSetObj descriptorSet(m_device);
21673 descriptorSet.AppendDummy();
21674 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21675
21676 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21677
21678 m_errorMonitor->VerifyNotFound();
21679}
21680
21681TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21682 m_errorMonitor->ExpectSuccess();
21683
21684 ASSERT_NO_FATAL_FAILURE(InitState());
21685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21686
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021687 char const *vsSource =
21688 "#version 450\n"
21689 "out gl_PerVertex {\n"
21690 " vec4 gl_Position;\n"
21691 "};\n"
21692 "void main(){\n"
21693 " gl_Position = vec4(0);\n"
21694 "}\n";
21695 char const *fsSource =
21696 "#version 450\n"
21697 "\n"
21698 "layout(location=0) out vec4 color;\n"
21699 "void main(){\n"
21700 " color = vec4(1);\n"
21701 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021702
21703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21705
21706 VkPipelineObj pipe(m_device);
21707 pipe.AddColorAttachment();
21708 pipe.AddShader(&vs);
21709 pipe.AddShader(&fs);
21710
21711 VkDescriptorSetObj descriptorSet(m_device);
21712 descriptorSet.AppendDummy();
21713 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21714
21715 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21716
21717 m_errorMonitor->VerifyNotFound();
21718}
21719
21720TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021721 TEST_DESCRIPTION(
21722 "Test that pipeline validation accepts the relaxed type matching rules "
21723 "set out in 14.1.3: fundamental type must match, and producer side must "
21724 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021725 m_errorMonitor->ExpectSuccess();
21726
21727 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21728
21729 ASSERT_NO_FATAL_FAILURE(InitState());
21730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21731
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021732 char const *vsSource =
21733 "#version 450\n"
21734 "out gl_PerVertex {\n"
21735 " vec4 gl_Position;\n"
21736 "};\n"
21737 "layout(location=0) out vec3 x;\n"
21738 "layout(location=1) out ivec3 y;\n"
21739 "layout(location=2) out vec3 z;\n"
21740 "void main(){\n"
21741 " gl_Position = vec4(0);\n"
21742 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21743 "}\n";
21744 char const *fsSource =
21745 "#version 450\n"
21746 "\n"
21747 "layout(location=0) out vec4 color;\n"
21748 "layout(location=0) in float x;\n"
21749 "layout(location=1) flat in int y;\n"
21750 "layout(location=2) in vec2 z;\n"
21751 "void main(){\n"
21752 " color = vec4(1 + x + y + z.x);\n"
21753 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021754
21755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21757
21758 VkPipelineObj pipe(m_device);
21759 pipe.AddColorAttachment();
21760 pipe.AddShader(&vs);
21761 pipe.AddShader(&fs);
21762
21763 VkDescriptorSetObj descriptorSet(m_device);
21764 descriptorSet.AppendDummy();
21765 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21766
21767 VkResult err = VK_SUCCESS;
21768 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21769 ASSERT_VK_SUCCESS(err);
21770
21771 m_errorMonitor->VerifyNotFound();
21772}
21773
21774TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021775 TEST_DESCRIPTION(
21776 "Test that pipeline validation accepts per-vertex variables "
21777 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021778 m_errorMonitor->ExpectSuccess();
21779
21780 ASSERT_NO_FATAL_FAILURE(InitState());
21781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21782
21783 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021784 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021785 return;
21786 }
21787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021788 char const *vsSource =
21789 "#version 450\n"
21790 "void main(){}\n";
21791 char const *tcsSource =
21792 "#version 450\n"
21793 "layout(location=0) out int x[];\n"
21794 "layout(vertices=3) out;\n"
21795 "void main(){\n"
21796 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21797 " gl_TessLevelInner[0] = 1;\n"
21798 " x[gl_InvocationID] = gl_InvocationID;\n"
21799 "}\n";
21800 char const *tesSource =
21801 "#version 450\n"
21802 "layout(triangles, equal_spacing, cw) in;\n"
21803 "layout(location=0) in int x[];\n"
21804 "out gl_PerVertex { vec4 gl_Position; };\n"
21805 "void main(){\n"
21806 " gl_Position.xyz = gl_TessCoord;\n"
21807 " gl_Position.w = x[0] + x[1] + x[2];\n"
21808 "}\n";
21809 char const *fsSource =
21810 "#version 450\n"
21811 "layout(location=0) out vec4 color;\n"
21812 "void main(){\n"
21813 " color = vec4(1);\n"
21814 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021815
21816 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21817 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21818 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21820
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021821 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21822 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021823
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021824 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021825
21826 VkPipelineObj pipe(m_device);
21827 pipe.SetInputAssembly(&iasci);
21828 pipe.SetTessellation(&tsci);
21829 pipe.AddColorAttachment();
21830 pipe.AddShader(&vs);
21831 pipe.AddShader(&tcs);
21832 pipe.AddShader(&tes);
21833 pipe.AddShader(&fs);
21834
21835 VkDescriptorSetObj descriptorSet(m_device);
21836 descriptorSet.AppendDummy();
21837 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21838
21839 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21840
21841 m_errorMonitor->VerifyNotFound();
21842}
21843
21844TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021845 TEST_DESCRIPTION(
21846 "Test that pipeline validation accepts a user-defined "
21847 "interface block passed into the geometry shader. This "
21848 "is interesting because the 'extra' array level is not "
21849 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021850 m_errorMonitor->ExpectSuccess();
21851
21852 ASSERT_NO_FATAL_FAILURE(InitState());
21853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21854
21855 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021856 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021857 return;
21858 }
21859
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021860 char const *vsSource =
21861 "#version 450\n"
21862 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21863 "void main(){\n"
21864 " vs_out.x = vec4(1);\n"
21865 "}\n";
21866 char const *gsSource =
21867 "#version 450\n"
21868 "layout(triangles) in;\n"
21869 "layout(triangle_strip, max_vertices=3) out;\n"
21870 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21871 "out gl_PerVertex { vec4 gl_Position; };\n"
21872 "void main() {\n"
21873 " gl_Position = gs_in[0].x;\n"
21874 " EmitVertex();\n"
21875 "}\n";
21876 char const *fsSource =
21877 "#version 450\n"
21878 "layout(location=0) out vec4 color;\n"
21879 "void main(){\n"
21880 " color = vec4(1);\n"
21881 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021882
21883 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21884 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21886
21887 VkPipelineObj pipe(m_device);
21888 pipe.AddColorAttachment();
21889 pipe.AddShader(&vs);
21890 pipe.AddShader(&gs);
21891 pipe.AddShader(&fs);
21892
21893 VkDescriptorSetObj descriptorSet(m_device);
21894 descriptorSet.AppendDummy();
21895 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21896
21897 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21898
21899 m_errorMonitor->VerifyNotFound();
21900}
21901
21902TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021903 TEST_DESCRIPTION(
21904 "Test that pipeline validation accepts basic use of 64bit vertex "
21905 "attributes. This is interesting because they consume multiple "
21906 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021907 m_errorMonitor->ExpectSuccess();
21908
21909 ASSERT_NO_FATAL_FAILURE(InitState());
21910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21911
21912 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021913 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021914 return;
21915 }
21916
21917 VkVertexInputBindingDescription input_bindings[1];
21918 memset(input_bindings, 0, sizeof(input_bindings));
21919
21920 VkVertexInputAttributeDescription input_attribs[4];
21921 memset(input_attribs, 0, sizeof(input_attribs));
21922 input_attribs[0].location = 0;
21923 input_attribs[0].offset = 0;
21924 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21925 input_attribs[1].location = 2;
21926 input_attribs[1].offset = 32;
21927 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21928 input_attribs[2].location = 4;
21929 input_attribs[2].offset = 64;
21930 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21931 input_attribs[3].location = 6;
21932 input_attribs[3].offset = 96;
21933 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21934
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021935 char const *vsSource =
21936 "#version 450\n"
21937 "\n"
21938 "layout(location=0) in dmat4 x;\n"
21939 "out gl_PerVertex {\n"
21940 " vec4 gl_Position;\n"
21941 "};\n"
21942 "void main(){\n"
21943 " gl_Position = vec4(x[0][0]);\n"
21944 "}\n";
21945 char const *fsSource =
21946 "#version 450\n"
21947 "\n"
21948 "layout(location=0) out vec4 color;\n"
21949 "void main(){\n"
21950 " color = vec4(1);\n"
21951 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021952
21953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21955
21956 VkPipelineObj pipe(m_device);
21957 pipe.AddColorAttachment();
21958 pipe.AddShader(&vs);
21959 pipe.AddShader(&fs);
21960
21961 pipe.AddVertexInputBindings(input_bindings, 1);
21962 pipe.AddVertexInputAttribs(input_attribs, 4);
21963
21964 VkDescriptorSetObj descriptorSet(m_device);
21965 descriptorSet.AppendDummy();
21966 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21967
21968 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21969
21970 m_errorMonitor->VerifyNotFound();
21971}
21972
21973TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21974 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21975 m_errorMonitor->ExpectSuccess();
21976
21977 ASSERT_NO_FATAL_FAILURE(InitState());
21978
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021979 char const *vsSource =
21980 "#version 450\n"
21981 "\n"
21982 "out gl_PerVertex {\n"
21983 " vec4 gl_Position;\n"
21984 "};\n"
21985 "void main(){\n"
21986 " gl_Position = vec4(1);\n"
21987 "}\n";
21988 char const *fsSource =
21989 "#version 450\n"
21990 "\n"
21991 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21992 "layout(location=0) out vec4 color;\n"
21993 "void main() {\n"
21994 " color = subpassLoad(x);\n"
21995 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021996
21997 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21998 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21999
22000 VkPipelineObj pipe(m_device);
22001 pipe.AddShader(&vs);
22002 pipe.AddShader(&fs);
22003 pipe.AddColorAttachment();
22004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22005
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022006 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22007 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022008 VkDescriptorSetLayout dsl;
22009 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22010 ASSERT_VK_SUCCESS(err);
22011
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022012 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022013 VkPipelineLayout pl;
22014 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22015 ASSERT_VK_SUCCESS(err);
22016
22017 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022018 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22019 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22020 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22021 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22022 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 -060022023 };
22024 VkAttachmentReference color = {
22025 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22026 };
22027 VkAttachmentReference input = {
22028 1, VK_IMAGE_LAYOUT_GENERAL,
22029 };
22030
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022031 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022032
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022033 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022034 VkRenderPass rp;
22035 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22036 ASSERT_VK_SUCCESS(err);
22037
22038 // should be OK. would go wrong here if it's going to...
22039 pipe.CreateVKPipeline(pl, rp);
22040
22041 m_errorMonitor->VerifyNotFound();
22042
22043 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22044 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22045 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22046}
22047
22048TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022049 TEST_DESCRIPTION(
22050 "Test that pipeline validation accepts a compute pipeline which declares a "
22051 "descriptor-backed resource which is not provided, but the shader does not "
22052 "statically use it. This is interesting because it requires compute pipelines "
22053 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022054 m_errorMonitor->ExpectSuccess();
22055
22056 ASSERT_NO_FATAL_FAILURE(InitState());
22057
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022058 char const *csSource =
22059 "#version 450\n"
22060 "\n"
22061 "layout(local_size_x=1) in;\n"
22062 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22063 "void main(){\n"
22064 " // x is not used.\n"
22065 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022066
22067 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22068
22069 VkDescriptorSetObj descriptorSet(m_device);
22070 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22071
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022072 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22073 nullptr,
22074 0,
22075 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22076 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22077 descriptorSet.GetPipelineLayout(),
22078 VK_NULL_HANDLE,
22079 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022080
22081 VkPipeline pipe;
22082 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22083
22084 m_errorMonitor->VerifyNotFound();
22085
22086 if (err == VK_SUCCESS) {
22087 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22088 }
22089}
22090
22091TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022092 TEST_DESCRIPTION(
22093 "Test that pipeline validation accepts a shader consuming only the "
22094 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022095 m_errorMonitor->ExpectSuccess();
22096
22097 ASSERT_NO_FATAL_FAILURE(InitState());
22098
22099 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022100 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22101 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22102 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022103 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022104 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022105 VkDescriptorSetLayout dsl;
22106 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22107 ASSERT_VK_SUCCESS(err);
22108
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022109 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022110 VkPipelineLayout pl;
22111 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22112 ASSERT_VK_SUCCESS(err);
22113
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022114 char const *csSource =
22115 "#version 450\n"
22116 "\n"
22117 "layout(local_size_x=1) in;\n"
22118 "layout(set=0, binding=0) uniform sampler s;\n"
22119 "layout(set=0, binding=1) uniform texture2D t;\n"
22120 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22121 "void main() {\n"
22122 " x = texture(sampler2D(t, s), vec2(0));\n"
22123 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022124 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22125
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022126 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22127 nullptr,
22128 0,
22129 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22130 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22131 pl,
22132 VK_NULL_HANDLE,
22133 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022134
22135 VkPipeline pipe;
22136 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22137
22138 m_errorMonitor->VerifyNotFound();
22139
22140 if (err == VK_SUCCESS) {
22141 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22142 }
22143
22144 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22145 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22146}
22147
22148TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022149 TEST_DESCRIPTION(
22150 "Test that pipeline validation accepts a shader consuming only the "
22151 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022152 m_errorMonitor->ExpectSuccess();
22153
22154 ASSERT_NO_FATAL_FAILURE(InitState());
22155
22156 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022157 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22158 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22159 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022160 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022161 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022162 VkDescriptorSetLayout dsl;
22163 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22164 ASSERT_VK_SUCCESS(err);
22165
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022166 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022167 VkPipelineLayout pl;
22168 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22169 ASSERT_VK_SUCCESS(err);
22170
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022171 char const *csSource =
22172 "#version 450\n"
22173 "\n"
22174 "layout(local_size_x=1) in;\n"
22175 "layout(set=0, binding=0) uniform texture2D t;\n"
22176 "layout(set=0, binding=1) uniform sampler s;\n"
22177 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22178 "void main() {\n"
22179 " x = texture(sampler2D(t, s), vec2(0));\n"
22180 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022181 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22182
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022183 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22184 nullptr,
22185 0,
22186 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22187 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22188 pl,
22189 VK_NULL_HANDLE,
22190 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022191
22192 VkPipeline pipe;
22193 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22194
22195 m_errorMonitor->VerifyNotFound();
22196
22197 if (err == VK_SUCCESS) {
22198 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22199 }
22200
22201 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22202 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22203}
22204
22205TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022206 TEST_DESCRIPTION(
22207 "Test that pipeline validation accepts a shader consuming "
22208 "both the sampler and the image of a combined image+sampler "
22209 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022210 m_errorMonitor->ExpectSuccess();
22211
22212 ASSERT_NO_FATAL_FAILURE(InitState());
22213
22214 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022215 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22216 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022217 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022218 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022219 VkDescriptorSetLayout dsl;
22220 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22221 ASSERT_VK_SUCCESS(err);
22222
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022223 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022224 VkPipelineLayout pl;
22225 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22226 ASSERT_VK_SUCCESS(err);
22227
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022228 char const *csSource =
22229 "#version 450\n"
22230 "\n"
22231 "layout(local_size_x=1) in;\n"
22232 "layout(set=0, binding=0) uniform texture2D t;\n"
22233 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22234 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22235 "void main() {\n"
22236 " x = texture(sampler2D(t, s), vec2(0));\n"
22237 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022238 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22239
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022240 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22241 nullptr,
22242 0,
22243 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22244 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22245 pl,
22246 VK_NULL_HANDLE,
22247 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022248
22249 VkPipeline pipe;
22250 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22251
22252 m_errorMonitor->VerifyNotFound();
22253
22254 if (err == VK_SUCCESS) {
22255 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22256 }
22257
22258 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22259 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22260}
22261
22262TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22263 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22264
22265 ASSERT_NO_FATAL_FAILURE(InitState());
22266
22267 // Positive test to check parameter_validation and unique_objects support
22268 // for NV_dedicated_allocation
22269 uint32_t extension_count = 0;
22270 bool supports_nv_dedicated_allocation = false;
22271 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22272 ASSERT_VK_SUCCESS(err);
22273
22274 if (extension_count > 0) {
22275 std::vector<VkExtensionProperties> available_extensions(extension_count);
22276
22277 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22278 ASSERT_VK_SUCCESS(err);
22279
22280 for (const auto &extension_props : available_extensions) {
22281 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22282 supports_nv_dedicated_allocation = true;
22283 }
22284 }
22285 }
22286
22287 if (supports_nv_dedicated_allocation) {
22288 m_errorMonitor->ExpectSuccess();
22289
22290 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22291 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22292 dedicated_buffer_create_info.pNext = nullptr;
22293 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22294
22295 uint32_t queue_family_index = 0;
22296 VkBufferCreateInfo buffer_create_info = {};
22297 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22298 buffer_create_info.pNext = &dedicated_buffer_create_info;
22299 buffer_create_info.size = 1024;
22300 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22301 buffer_create_info.queueFamilyIndexCount = 1;
22302 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22303
22304 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022305 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022306 ASSERT_VK_SUCCESS(err);
22307
22308 VkMemoryRequirements memory_reqs;
22309 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22310
22311 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22312 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22313 dedicated_memory_info.pNext = nullptr;
22314 dedicated_memory_info.buffer = buffer;
22315 dedicated_memory_info.image = VK_NULL_HANDLE;
22316
22317 VkMemoryAllocateInfo memory_info = {};
22318 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22319 memory_info.pNext = &dedicated_memory_info;
22320 memory_info.allocationSize = memory_reqs.size;
22321
22322 bool pass;
22323 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22324 ASSERT_TRUE(pass);
22325
22326 VkDeviceMemory buffer_memory;
22327 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22328 ASSERT_VK_SUCCESS(err);
22329
22330 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22331 ASSERT_VK_SUCCESS(err);
22332
22333 vkDestroyBuffer(m_device->device(), buffer, NULL);
22334 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22335
22336 m_errorMonitor->VerifyNotFound();
22337 }
22338}
22339
22340TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22341 VkResult err;
22342
22343 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22344
22345 ASSERT_NO_FATAL_FAILURE(InitState());
22346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22347
22348 std::vector<const char *> device_extension_names;
22349 auto features = m_device->phy().features();
22350 // Artificially disable support for non-solid fill modes
22351 features.fillModeNonSolid = false;
22352 // The sacrificial device object
22353 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22354
22355 VkRenderpassObj render_pass(&test_device);
22356
22357 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22358 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22359 pipeline_layout_ci.setLayoutCount = 0;
22360 pipeline_layout_ci.pSetLayouts = NULL;
22361
22362 VkPipelineLayout pipeline_layout;
22363 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22364 ASSERT_VK_SUCCESS(err);
22365
22366 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22367 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22368 rs_ci.pNext = nullptr;
22369 rs_ci.lineWidth = 1.0f;
22370 rs_ci.rasterizerDiscardEnable = true;
22371
22372 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22373 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22374
22375 // Set polygonMode=FILL. No error is expected
22376 m_errorMonitor->ExpectSuccess();
22377 {
22378 VkPipelineObj pipe(&test_device);
22379 pipe.AddShader(&vs);
22380 pipe.AddShader(&fs);
22381 pipe.AddColorAttachment();
22382 // Set polygonMode to a good value
22383 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22384 pipe.SetRasterization(&rs_ci);
22385 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22386 }
22387 m_errorMonitor->VerifyNotFound();
22388
22389 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22390}
22391
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022392#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022393TEST_F(VkPositiveLayerTest, LongFenceChain)
22394{
22395 m_errorMonitor->ExpectSuccess();
22396
22397 ASSERT_NO_FATAL_FAILURE(InitState());
22398 VkResult err;
22399
22400 std::vector<VkFence> fences;
22401
22402 const int chainLength = 32768;
22403
22404 for (int i = 0; i < chainLength; i++) {
22405 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22406 VkFence fence;
22407 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22408 ASSERT_VK_SUCCESS(err);
22409
22410 fences.push_back(fence);
22411
22412 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22413 0, nullptr, 0, nullptr };
22414 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22415 ASSERT_VK_SUCCESS(err);
22416
22417 }
22418
22419 // BOOM, stack overflow.
22420 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22421
22422 for (auto fence : fences)
22423 vkDestroyFence(m_device->device(), fence, nullptr);
22424
22425 m_errorMonitor->VerifyNotFound();
22426}
22427#endif
22428
Cody Northrop1242dfd2016-07-13 17:24:59 -060022429#if defined(ANDROID) && defined(VALIDATION_APK)
22430static bool initialized = false;
22431static bool active = false;
22432
22433// Convert Intents to argv
22434// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022435std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022436 std::vector<std::string> args;
22437 JavaVM &vm = *app.activity->vm;
22438 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022439 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022440
22441 JNIEnv &env = *p_env;
22442 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022443 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022444 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022445 jmethodID get_string_extra_method =
22446 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022447 jvalue get_string_extra_args;
22448 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022449 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022450
22451 std::string args_str;
22452 if (extra_str) {
22453 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22454 args_str = extra_utf;
22455 env.ReleaseStringUTFChars(extra_str, extra_utf);
22456 env.DeleteLocalRef(extra_str);
22457 }
22458
22459 env.DeleteLocalRef(get_string_extra_args.l);
22460 env.DeleteLocalRef(intent);
22461 vm.DetachCurrentThread();
22462
22463 // split args_str
22464 std::stringstream ss(args_str);
22465 std::string arg;
22466 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022467 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022468 }
22469
22470 return args;
22471}
22472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022473static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022474
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022475static void processCommand(struct android_app *app, int32_t cmd) {
22476 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022477 case APP_CMD_INIT_WINDOW: {
22478 if (app->window) {
22479 initialized = true;
22480 }
22481 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022482 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022483 case APP_CMD_GAINED_FOCUS: {
22484 active = true;
22485 break;
22486 }
22487 case APP_CMD_LOST_FOCUS: {
22488 active = false;
22489 break;
22490 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022491 }
22492}
22493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022494void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022495 app_dummy();
22496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022497 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022498
22499 int vulkanSupport = InitVulkan();
22500 if (vulkanSupport == 0) {
22501 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22502 return;
22503 }
22504
22505 app->onAppCmd = processCommand;
22506 app->onInputEvent = processInput;
22507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022508 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022509 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022510 struct android_poll_source *source;
22511 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022512 if (source) {
22513 source->process(app, source);
22514 }
22515
22516 if (app->destroyRequested != 0) {
22517 VkTestFramework::Finish();
22518 return;
22519 }
22520 }
22521
22522 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022523 // Use the following key to send arguments to gtest, i.e.
22524 // --es args "--gtest_filter=-VkLayerTest.foo"
22525 const char key[] = "args";
22526 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022528 std::string filter = "";
22529 if (args.size() > 0) {
22530 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22531 filter += args[0];
22532 } else {
22533 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22534 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022535
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022536 int argc = 2;
22537 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22538 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022540 // Route output to files until we can override the gtest output
22541 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22542 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022544 ::testing::InitGoogleTest(&argc, argv);
22545 VkTestFramework::InitArgs(&argc, argv);
22546 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022548 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022550 if (result != 0) {
22551 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22552 } else {
22553 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22554 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022556 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022558 fclose(stdout);
22559 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022561 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022562 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022563 }
22564 }
22565}
22566#endif
22567
Tony Barbour300a6082015-04-07 13:44:53 -060022568int main(int argc, char **argv) {
22569 int result;
22570
Cody Northrop8e54a402016-03-08 22:25:52 -070022571#ifdef ANDROID
22572 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022573 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022574#endif
22575
Tony Barbour300a6082015-04-07 13:44:53 -060022576 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022577 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022578
22579 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22580
22581 result = RUN_ALL_TESTS();
22582
Tony Barbour6918cd52015-04-09 12:58:51 -060022583 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022584 return result;
22585}