blob: 9f80e6579cc71173ae3fa593248d85fcb56799a3 [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) {
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700232 other_messages_.push_back(errorString);
233 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600234 }
235
Dave Houltonfbf52152017-01-06 12:55:29 -0700236 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600237 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600238 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600239
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700240 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600241
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700242 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600243
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700244 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700245
246 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600247
Jeremy Hayes47acaac2017-03-15 13:36:03 -0600248 void ReportUnexpectedErrors(void) const {
249 if (other_messages_.size() > 0) {
250 cout << "Unexpected error messages logged for this test are:" << endl;
251 for (auto const &msg : other_messages_) {
252 ADD_FAILURE() << " " << msg;
Tony Barbour59b42282016-11-03 13:31:28 -0600253 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600254 }
255 }
256
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600257 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200258
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600259 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700260 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Match ANY message matching specified type
262 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700263 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200264 }
265
266 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600267 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700268 if (!AllDesiredMsgsFound()) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700269 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700270 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700273 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600274 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200275 }
Jeremy Hayes47acaac2017-03-15 13:36:03 -0600276
277 ReportUnexpectedErrors();
278
Dave Houltonfbf52152017-01-06 12:55:29 -0700279 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
281
282 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600283 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700284 if (AnyDesiredMsgFound()) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700285 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700286 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600287 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200288 }
Jeremy Hayes47acaac2017-03-15 13:36:03 -0600289
290 ReportUnexpectedErrors();
291
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tobin Ehliscdf95132017-03-15 13:50:56 -0600358 bool m_enable_maintenance1_ext = false;
Tony Barbour300a6082015-04-07 13:44:53 -0600359
360 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600361 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600362 std::vector<const char *> instance_extension_names;
363 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600364
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700365 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600366 /*
367 * Since CreateDbgMsgCallback is an instance level extension call
368 * any extension / layer that utilizes that feature also needs
369 * to be enabled at create instance time.
370 */
Karl Schultz6addd812016-02-02 17:17:23 -0700371 // Use Threading layer first to protect others from
372 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700373 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600374 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800375 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700376 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600377 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700378 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600379
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 if (m_enableWSI) {
381 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
382 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
383#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
384#if defined(VK_USE_PLATFORM_ANDROID_KHR)
385 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700386#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600387#if defined(VK_USE_PLATFORM_MIR_KHR)
388 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700389#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
391 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700392#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600393#if defined(VK_USE_PLATFORM_WIN32_KHR)
394 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395#endif // VK_USE_PLATFORM_WIN32_KHR
396#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600397#if defined(VK_USE_PLATFORM_XCB_KHR)
398 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
399#elif defined(VK_USE_PLATFORM_XLIB_KHR)
400 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700401#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600402 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600403 if (m_enable_maintenance1_ext) {
404 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
405 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600406
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600407 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600408 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 this->app_info.pApplicationName = "layer_tests";
410 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600411 this->app_info.pEngineName = "unittest";
412 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600413 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600414
Tony Barbour15524c32015-04-29 17:34:29 -0600415 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600417 }
418
419 virtual void TearDown() {
420 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600421 ShutdownFramework();
Jeremy Hayes47acaac2017-03-15 13:36:03 -0600422
423 // Shutting down the framework may have triggered some unexpected errors. Let's check one last time before we destroy the
424 // error monitor.
425 m_errorMonitor->ReportUnexpectedErrors();
426
Tony Barbour0b4d9562015-04-09 10:48:04 -0600427 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600428 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600429
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600430 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600431};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500432
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600433void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500434 // Create identity matrix
435 int i;
436 struct vktriangle_vs_uniform data;
437
438 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700439 glm::mat4 View = glm::mat4(1.0f);
440 glm::mat4 Model = glm::mat4(1.0f);
441 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500442 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700443 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 memcpy(&data.mvp, &MVP[0][0], matrixSize);
446
Karl Schultz6addd812016-02-02 17:17:23 -0700447 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600448 {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 -0500449 };
450
Karl Schultz6addd812016-02-02 17:17:23 -0700451 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500452 data.position[i][0] = tri_data[i].posX;
453 data.position[i][1] = tri_data[i].posY;
454 data.position[i][2] = tri_data[i].posZ;
455 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700456 data.color[i][0] = tri_data[i].r;
457 data.color[i][1] = tri_data[i].g;
458 data.color[i][2] = tri_data[i].b;
459 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460 }
461
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500462 ASSERT_NO_FATAL_FAILURE(InitViewport());
463
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200464 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
465 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500466
Karl Schultz6addd812016-02-02 17:17:23 -0700467 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500469
470 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800471 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500472 pipelineobj.AddShader(&vs);
473 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600474 if (failMask & BsoFailLineWidth) {
475 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600477 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
479 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600480 }
481 if (failMask & BsoFailDepthBias) {
482 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600483 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600484 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600485 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600486 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600487 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600488 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700489 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700490 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600491 if (failMask & BsoFailViewport) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
493 }
494 if (failMask & BsoFailScissor) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
496 }
497 if (failMask & BsoFailBlend) {
498 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600499 VkPipelineColorBlendAttachmentState att_state = {};
500 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
501 att_state.blendEnable = VK_TRUE;
502 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 }
504 if (failMask & BsoFailDepthBounds) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
506 }
507 if (failMask & BsoFailStencilReadMask) {
508 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
509 }
510 if (failMask & BsoFailStencilWriteMask) {
511 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
512 }
513 if (failMask & BsoFailStencilReference) {
514 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
515 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600518 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500519
520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700521 m_commandBuffer->BeginCommandBuffer();
522 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
526 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600527 if (failMask & BsoFailIndexBuffer) {
528 // Use DrawIndexed w/o an index buffer bound
529 DrawIndexed(3, 1, 0, 0, 0);
530 } else {
531 Draw(3, 1, 0, 0);
532 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533
Mark Muellerd4914412016-06-13 17:52:06 -0600534 if (failMask & BsoFailCmdClearAttachments) {
535 VkClearAttachment color_attachment = {};
536 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700537 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600538 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600541 }
542
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500543 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700544 m_commandBuffer->EndRenderPass();
545 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600546 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500547}
548
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
550 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500551 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500553 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600554 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500555 }
556
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800557 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700558 // Make sure depthWriteEnable is set so that Depth fail test will work
559 // correctly
560 // Make sure stencilTestEnable is set so that Stencil fail test will work
561 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600562 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800563 stencil.failOp = VK_STENCIL_OP_KEEP;
564 stencil.passOp = VK_STENCIL_OP_KEEP;
565 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
566 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600567
568 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
569 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600570 ds_ci.pNext = NULL;
571 ds_ci.depthTestEnable = VK_FALSE;
572 ds_ci.depthWriteEnable = VK_TRUE;
573 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
574 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600575 if (failMask & BsoFailDepthBounds) {
576 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600577 ds_ci.maxDepthBounds = 0.0f;
578 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600579 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600580 ds_ci.stencilTestEnable = VK_TRUE;
581 ds_ci.front = stencil;
582 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600583
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600584 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600585 pipelineobj.SetViewport(m_viewports);
586 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800587 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600588 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600589 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800590 commandBuffer->BindPipeline(pipelineobj);
591 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500592}
593
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600594class VkMaintenance1LayerTest : public VkLayerTest {
595 public:
596 protected:
597 VkMaintenance1LayerTest(){ m_enable_maintenance1_ext = true; }
598};
599
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600600class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700601 public:
602 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600603};
604
Ian Elliott2c1daf52016-05-12 09:41:46 -0600605class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700606 public:
607 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600608 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600609};
610
Mark Muellerdfe37552016-07-07 14:47:42 -0600611class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700612 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600613 enum eTestEnFlags {
614 eDoubleDelete,
615 eInvalidDeviceOffset,
616 eInvalidMemoryOffset,
617 eBindNullBuffer,
618 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600619 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 };
621
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
625 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600626 return true;
627 }
628 VkDeviceSize offset_limit = 0;
629 if (eInvalidMemoryOffset == aTestFlag) {
630 VkBuffer vulkanBuffer;
631 VkBufferCreateInfo buffer_create_info = {};
632 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
633 buffer_create_info.size = 32;
634 buffer_create_info.usage = aBufferUsage;
635
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600636 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600637 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600638
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600639 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600640 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
641 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
643 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600644 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600646 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600648 }
649 if (eOffsetAlignment < offset_limit) {
650 return true;
651 }
652 return false;
653 }
654
655 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
657 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 if (eBindNullBuffer == aTestFlag) {
659 VulkanMemory = 0;
660 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
661 } else {
662 VkBufferCreateInfo buffer_create_info = {};
663 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
664 buffer_create_info.size = 32;
665 buffer_create_info.usage = aBufferUsage;
666
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 CreateCurrent = true;
670
671 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600673
674 VkMemoryAllocateInfo memory_allocate_info = {};
675 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800676 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600677 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
678 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600679 if (!pass) {
680 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
681 return;
682 }
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 AllocateCurrent = true;
686 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
688 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600689 BoundCurrent = true;
690
691 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
692 }
693 }
694
695 ~VkBufferTest() {
696 if (CreateCurrent) {
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699 if (AllocateCurrent) {
700 if (InvalidDeleteEn) {
701 union {
702 VkDeviceMemory device_memory;
703 unsigned long long index_access;
704 } bad_index;
705
706 bad_index.device_memory = VulkanMemory;
707 bad_index.index_access++;
708
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600709 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600710 }
711 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
712 }
713 }
714
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600716
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600718
719 void TestDoubleDestroy() {
720 // Destroy the buffer but leave the flag set, which will cause
721 // the buffer to be destroyed again in the destructor.
722 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
723 }
724
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600726 bool AllocateCurrent;
727 bool BoundCurrent;
728 bool CreateCurrent;
729 bool InvalidDeleteEn;
730
731 VkBuffer VulkanBuffer;
732 VkDevice VulkanDevice;
733 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600734};
735
736class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700737 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600738 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700740 : BoundCurrent(false),
741 AttributeCount(aAttributeCount),
742 BindingCount(aBindingCount),
743 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600745 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
746 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700747 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600748
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600749 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
750 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600751
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600752 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
753 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
754 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
755 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
756 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757
758 unsigned i = 0;
759 do {
760 VertexInputAttributeDescription[i].binding = BindId;
761 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
763 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 i++;
765 } while (AttributeCount < i);
766
767 i = 0;
768 do {
769 VertexInputBindingDescription[i].binding = BindId;
770 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600772 i++;
773 } while (BindingCount < i);
774 }
775
776 ~VkVerticesObj() {
777 if (VertexInputAttributeDescription) {
778 delete[] VertexInputAttributeDescription;
779 }
780 if (VertexInputBindingDescription) {
781 delete[] VertexInputBindingDescription;
782 }
783 }
784
785 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
787 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600788 return true;
789 }
790
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600791 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600792 VkDeviceSize *offsetList;
793 unsigned offsetCount;
794
795 if (aOffsetCount) {
796 offsetList = aOffsetList;
797 offsetCount = aOffsetCount;
798 } else {
799 offsetList = new VkDeviceSize[1]();
800 offsetCount = 1;
801 }
802
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600803 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600804 BoundCurrent = true;
805
806 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600807 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600808 }
809 }
810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700811 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600812 static uint32_t BindIdGenerator;
813
814 bool BoundCurrent;
815 unsigned AttributeCount;
816 unsigned BindingCount;
817 uint32_t BindId;
818
819 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
820 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
821 VkVertexInputBindingDescription *VertexInputBindingDescription;
822 VkConstantBufferObj VulkanMemoryBuffer;
823};
824
825uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500826// ********************************************************************************************************************
827// ********************************************************************************************************************
828// ********************************************************************************************************************
829// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600830TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700831 TEST_DESCRIPTION(
832 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
833 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834
835 ASSERT_NO_FATAL_FAILURE(InitState());
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600838 // Specify NULL for a pointer to a handle
839 // Expected to trigger an error with
840 // parameter_validation::validate_required_pointer
841 vkGetPhysicalDeviceFeatures(gpu(), NULL);
842 m_errorMonitor->VerifyFound();
843
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
845 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600846 // Specify NULL for pointer to array count
847 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600848 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600849 m_errorMonitor->VerifyFound();
850
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600852 // Specify 0 for a required array count
853 // Expected to trigger an error with parameter_validation::validate_array
854 VkViewport view_port = {};
855 m_commandBuffer->SetViewport(0, 0, &view_port);
856 m_errorMonitor->VerifyFound();
857
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600859 // Specify NULL for a required array
860 // Expected to trigger an error with parameter_validation::validate_array
861 m_commandBuffer->SetViewport(0, 1, NULL);
862 m_errorMonitor->VerifyFound();
863
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600865 // Specify VK_NULL_HANDLE for a required handle
866 // Expected to trigger an error with
867 // parameter_validation::validate_required_handle
868 vkUnmapMemory(device(), VK_NULL_HANDLE);
869 m_errorMonitor->VerifyFound();
870
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
872 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600873 // Specify VK_NULL_HANDLE for a required handle array entry
874 // Expected to trigger an error with
875 // parameter_validation::validate_required_handle_array
876 VkFence fence = VK_NULL_HANDLE;
877 vkResetFences(device(), 1, &fence);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600881 // Specify NULL for a required struct pointer
882 // Expected to trigger an error with
883 // parameter_validation::validate_struct_type
884 VkDeviceMemory memory = VK_NULL_HANDLE;
885 vkAllocateMemory(device(), NULL, NULL, &memory);
886 m_errorMonitor->VerifyFound();
887
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600889 // Specify 0 for a required VkFlags parameter
890 // Expected to trigger an error with parameter_validation::validate_flags
891 m_commandBuffer->SetStencilReference(0, 0);
892 m_errorMonitor->VerifyFound();
893
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600894 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 -0600895 // Specify 0 for a required VkFlags array entry
896 // Expected to trigger an error with
897 // parameter_validation::validate_flags_array
898 VkSemaphore semaphore = VK_NULL_HANDLE;
899 VkPipelineStageFlags stageFlags = 0;
900 VkSubmitInfo submitInfo = {};
901 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
902 submitInfo.waitSemaphoreCount = 1;
903 submitInfo.pWaitSemaphores = &semaphore;
904 submitInfo.pWaitDstStageMask = &stageFlags;
905 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
906 m_errorMonitor->VerifyFound();
907}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600908
Dustin Gravesfce74c02016-05-10 11:42:58 -0600909TEST_F(VkLayerTest, ReservedParameter) {
910 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
911
912 ASSERT_NO_FATAL_FAILURE(InitState());
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600915 // Specify 0 for a reserved VkFlags parameter
916 // Expected to trigger an error with
917 // parameter_validation::validate_reserved_flags
918 VkEvent event_handle = VK_NULL_HANDLE;
919 VkEventCreateInfo event_info = {};
920 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
921 event_info.flags = 1;
922 vkCreateEvent(device(), &event_info, NULL, &event_handle);
923 m_errorMonitor->VerifyFound();
924}
925
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700927 TEST_DESCRIPTION(
928 "Specify an invalid VkStructureType for a Vulkan "
929 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600930
931 ASSERT_NO_FATAL_FAILURE(InitState());
932
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600934 // Zero struct memory, effectively setting sType to
935 // VK_STRUCTURE_TYPE_APPLICATION_INFO
936 // Expected to trigger an error with
937 // parameter_validation::validate_struct_type
938 VkMemoryAllocateInfo alloc_info = {};
939 VkDeviceMemory memory = VK_NULL_HANDLE;
940 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
941 m_errorMonitor->VerifyFound();
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600944 // Zero struct memory, effectively setting sType to
945 // VK_STRUCTURE_TYPE_APPLICATION_INFO
946 // Expected to trigger an error with
947 // parameter_validation::validate_struct_type_array
948 VkSubmitInfo submit_info = {};
949 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
950 m_errorMonitor->VerifyFound();
951}
952
953TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600954 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600959 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600960 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600962 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600963 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600964 // Zero-initialization will provide the correct sType
965 VkApplicationInfo app_info = {};
966 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
967 event_alloc_info.pNext = &app_info;
968 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
972 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600973 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
974 // a function that has allowed pNext structure types and specify
975 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600976 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600977 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600978 VkMemoryAllocateInfo memory_alloc_info = {};
979 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
980 memory_alloc_info.pNext = &app_info;
981 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600982 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600983}
Dustin Graves5d33d532016-05-09 16:21:12 -0600984
985TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987
988 ASSERT_NO_FATAL_FAILURE(InitState());
989
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
991 "does not fall within the begin..end "
992 "range of the core VkFormat "
993 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkFormat value
995 // Expected to trigger an error with
996 // parameter_validation::validate_ranged_enum
997 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600998 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600999 m_errorMonitor->VerifyFound();
1000
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001001 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 -06001002 // Specify an invalid VkFlags bitmask value
1003 // Expected to trigger an error with parameter_validation::validate_flags
1004 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001005 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1006 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001007 m_errorMonitor->VerifyFound();
1008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 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 -06001010 // Specify an invalid VkFlags array entry
1011 // Expected to trigger an error with
1012 // parameter_validation::validate_flags_array
1013 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001015 VkSubmitInfo submit_info = {};
1016 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1017 submit_info.waitSemaphoreCount = 1;
1018 submit_info.pWaitSemaphores = &semaphore;
1019 submit_info.pWaitDstStageMask = &stage_flags;
1020 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1021 m_errorMonitor->VerifyFound();
1022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001024 // Specify an invalid VkBool32 value
1025 // Expected to trigger a warning with
1026 // parameter_validation::validate_bool32
1027 VkSampler sampler = VK_NULL_HANDLE;
1028 VkSamplerCreateInfo sampler_info = {};
1029 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1030 sampler_info.pNext = NULL;
1031 sampler_info.magFilter = VK_FILTER_NEAREST;
1032 sampler_info.minFilter = VK_FILTER_NEAREST;
1033 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1034 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1035 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1036 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1037 sampler_info.mipLodBias = 1.0;
1038 sampler_info.maxAnisotropy = 1;
1039 sampler_info.compareEnable = VK_FALSE;
1040 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1041 sampler_info.minLod = 1.0;
1042 sampler_info.maxLod = 1.0;
1043 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1044 sampler_info.unnormalizedCoordinates = VK_FALSE;
1045 // Not VK_TRUE or VK_FALSE
1046 sampler_info.anisotropyEnable = 3;
1047 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1048 m_errorMonitor->VerifyFound();
1049}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050
1051TEST_F(VkLayerTest, FailedReturnValue) {
1052 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1053
1054 ASSERT_NO_FATAL_FAILURE(InitState());
1055
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001056 // Find an unsupported image format
1057 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1058 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1059 VkFormat format = static_cast<VkFormat>(f);
1060 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001061 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 unsupported = format;
1063 break;
1064 }
1065 }
1066
1067 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1069 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001070 // Specify an unsupported VkFormat value to generate a
1071 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1072 // Expected to trigger a warning from
1073 // parameter_validation::validate_result
1074 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1076 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001077 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1078 m_errorMonitor->VerifyFound();
1079 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001080}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001081
1082TEST_F(VkLayerTest, UpdateBufferAlignment) {
1083 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085
1086 ASSERT_NO_FATAL_FAILURE(InitState());
1087
1088 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1089 vk_testing::Buffer buffer;
1090 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1091
Tony Barbour552f6c02016-12-21 14:34:07 -07001092 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001093 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001100 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1101 m_errorMonitor->VerifyFound();
1102
1103 // Introduce failure by using dataSize that is < 0
1104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using dataSize that is > 65536
1110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001111 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001112 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1113 m_errorMonitor->VerifyFound();
1114
Tony Barbour552f6c02016-12-21 14:34:07 -07001115 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116}
1117
1118TEST_F(VkLayerTest, FillBufferAlignment) {
1119 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1120
1121 ASSERT_NO_FATAL_FAILURE(InitState());
1122
1123 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1124 vk_testing::Buffer buffer;
1125 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1126
Tony Barbour552f6c02016-12-21 14:34:07 -07001127 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001128
1129 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1132 m_errorMonitor->VerifyFound();
1133
1134 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001136 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1137 m_errorMonitor->VerifyFound();
1138
1139 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001141 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1142 m_errorMonitor->VerifyFound();
1143
Tony Barbour552f6c02016-12-21 14:34:07 -07001144 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001145}
Dustin Graves40f35822016-06-23 11:12:53 -06001146
Cortd889ff92016-07-27 09:51:27 -07001147TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1148 VkResult err;
1149
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001150 TEST_DESCRIPTION(
1151 "Attempt to use a non-solid polygon fill mode in a "
1152 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001153
1154 ASSERT_NO_FATAL_FAILURE(InitState());
1155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1156
1157 std::vector<const char *> device_extension_names;
1158 auto features = m_device->phy().features();
1159 // Artificially disable support for non-solid fill modes
1160 features.fillModeNonSolid = false;
1161 // The sacrificial device object
1162 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1163
1164 VkRenderpassObj render_pass(&test_device);
1165
1166 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1167 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1168 pipeline_layout_ci.setLayoutCount = 0;
1169 pipeline_layout_ci.pSetLayouts = NULL;
1170
1171 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001172 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001173 ASSERT_VK_SUCCESS(err);
1174
1175 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1176 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1177 rs_ci.pNext = nullptr;
1178 rs_ci.lineWidth = 1.0f;
1179 rs_ci.rasterizerDiscardEnable = true;
1180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1182 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001183
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001184 // Set polygonMode to unsupported value POINT, 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_POINT;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
1199 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1201 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001202 {
1203 VkPipelineObj pipe(&test_device);
1204 pipe.AddShader(&vs);
1205 pipe.AddShader(&fs);
1206 pipe.AddColorAttachment();
1207 // Introduce failure by setting unsupported polygon mode
1208 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1209 pipe.SetRasterization(&rs_ci);
1210 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1211 }
1212 m_errorMonitor->VerifyFound();
1213
Cortd889ff92016-07-27 09:51:27 -07001214 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1215}
1216
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001217#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001218TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001219{
1220 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001221 VkFenceCreateInfo fenceInfo = {};
1222 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1223 fenceInfo.pNext = NULL;
1224 fenceInfo.flags = 0;
1225
Mike Weiblencce7ec72016-10-17 19:33:05 -06001226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001229
1230 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1231 vk_testing::Buffer buffer;
1232 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233
Tony Barbourfe3351b2015-07-28 10:17:20 -06001234 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001235 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001236 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237
1238 testFence.init(*m_device, fenceInfo);
1239
1240 // Bypass framework since it does the waits automatically
1241 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001242 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001243 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1244 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001245 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001246 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001247 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001248 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001250 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001251 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001252
1253 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254 ASSERT_VK_SUCCESS( err );
1255
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001256 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001258
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001259 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001260}
1261
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001263{
1264 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001265 VkFenceCreateInfo fenceInfo = {};
1266 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1267 fenceInfo.pNext = NULL;
1268 fenceInfo.flags = 0;
1269
Mike Weiblencce7ec72016-10-17 19:33:05 -06001270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001271
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001272 ASSERT_NO_FATAL_FAILURE(InitState());
1273 ASSERT_NO_FATAL_FAILURE(InitViewport());
1274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1275
Tony Barbourfe3351b2015-07-28 10:17:20 -06001276 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001277 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001278 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001279
1280 testFence.init(*m_device, fenceInfo);
1281
1282 // Bypass framework since it does the waits automatically
1283 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001284 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001285 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1286 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001287 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001288 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001289 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001290 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001291 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001292 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001293 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001294
1295 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296 ASSERT_VK_SUCCESS( err );
1297
Jon Ashburnf19916e2016-01-11 13:12:43 -07001298 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001299 VkCommandBufferBeginInfo info = {};
1300 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1301 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001302 info.renderPass = VK_NULL_HANDLE;
1303 info.subpass = 0;
1304 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001305 info.occlusionQueryEnable = VK_FALSE;
1306 info.queryFlags = 0;
1307 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001308
1309 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001310 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001312 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001313}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001314#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001315
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001316TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1317 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1318
1319 ASSERT_NO_FATAL_FAILURE(InitState());
1320
1321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1322 VkBuffer buffer;
1323 VkBufferCreateInfo buf_info = {};
1324 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1325 buf_info.pNext = NULL;
1326 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1327 buf_info.size = 2048;
1328 buf_info.queueFamilyIndexCount = 0;
1329 buf_info.pQueueFamilyIndices = NULL;
1330 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1331 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1332 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1333 m_errorMonitor->VerifyFound();
1334
1335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1336 VkImage image;
1337 VkImageCreateInfo image_create_info = {};
1338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1339 image_create_info.pNext = NULL;
1340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1341 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1342 image_create_info.extent.width = 512;
1343 image_create_info.extent.height = 64;
1344 image_create_info.extent.depth = 1;
1345 image_create_info.mipLevels = 1;
1346 image_create_info.arrayLayers = 1;
1347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1348 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1349 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1350 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1351 image_create_info.queueFamilyIndexCount = 0;
1352 image_create_info.pQueueFamilyIndices = NULL;
1353 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1354 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1355 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1356 m_errorMonitor->VerifyFound();
1357}
1358
Dave Houlton829c0d82017-01-24 15:09:17 -07001359TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1360 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1361
1362 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001363 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001364 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1365
1366 // Mask out device features we don't want
1367 VkPhysicalDeviceFeatures desired_features = available_features;
1368 desired_features.sparseResidencyImage2D = VK_FALSE;
1369 desired_features.sparseResidencyImage3D = VK_FALSE;
1370 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1371
1372 VkImage image = VK_NULL_HANDLE;
1373 VkResult result = VK_RESULT_MAX_ENUM;
1374 VkImageCreateInfo image_create_info = {};
1375 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1376 image_create_info.pNext = NULL;
1377 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1378 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1379 image_create_info.extent.width = 512;
1380 image_create_info.extent.height = 1;
1381 image_create_info.extent.depth = 1;
1382 image_create_info.mipLevels = 1;
1383 image_create_info.arrayLayers = 1;
1384 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1385 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1386 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1387 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1388 image_create_info.queueFamilyIndexCount = 0;
1389 image_create_info.pQueueFamilyIndices = NULL;
1390 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1391 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1392
1393 // 1D image w/ sparse residency is an error
1394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1395 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1396 m_errorMonitor->VerifyFound();
1397 if (VK_SUCCESS == result) {
1398 vkDestroyImage(m_device->device(), image, NULL);
1399 image = VK_NULL_HANDLE;
1400 }
1401
1402 // 2D image w/ sparse residency when feature isn't available
1403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1404 image_create_info.extent.height = 64;
1405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1406 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1407 m_errorMonitor->VerifyFound();
1408 if (VK_SUCCESS == result) {
1409 vkDestroyImage(m_device->device(), image, NULL);
1410 image = VK_NULL_HANDLE;
1411 }
1412
1413 // 3D image w/ sparse residency when feature isn't available
1414 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1415 image_create_info.extent.depth = 8;
1416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1417 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1418 m_errorMonitor->VerifyFound();
1419 if (VK_SUCCESS == result) {
1420 vkDestroyImage(m_device->device(), image, NULL);
1421 image = VK_NULL_HANDLE;
1422 }
1423}
1424
1425TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1426 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1427
1428 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001429 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001430 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1431
1432 // These tests all require that the device support sparse residency for 2D images
1433 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1434 return;
1435 }
1436
1437 // Mask out device features we don't want
1438 VkPhysicalDeviceFeatures desired_features = available_features;
1439 desired_features.sparseResidency2Samples = VK_FALSE;
1440 desired_features.sparseResidency4Samples = VK_FALSE;
1441 desired_features.sparseResidency8Samples = VK_FALSE;
1442 desired_features.sparseResidency16Samples = VK_FALSE;
1443 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1444
1445 VkImage image = VK_NULL_HANDLE;
1446 VkResult result = VK_RESULT_MAX_ENUM;
1447 VkImageCreateInfo image_create_info = {};
1448 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1449 image_create_info.pNext = NULL;
1450 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1451 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1452 image_create_info.extent.width = 64;
1453 image_create_info.extent.height = 64;
1454 image_create_info.extent.depth = 1;
1455 image_create_info.mipLevels = 1;
1456 image_create_info.arrayLayers = 1;
1457 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1458 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1459 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1460 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1461 image_create_info.queueFamilyIndexCount = 0;
1462 image_create_info.pQueueFamilyIndices = NULL;
1463 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1464 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1465
1466 // 2D image w/ sparse residency and linear tiling is an error
1467 m_errorMonitor->SetDesiredFailureMsg(
1468 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1469 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1470 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1471 m_errorMonitor->VerifyFound();
1472 if (VK_SUCCESS == result) {
1473 vkDestroyImage(m_device->device(), image, NULL);
1474 image = VK_NULL_HANDLE;
1475 }
1476 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1477
1478 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1479 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1481 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1482 m_errorMonitor->VerifyFound();
1483 if (VK_SUCCESS == result) {
1484 vkDestroyImage(m_device->device(), image, NULL);
1485 image = VK_NULL_HANDLE;
1486 }
1487
1488 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1490 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1491 m_errorMonitor->VerifyFound();
1492 if (VK_SUCCESS == result) {
1493 vkDestroyImage(m_device->device(), image, NULL);
1494 image = VK_NULL_HANDLE;
1495 }
1496
1497 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1499 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1500 m_errorMonitor->VerifyFound();
1501 if (VK_SUCCESS == result) {
1502 vkDestroyImage(m_device->device(), image, NULL);
1503 image = VK_NULL_HANDLE;
1504 }
1505
1506 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1508 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1509 m_errorMonitor->VerifyFound();
1510 if (VK_SUCCESS == result) {
1511 vkDestroyImage(m_device->device(), image, NULL);
1512 image = VK_NULL_HANDLE;
1513 }
1514}
1515
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001517 TEST_DESCRIPTION(
1518 "Create a buffer and image, allocate memory, and bind the "
1519 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001520 VkResult err;
1521 bool pass;
1522 ASSERT_NO_FATAL_FAILURE(InitState());
1523
Tobin Ehlis077ded32016-05-12 17:39:13 -06001524 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001525 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001526 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001527 VkDeviceMemory mem; // buffer will be bound first
1528 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001530 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001531
1532 VkBufferCreateInfo buf_info = {};
1533 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1534 buf_info.pNext = NULL;
1535 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1536 buf_info.size = 256;
1537 buf_info.queueFamilyIndexCount = 0;
1538 buf_info.pQueueFamilyIndices = NULL;
1539 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1540 buf_info.flags = 0;
1541 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1542 ASSERT_VK_SUCCESS(err);
1543
Tobin Ehlis077ded32016-05-12 17:39:13 -06001544 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001545
1546 VkImageCreateInfo image_create_info = {};
1547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1548 image_create_info.pNext = NULL;
1549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1550 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1551 image_create_info.extent.width = 64;
1552 image_create_info.extent.height = 64;
1553 image_create_info.extent.depth = 1;
1554 image_create_info.mipLevels = 1;
1555 image_create_info.arrayLayers = 1;
1556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001557 // Image tiling must be optimal to trigger error when aliasing linear buffer
1558 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001559 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1560 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1561 image_create_info.queueFamilyIndexCount = 0;
1562 image_create_info.pQueueFamilyIndices = NULL;
1563 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1564 image_create_info.flags = 0;
1565
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1567 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001568 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1569 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570
Tobin Ehlis077ded32016-05-12 17:39:13 -06001571 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1572
1573 VkMemoryAllocateInfo alloc_info = {};
1574 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1575 alloc_info.pNext = NULL;
1576 alloc_info.memoryTypeIndex = 0;
1577 // Ensure memory is big enough for both bindings
1578 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001579 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1580 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001583 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001584 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001585 return;
1586 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001587 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1588 ASSERT_VK_SUCCESS(err);
1589 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1590 ASSERT_VK_SUCCESS(err);
1591
Rene Lindsayd14f5572016-12-16 14:57:18 -07001592 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1593
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001595 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001596 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1597 m_errorMonitor->VerifyFound();
1598
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001599 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001600 // aliasing buffer2
1601 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1602 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001603 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1604 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001605 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001606 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001608 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001609 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001610 m_errorMonitor->VerifyFound();
1611
1612 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001613 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001614 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001615 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001616 vkFreeMemory(m_device->device(), mem, NULL);
1617 vkFreeMemory(m_device->device(), mem_img, NULL);
1618}
1619
Tobin Ehlis35372522016-05-12 08:32:31 -06001620TEST_F(VkLayerTest, InvalidMemoryMapping) {
1621 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1622 VkResult err;
1623 bool pass;
1624 ASSERT_NO_FATAL_FAILURE(InitState());
1625
1626 VkBuffer buffer;
1627 VkDeviceMemory mem;
1628 VkMemoryRequirements mem_reqs;
1629
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001630 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1631
Tobin Ehlis35372522016-05-12 08:32:31 -06001632 VkBufferCreateInfo buf_info = {};
1633 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1634 buf_info.pNext = NULL;
1635 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1636 buf_info.size = 256;
1637 buf_info.queueFamilyIndexCount = 0;
1638 buf_info.pQueueFamilyIndices = NULL;
1639 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1640 buf_info.flags = 0;
1641 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1642 ASSERT_VK_SUCCESS(err);
1643
1644 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1645 VkMemoryAllocateInfo alloc_info = {};
1646 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1647 alloc_info.pNext = NULL;
1648 alloc_info.memoryTypeIndex = 0;
1649
1650 // Ensure memory is big enough for both bindings
1651 static const VkDeviceSize allocation_size = 0x10000;
1652 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001653 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 -06001654 if (!pass) {
1655 vkDestroyBuffer(m_device->device(), buffer, NULL);
1656 return;
1657 }
1658 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1659 ASSERT_VK_SUCCESS(err);
1660
1661 uint8_t *pData;
1662 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 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 -06001664 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1665 m_errorMonitor->VerifyFound();
1666 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001668 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1670 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1671 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 m_errorMonitor->VerifyFound();
1673
1674 // Unmap the memory to avoid re-map error
1675 vkUnmapMemory(m_device->device(), mem);
1676 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1678 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1679 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 m_errorMonitor->VerifyFound();
1681 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1683 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001684 m_errorMonitor->VerifyFound();
1685 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001687 vkUnmapMemory(m_device->device(), mem);
1688 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001689
Tobin Ehlis35372522016-05-12 08:32:31 -06001690 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001691 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001692 ASSERT_VK_SUCCESS(err);
1693 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001694 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001695 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001696 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001698 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1699 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700
Tobin Ehlis35372522016-05-12 08:32:31 -06001701 // Now flush range that oversteps mapped range
1702 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001703 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001704 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001705 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1708 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1709 m_errorMonitor->VerifyFound();
1710
1711 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1712 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001713 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001714 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001715 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001716 mmr.size = VK_WHOLE_SIZE;
1717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001718 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1719 m_errorMonitor->VerifyFound();
1720
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001721#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001722 // Some platforms have an atomsize of 1 which makes the test meaningless
1723 if (atom_size > 3) {
1724 // Now with an offset NOT a multiple of the device limit
1725 vkUnmapMemory(m_device->device(), mem);
1726 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1727 ASSERT_VK_SUCCESS(err);
1728 mmr.offset = 3; // Not a multiple of atom_size
1729 mmr.size = VK_WHOLE_SIZE;
1730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1731 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1732 m_errorMonitor->VerifyFound();
1733
1734 // Now with a size NOT a multiple of the device limit
1735 vkUnmapMemory(m_device->device(), mem);
1736 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1737 ASSERT_VK_SUCCESS(err);
1738 mmr.offset = atom_size;
1739 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1741 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1742 m_errorMonitor->VerifyFound();
1743 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001744#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001745 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1746 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001747 if (!pass) {
1748 vkFreeMemory(m_device->device(), mem, NULL);
1749 vkDestroyBuffer(m_device->device(), buffer, NULL);
1750 return;
1751 }
1752 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1753 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1754
1755 vkDestroyBuffer(m_device->device(), buffer, NULL);
1756 vkFreeMemory(m_device->device(), mem, NULL);
1757}
1758
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001759#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001760TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1761 VkResult err;
1762 bool pass;
1763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001764 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1765 // following declaration (which is temporarily being moved below):
1766 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001767 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001768 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001769 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001770 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001771 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001772 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001773
1774 ASSERT_NO_FATAL_FAILURE(InitState());
1775
Ian Elliott3f06ce52016-04-29 14:46:21 -06001776#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1777#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1778 // Use the functions from the VK_KHR_android_surface extension without
1779 // enabling that extension:
1780
1781 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001782 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1784 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001785 pass = (err != VK_SUCCESS);
1786 ASSERT_TRUE(pass);
1787 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001788#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001789
Ian Elliott3f06ce52016-04-29 14:46:21 -06001790#if defined(VK_USE_PLATFORM_MIR_KHR)
1791 // Use the functions from the VK_KHR_mir_surface extension without enabling
1792 // that extension:
1793
1794 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001795 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001797 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1798 pass = (err != VK_SUCCESS);
1799 ASSERT_TRUE(pass);
1800 m_errorMonitor->VerifyFound();
1801
1802 // Tell whether an mir_connection supports presentation:
1803 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1805 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001806 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001807#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001808
Ian Elliott3f06ce52016-04-29 14:46:21 -06001809#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1810 // Use the functions from the VK_KHR_wayland_surface extension without
1811 // enabling that extension:
1812
1813 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001814 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1816 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001817 pass = (err != VK_SUCCESS);
1818 ASSERT_TRUE(pass);
1819 m_errorMonitor->VerifyFound();
1820
1821 // Tell whether an wayland_display supports presentation:
1822 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001826#endif // VK_USE_PLATFORM_WAYLAND_KHR
1827#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828
Ian Elliott3f06ce52016-04-29 14:46:21 -06001829#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1831 // TO NON-LINUX PLATFORMS:
1832 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001833 // Use the functions from the VK_KHR_win32_surface extension without
1834 // enabling that extension:
1835
1836 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001837 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1839 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001840 pass = (err != VK_SUCCESS);
1841 ASSERT_TRUE(pass);
1842 m_errorMonitor->VerifyFound();
1843
1844 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001846 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001847 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001848// Set this (for now, until all platforms are supported and tested):
1849#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001850#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001851#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1853 // TO NON-LINUX PLATFORMS:
1854 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001855#endif
1856#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001857 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1858 // that extension:
1859
1860 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001861 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001863 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1864 pass = (err != VK_SUCCESS);
1865 ASSERT_TRUE(pass);
1866 m_errorMonitor->VerifyFound();
1867
1868 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001869 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001870 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1872 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001873 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001874// Set this (for now, until all platforms are supported and tested):
1875#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001876#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001877
Ian Elliott12630812016-04-29 14:35:43 -06001878#if defined(VK_USE_PLATFORM_XLIB_KHR)
1879 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1880 // that extension:
1881
1882 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001883 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001885 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1886 pass = (err != VK_SUCCESS);
1887 ASSERT_TRUE(pass);
1888 m_errorMonitor->VerifyFound();
1889
1890 // Tell whether an Xlib VisualID supports presentation:
1891 Display *dpy = NULL;
1892 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001894 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1895 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001896// Set this (for now, until all platforms are supported and tested):
1897#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001898#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001899
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900// Use the functions from the VK_KHR_surface extension without enabling
1901// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001902
Ian Elliott489eec02016-05-05 14:12:44 -06001903#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001904 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 vkDestroySurfaceKHR(instance(), surface, NULL);
1907 m_errorMonitor->VerifyFound();
1908
1909 // Check if surface supports presentation:
1910 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001912 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1913 pass = (err != VK_SUCCESS);
1914 ASSERT_TRUE(pass);
1915 m_errorMonitor->VerifyFound();
1916
1917 // Check surface capabilities:
1918 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1920 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001921 pass = (err != VK_SUCCESS);
1922 ASSERT_TRUE(pass);
1923 m_errorMonitor->VerifyFound();
1924
1925 // Check surface formats:
1926 uint32_t format_count = 0;
1927 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1929 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001930 pass = (err != VK_SUCCESS);
1931 ASSERT_TRUE(pass);
1932 m_errorMonitor->VerifyFound();
1933
1934 // Check surface present modes:
1935 uint32_t present_mode_count = 0;
1936 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1938 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001939 pass = (err != VK_SUCCESS);
1940 ASSERT_TRUE(pass);
1941 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001942#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001943
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 // Use the functions from the VK_KHR_swapchain extension without enabling
1945 // that extension:
1946
1947 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001949 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1950 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001951 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001952 pass = (err != VK_SUCCESS);
1953 ASSERT_TRUE(pass);
1954 m_errorMonitor->VerifyFound();
1955
1956 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1958 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001959 pass = (err != VK_SUCCESS);
1960 ASSERT_TRUE(pass);
1961 m_errorMonitor->VerifyFound();
1962
Chris Forbeseb7d5502016-09-13 18:19:21 +12001963 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1964 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1965 VkFence fence;
1966 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1967
Ian Elliott1c32c772016-04-28 14:47:13 -06001968 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001970 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001971 pass = (err != VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
Chris Forbeseb7d5502016-09-13 18:19:21 +12001975 vkDestroyFence(m_device->device(), fence, nullptr);
1976
Ian Elliott1c32c772016-04-28 14:47:13 -06001977 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001978 //
1979 // NOTE: Currently can't test this because a real swapchain is needed (as
1980 // opposed to the fake one we created) in order for the layer to lookup the
1981 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001982
1983 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001985 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1986 m_errorMonitor->VerifyFound();
1987}
Chris Forbes09368e42016-10-13 11:59:22 +13001988#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001989
Karl Schultz6addd812016-02-02 17:17:23 -07001990TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1991 VkResult err;
1992 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1995 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001996
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001997 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001998
1999 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002000 VkImage image;
2001 VkDeviceMemory mem;
2002 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002003
Karl Schultz6addd812016-02-02 17:17:23 -07002004 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2005 const int32_t tex_width = 32;
2006 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002007
Tony Barboureb254902015-07-15 12:50:33 -06002008 VkImageCreateInfo image_create_info = {};
2009 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002010 image_create_info.pNext = NULL;
2011 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2012 image_create_info.format = tex_format;
2013 image_create_info.extent.width = tex_width;
2014 image_create_info.extent.height = tex_height;
2015 image_create_info.extent.depth = 1;
2016 image_create_info.mipLevels = 1;
2017 image_create_info.arrayLayers = 1;
2018 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2019 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2020 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2021 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002022 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002023
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002024 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002025 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002026 mem_alloc.pNext = NULL;
2027 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028
Chia-I Wuf7458c52015-10-26 21:10:41 +08002029 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
Karl Schultz6addd812016-02-02 17:17:23 -07002032 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002033
Mark Lobodzinski23065352015-05-29 09:32:35 -05002034 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002035
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002036 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 -07002037 if (!pass) { // If we can't find any unmappable memory this test doesn't
2038 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002039 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002040 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002042
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002043 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002044 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002045 ASSERT_VK_SUCCESS(err);
2046
2047 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002048 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002049 ASSERT_VK_SUCCESS(err);
2050
2051 // Map memory as if to initialize the image
2052 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002053 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002055 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002056
Chia-I Wuf7458c52015-10-26 21:10:41 +08002057 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002058 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002059}
2060
Karl Schultz6addd812016-02-02 17:17:23 -07002061TEST_F(VkLayerTest, RebindMemory) {
2062 VkResult err;
2063 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002066
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002067 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002068
2069 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002070 VkImage image;
2071 VkDeviceMemory mem1;
2072 VkDeviceMemory mem2;
2073 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002074
Karl Schultz6addd812016-02-02 17:17:23 -07002075 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2076 const int32_t tex_width = 32;
2077 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Tony Barboureb254902015-07-15 12:50:33 -06002079 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2081 image_create_info.pNext = NULL;
2082 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2083 image_create_info.format = tex_format;
2084 image_create_info.extent.width = tex_width;
2085 image_create_info.extent.height = tex_height;
2086 image_create_info.extent.depth = 1;
2087 image_create_info.mipLevels = 1;
2088 image_create_info.arrayLayers = 1;
2089 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2090 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2091 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2092 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002093
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002094 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002095 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2096 mem_alloc.pNext = NULL;
2097 mem_alloc.allocationSize = 0;
2098 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002099
Karl Schultz6addd812016-02-02 17:17:23 -07002100 // Introduce failure, do NOT set memProps to
2101 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002102 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002103 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002104 ASSERT_VK_SUCCESS(err);
2105
Karl Schultz6addd812016-02-02 17:17:23 -07002106 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002107
2108 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002109 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002110 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002111
2112 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002113 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002114 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002115 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116 ASSERT_VK_SUCCESS(err);
2117
2118 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002119 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002120 ASSERT_VK_SUCCESS(err);
2121
Karl Schultz6addd812016-02-02 17:17:23 -07002122 // Introduce validation failure, try to bind a different memory object to
2123 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002124 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002125
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002126 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002127
Chia-I Wuf7458c52015-10-26 21:10:41 +08002128 vkDestroyImage(m_device->device(), image, NULL);
2129 vkFreeMemory(m_device->device(), mem1, NULL);
2130 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002131}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002132
Karl Schultz6addd812016-02-02 17:17:23 -07002133TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002134 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002135
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2137 "submitted in SIGNALED state. Fences "
2138 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002139
2140 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002141 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2142 fenceInfo.pNext = NULL;
2143 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002144
Tony Barbour300a6082015-04-07 13:44:53 -06002145 ASSERT_NO_FATAL_FAILURE(InitState());
2146 ASSERT_NO_FATAL_FAILURE(InitViewport());
2147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2148
Tony Barbour552f6c02016-12-21 14:34:07 -07002149 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002150 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002151 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002152
2153 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002154
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002155 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002156 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2157 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002158 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002159 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002160 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002161 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002162 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002163 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002164 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002165
2166 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002167 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002168
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002169 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002170}
Chris Forbes4e44c912016-06-16 10:20:00 +12002171
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002173 TEST_DESCRIPTION(
2174 "Specify wrong usage for image then create conflicting view of image "
2175 "Initialize buffer with wrong usage then perform copy expecting errors "
2176 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002178
2179 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002180
Tony Barbourf887b162017-03-09 10:06:46 -07002181 auto format = find_depth_stencil_format(m_device);
2182 if (!format) {
2183 printf(" No Depth + Stencil format found. Skipped.\n");
2184 return;
2185 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002186
Tony Barbourf92621a2016-05-02 14:28:12 -06002187 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002188 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002189 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002190 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002191
Tony Barbourf92621a2016-05-02 14:28:12 -06002192 VkImageView dsv;
2193 VkImageViewCreateInfo dsvci = {};
2194 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2195 dsvci.image = image.handle();
2196 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002197 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 dsvci.subresourceRange.layerCount = 1;
2199 dsvci.subresourceRange.baseMipLevel = 0;
2200 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002201 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002202
Tony Barbourf92621a2016-05-02 14:28:12 -06002203 // Create a view with depth / stencil aspect for image with different usage
2204 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002205
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002206 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002207
2208 // Initialize buffer with TRANSFER_DST usage
2209 vk_testing::Buffer buffer;
2210 VkMemoryPropertyFlags reqs = 0;
2211 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2212 VkBufferImageCopy region = {};
2213 region.bufferRowLength = 128;
2214 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002215 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002216 region.imageSubresource.layerCount = 1;
2217 region.imageExtent.height = 16;
2218 region.imageExtent.width = 16;
2219 region.imageExtent.depth = 1;
2220
Mark Lobodzinski80871462017-02-16 10:37:27 -07002221 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002222 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002223
Chris Forbesda581202016-10-06 18:25:26 +13002224 // two separate errors from this call:
2225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002228 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2229 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002230 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002231}
Tony Barbour75d79f02016-08-30 09:39:07 -06002232
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002233TEST_F(VkLayerTest, LeakAnObject) {
2234 VkResult err;
2235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002237
2238 // Note that we have to create a new device since destroying the
2239 // framework's device causes Teardown() to fail and just calling Teardown
2240 // will destroy the errorMonitor.
2241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 ASSERT_NO_FATAL_FAILURE(InitState());
2245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002246 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002247 std::vector<VkDeviceQueueCreateInfo> queue_info;
2248 queue_info.reserve(queue_props.size());
2249 std::vector<std::vector<float>> queue_priorities;
2250 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2251 VkDeviceQueueCreateInfo qi = {};
2252 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2253 qi.pNext = NULL;
2254 qi.queueFamilyIndex = i;
2255 qi.queueCount = queue_props[i].queueCount;
2256 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2257 qi.pQueuePriorities = queue_priorities[i].data();
2258 queue_info.push_back(qi);
2259 }
2260
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002261 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002262
2263 // The sacrificial device object
2264 VkDevice testDevice;
2265 VkDeviceCreateInfo device_create_info = {};
2266 auto features = m_device->phy().features();
2267 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2268 device_create_info.pNext = NULL;
2269 device_create_info.queueCreateInfoCount = queue_info.size();
2270 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002271 device_create_info.enabledLayerCount = 0;
2272 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002273 device_create_info.pEnabledFeatures = &features;
2274 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2275 ASSERT_VK_SUCCESS(err);
2276
2277 VkFence fence;
2278 VkFenceCreateInfo fence_create_info = {};
2279 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2280 fence_create_info.pNext = NULL;
2281 fence_create_info.flags = 0;
2282 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2283 ASSERT_VK_SUCCESS(err);
2284
2285 // Induce failure by not calling vkDestroyFence
2286 vkDestroyDevice(testDevice, NULL);
2287 m_errorMonitor->VerifyFound();
2288}
2289
2290TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002291 TEST_DESCRIPTION(
2292 "Allocate command buffers from one command pool and "
2293 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296
Cody Northropc31a84f2016-08-22 10:41:47 -06002297 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298 VkCommandPool command_pool_one;
2299 VkCommandPool command_pool_two;
2300
2301 VkCommandPoolCreateInfo pool_create_info{};
2302 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2303 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2304 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002307
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002308 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002309
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002310 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002311 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002312 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002314 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002316 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002317
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002318 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002319
2320 m_errorMonitor->VerifyFound();
2321
2322 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2323 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2324}
2325
2326TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2327 VkResult err;
2328
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002329 TEST_DESCRIPTION(
2330 "Allocate descriptor sets from one DS pool and "
2331 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002334
2335 ASSERT_NO_FATAL_FAILURE(InitState());
2336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2337
2338 VkDescriptorPoolSize ds_type_count = {};
2339 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2340 ds_type_count.descriptorCount = 1;
2341
2342 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2343 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2344 ds_pool_ci.pNext = NULL;
2345 ds_pool_ci.flags = 0;
2346 ds_pool_ci.maxSets = 1;
2347 ds_pool_ci.poolSizeCount = 1;
2348 ds_pool_ci.pPoolSizes = &ds_type_count;
2349
2350 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 ASSERT_VK_SUCCESS(err);
2353
2354 // Create a second descriptor pool
2355 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002356 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002357 ASSERT_VK_SUCCESS(err);
2358
2359 VkDescriptorSetLayoutBinding dsl_binding = {};
2360 dsl_binding.binding = 0;
2361 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2362 dsl_binding.descriptorCount = 1;
2363 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2364 dsl_binding.pImmutableSamplers = NULL;
2365
2366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2368 ds_layout_ci.pNext = NULL;
2369 ds_layout_ci.bindingCount = 1;
2370 ds_layout_ci.pBindings = &dsl_binding;
2371
2372 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002374 ASSERT_VK_SUCCESS(err);
2375
2376 VkDescriptorSet descriptorSet;
2377 VkDescriptorSetAllocateInfo alloc_info = {};
2378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2379 alloc_info.descriptorSetCount = 1;
2380 alloc_info.descriptorPool = ds_pool_one;
2381 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002383 ASSERT_VK_SUCCESS(err);
2384
2385 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2386
2387 m_errorMonitor->VerifyFound();
2388
2389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2390 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2391 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2392}
2393
2394TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002396
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002397 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002398
2399 ASSERT_NO_FATAL_FAILURE(InitState());
2400
2401 // Pass bogus handle into GetImageMemoryRequirements
2402 VkMemoryRequirements mem_reqs;
2403 uint64_t fakeImageHandle = 0xCADECADE;
2404 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2405
2406 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2407
2408 m_errorMonitor->VerifyFound();
2409}
2410
Mike Schuchardt17838902017-02-21 09:48:06 -07002411TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2412 TEST_DESCRIPTION(
2413 "Try to destroy a render pass object using a device other than the one it was created on. "
2414 "This should generate a distinct error from the invalid handle error.");
2415 // Create first device and renderpass
2416 ASSERT_NO_FATAL_FAILURE(InitState());
2417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2418
2419 // Create second device
2420 float priorities[] = {1.0f};
2421 VkDeviceQueueCreateInfo queue_info{};
2422 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2423 queue_info.pNext = NULL;
2424 queue_info.flags = 0;
2425 queue_info.queueFamilyIndex = 0;
2426 queue_info.queueCount = 1;
2427 queue_info.pQueuePriorities = &priorities[0];
2428
2429 VkDeviceCreateInfo device_create_info = {};
2430 auto features = m_device->phy().features();
2431 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2432 device_create_info.pNext = NULL;
2433 device_create_info.queueCreateInfoCount = 1;
2434 device_create_info.pQueueCreateInfos = &queue_info;
2435 device_create_info.enabledLayerCount = 0;
2436 device_create_info.ppEnabledLayerNames = NULL;
2437 device_create_info.pEnabledFeatures = &features;
2438
2439 VkDevice second_device;
2440 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2441
2442 // Try to destroy the renderpass from the first device using the second device
2443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2444 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2445 m_errorMonitor->VerifyFound();
2446
2447 vkDestroyDevice(second_device, NULL);
2448}
2449
Karl Schultz6addd812016-02-02 17:17:23 -07002450TEST_F(VkLayerTest, PipelineNotBound) {
2451 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002454
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002456
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002457 ASSERT_NO_FATAL_FAILURE(InitState());
2458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002459
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002460 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002461 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2462 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002463
2464 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002465 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2466 ds_pool_ci.pNext = NULL;
2467 ds_pool_ci.maxSets = 1;
2468 ds_pool_ci.poolSizeCount = 1;
2469 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002470
2471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002473 ASSERT_VK_SUCCESS(err);
2474
2475 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002476 dsl_binding.binding = 0;
2477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2478 dsl_binding.descriptorCount = 1;
2479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2480 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002481
2482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2484 ds_layout_ci.pNext = NULL;
2485 ds_layout_ci.bindingCount = 1;
2486 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
2492 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002493 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002494 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002495 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002496 alloc_info.descriptorPool = ds_pool;
2497 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002498 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002499 ASSERT_VK_SUCCESS(err);
2500
2501 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002502 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2503 pipeline_layout_ci.pNext = NULL;
2504 pipeline_layout_ci.setLayoutCount = 1;
2505 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002506
2507 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002508 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002509 ASSERT_VK_SUCCESS(err);
2510
Mark Youngad779052016-01-06 14:26:04 -07002511 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002512
Tony Barbour552f6c02016-12-21 14:34:07 -07002513 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002514 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002515
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002516 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002517
Chia-I Wuf7458c52015-10-26 21:10:41 +08002518 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2519 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2520 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002521}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002522
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002523TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2524 VkResult err;
2525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002526 TEST_DESCRIPTION(
2527 "Test validation check for an invalid memory type index "
2528 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002529
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002530 ASSERT_NO_FATAL_FAILURE(InitState());
2531
2532 // Create an image, allocate memory, set a bad typeIndex and then try to
2533 // bind it
2534 VkImage image;
2535 VkDeviceMemory mem;
2536 VkMemoryRequirements mem_reqs;
2537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2538 const int32_t tex_width = 32;
2539 const int32_t tex_height = 32;
2540
2541 VkImageCreateInfo image_create_info = {};
2542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2543 image_create_info.pNext = NULL;
2544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2545 image_create_info.format = tex_format;
2546 image_create_info.extent.width = tex_width;
2547 image_create_info.extent.height = tex_height;
2548 image_create_info.extent.depth = 1;
2549 image_create_info.mipLevels = 1;
2550 image_create_info.arrayLayers = 1;
2551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2552 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2553 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2554 image_create_info.flags = 0;
2555
2556 VkMemoryAllocateInfo mem_alloc = {};
2557 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2558 mem_alloc.pNext = NULL;
2559 mem_alloc.allocationSize = 0;
2560 mem_alloc.memoryTypeIndex = 0;
2561
2562 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2563 ASSERT_VK_SUCCESS(err);
2564
2565 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2566 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002567
2568 // Introduce Failure, select invalid TypeIndex
2569 VkPhysicalDeviceMemoryProperties memory_info;
2570
2571 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2572 unsigned int i;
2573 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2574 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2575 mem_alloc.memoryTypeIndex = i;
2576 break;
2577 }
2578 }
2579 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002580 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002581 vkDestroyImage(m_device->device(), image, NULL);
2582 return;
2583 }
2584
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002585 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 -06002586
2587 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2588 ASSERT_VK_SUCCESS(err);
2589
2590 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2591 (void)err;
2592
2593 m_errorMonitor->VerifyFound();
2594
2595 vkDestroyImage(m_device->device(), image, NULL);
2596 vkFreeMemory(m_device->device(), mem, NULL);
2597}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002598
Karl Schultz6addd812016-02-02 17:17:23 -07002599TEST_F(VkLayerTest, BindInvalidMemory) {
2600 VkResult err;
2601 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002602
2603 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002606 const int32_t tex_width = 256;
2607 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002608
2609 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2611 image_create_info.pNext = NULL;
2612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2613 image_create_info.format = tex_format;
2614 image_create_info.extent.width = tex_width;
2615 image_create_info.extent.height = tex_height;
2616 image_create_info.extent.depth = 1;
2617 image_create_info.mipLevels = 1;
2618 image_create_info.arrayLayers = 1;
2619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002621 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2622 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002623
Cortf801b982017-01-17 18:10:21 -08002624 VkBufferCreateInfo buffer_create_info = {};
2625 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2626 buffer_create_info.pNext = NULL;
2627 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002628 buffer_create_info.size = 4 * 1024 * 1024;
2629 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002630 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002631
Cortf801b982017-01-17 18:10:21 -08002632 // Create an image/buffer, allocate memory, free it, and then try to bind it
2633 {
2634 VkImage image = VK_NULL_HANDLE;
2635 VkBuffer buffer = VK_NULL_HANDLE;
2636 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2639 ASSERT_VK_SUCCESS(err);
2640 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2641 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2642 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2645 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2646 image_mem_alloc.allocationSize = image_mem_reqs.size;
2647 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2648 ASSERT_TRUE(pass);
2649 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2650 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2651 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2652 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2655 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2656 ASSERT_VK_SUCCESS(err);
2657 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2658 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002659
Cortf801b982017-01-17 18:10:21 -08002660 vkFreeMemory(device(), image_mem, NULL);
2661 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002662
Cortf801b982017-01-17 18:10:21 -08002663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2664 err = vkBindImageMemory(device(), image, image_mem, 0);
2665 (void)err; // This may very well return an error.
2666 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002667
Cortf801b982017-01-17 18:10:21 -08002668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2669 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2670 (void)err; // This may very well return an error.
2671 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002672
Cortf801b982017-01-17 18:10:21 -08002673 vkDestroyImage(m_device->device(), image, NULL);
2674 vkDestroyBuffer(m_device->device(), buffer, NULL);
2675 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002676
2677 // Try to bind memory to an object that already has a memory binding
2678 {
2679 VkImage image = VK_NULL_HANDLE;
2680 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2681 ASSERT_VK_SUCCESS(err);
2682 VkBuffer buffer = VK_NULL_HANDLE;
2683 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2684 ASSERT_VK_SUCCESS(err);
2685 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2686 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2687 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2688 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2689 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2690 image_alloc_info.allocationSize = image_mem_reqs.size;
2691 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2692 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2693 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2694 ASSERT_TRUE(pass);
2695 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2696 ASSERT_TRUE(pass);
2697 VkDeviceMemory image_mem, buffer_mem;
2698 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2699 ASSERT_VK_SUCCESS(err);
2700 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2701 ASSERT_VK_SUCCESS(err);
2702
2703 err = vkBindImageMemory(device(), image, image_mem, 0);
2704 ASSERT_VK_SUCCESS(err);
2705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2706 err = vkBindImageMemory(device(), image, image_mem, 0);
2707 (void)err; // This may very well return an error.
2708 m_errorMonitor->VerifyFound();
2709
2710 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2711 ASSERT_VK_SUCCESS(err);
2712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2713 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2714 (void)err; // This may very well return an error.
2715 m_errorMonitor->VerifyFound();
2716
2717 vkFreeMemory(device(), image_mem, NULL);
2718 vkFreeMemory(device(), buffer_mem, NULL);
2719 vkDestroyImage(device(), image, NULL);
2720 vkDestroyBuffer(device(), buffer, NULL);
2721 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002722
Cort Strattonde748202017-02-17 12:50:01 -08002723 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002724 {
2725 VkImage image = VK_NULL_HANDLE;
2726 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2727 ASSERT_VK_SUCCESS(err);
2728 VkBuffer buffer = VK_NULL_HANDLE;
2729 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2730 ASSERT_VK_SUCCESS(err);
2731 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2732 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2733 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2734 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2735 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002736 // Leave some extra space for alignment wiggle room
2737 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002738 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002739 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002740 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2741 ASSERT_TRUE(pass);
2742 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2743 ASSERT_TRUE(pass);
2744 VkDeviceMemory image_mem, buffer_mem;
2745 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2746 ASSERT_VK_SUCCESS(err);
2747 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2748 ASSERT_VK_SUCCESS(err);
2749
Cort Strattonde748202017-02-17 12:50:01 -08002750 // Test unaligned memory offset
2751 {
2752 if (image_mem_reqs.alignment > 1) {
2753 VkDeviceSize image_offset = 1;
2754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2755 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2756 (void)err; // This may very well return an error.
2757 m_errorMonitor->VerifyFound();
2758 }
Cort6c7dff72017-01-27 18:34:50 -08002759
Cort Strattonde748202017-02-17 12:50:01 -08002760 if (buffer_mem_reqs.alignment > 1) {
2761 VkDeviceSize buffer_offset = 1;
2762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2763 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2764 (void)err; // This may very well return an error.
2765 m_errorMonitor->VerifyFound();
2766 }
2767 }
2768
2769 // Test memory offsets outside the memory allocation
2770 {
2771 VkDeviceSize image_offset =
2772 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2774 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2775 (void)err; // This may very well return an error.
2776 m_errorMonitor->VerifyFound();
2777
2778 VkDeviceSize buffer_offset =
2779 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
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
2786 // Test memory offsets within the memory allocation, but which leave too little memory for
2787 // the resource.
2788 {
2789 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2790 if (image_offset > 0) {
2791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2792 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2793 (void)err; // This may very well return an error.
2794 m_errorMonitor->VerifyFound();
2795 }
2796
2797 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2798 if (buffer_offset > 0) {
2799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2800 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2801 (void)err; // This may very well return an error.
2802 m_errorMonitor->VerifyFound();
2803 }
2804 }
Cort6c7dff72017-01-27 18:34:50 -08002805
2806 vkFreeMemory(device(), image_mem, NULL);
2807 vkFreeMemory(device(), buffer_mem, NULL);
2808 vkDestroyImage(device(), image, NULL);
2809 vkDestroyBuffer(device(), buffer, NULL);
2810 }
2811
Cort Stratton4c38bb52017-01-28 13:33:10 -08002812 // Try to bind memory to an object with an invalid memory type
2813 {
2814 VkImage image = VK_NULL_HANDLE;
2815 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2816 ASSERT_VK_SUCCESS(err);
2817 VkBuffer buffer = VK_NULL_HANDLE;
2818 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2819 ASSERT_VK_SUCCESS(err);
2820 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2821 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2822 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2823 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2824 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2825 image_alloc_info.allocationSize = image_mem_reqs.size;
2826 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2827 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002828 // Create a mask of available memory types *not* supported by these resources,
2829 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002830 VkPhysicalDeviceMemoryProperties memory_properties = {};
2831 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002832 VkDeviceMemory image_mem, buffer_mem;
2833
Cort Stratton4c38bb52017-01-28 13:33:10 -08002834 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002835 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002836 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2837 ASSERT_TRUE(pass);
2838 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2839 ASSERT_VK_SUCCESS(err);
2840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2841 err = vkBindImageMemory(device(), image, image_mem, 0);
2842 (void)err; // This may very well return an error.
2843 m_errorMonitor->VerifyFound();
2844 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002845 }
2846
Cort Stratton4c38bb52017-01-28 13:33:10 -08002847 uint32_t buffer_unsupported_mem_type_bits =
2848 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002849 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002850 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2851 ASSERT_TRUE(pass);
2852 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2853 ASSERT_VK_SUCCESS(err);
2854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2855 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2856 (void)err; // This may very well return an error.
2857 m_errorMonitor->VerifyFound();
2858 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002859 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002860
Cort Stratton4c38bb52017-01-28 13:33:10 -08002861 vkDestroyImage(device(), image, NULL);
2862 vkDestroyBuffer(device(), buffer, NULL);
2863 }
2864
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002865 // Try to bind memory to an image created with sparse memory flags
2866 {
2867 VkImageCreateInfo sparse_image_create_info = image_create_info;
2868 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2869 VkImageFormatProperties image_format_properties = {};
2870 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2871 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2872 sparse_image_create_info.usage, sparse_image_create_info.flags,
2873 &image_format_properties);
2874 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2875 // most likely means sparse formats aren't supported here; skip this test.
2876 } else {
2877 ASSERT_VK_SUCCESS(err);
2878 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002879 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002880 return;
2881 } else {
2882 VkImage sparse_image = VK_NULL_HANDLE;
2883 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2884 ASSERT_VK_SUCCESS(err);
2885 VkMemoryRequirements sparse_mem_reqs = {};
2886 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2887 if (sparse_mem_reqs.memoryTypeBits != 0) {
2888 VkMemoryAllocateInfo sparse_mem_alloc = {};
2889 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2890 sparse_mem_alloc.pNext = NULL;
2891 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2892 sparse_mem_alloc.memoryTypeIndex = 0;
2893 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2894 ASSERT_TRUE(pass);
2895 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2896 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2897 ASSERT_VK_SUCCESS(err);
2898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2899 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2900 // This may very well return an error.
2901 (void)err;
2902 m_errorMonitor->VerifyFound();
2903 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2904 }
2905 vkDestroyImage(m_device->device(), sparse_image, NULL);
2906 }
2907 }
2908 }
2909
2910 // Try to bind memory to a buffer created with sparse memory flags
2911 {
2912 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2913 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2914 if (!m_device->phy().features().sparseResidencyBuffer) {
2915 // most likely means sparse formats aren't supported here; skip this test.
2916 } else {
2917 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2918 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2919 ASSERT_VK_SUCCESS(err);
2920 VkMemoryRequirements sparse_mem_reqs = {};
2921 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2922 if (sparse_mem_reqs.memoryTypeBits != 0) {
2923 VkMemoryAllocateInfo sparse_mem_alloc = {};
2924 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2925 sparse_mem_alloc.pNext = NULL;
2926 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2927 sparse_mem_alloc.memoryTypeIndex = 0;
2928 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2929 ASSERT_TRUE(pass);
2930 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2931 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2932 ASSERT_VK_SUCCESS(err);
2933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2934 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2935 // This may very well return an error.
2936 (void)err;
2937 m_errorMonitor->VerifyFound();
2938 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2939 }
2940 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2941 }
2942 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002943}
2944
Karl Schultz6addd812016-02-02 17:17:23 -07002945TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2946 VkResult err;
2947 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002948
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002950
Tobin Ehlisec598302015-09-15 15:02:17 -06002951 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002952
Karl Schultz6addd812016-02-02 17:17:23 -07002953 // Create an image object, allocate memory, destroy the object and then try
2954 // to bind it
2955 VkImage image;
2956 VkDeviceMemory mem;
2957 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002958
Karl Schultz6addd812016-02-02 17:17:23 -07002959 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2960 const int32_t tex_width = 32;
2961 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002962
2963 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002964 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2965 image_create_info.pNext = NULL;
2966 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2967 image_create_info.format = tex_format;
2968 image_create_info.extent.width = tex_width;
2969 image_create_info.extent.height = tex_height;
2970 image_create_info.extent.depth = 1;
2971 image_create_info.mipLevels = 1;
2972 image_create_info.arrayLayers = 1;
2973 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2974 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2975 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2976 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002977
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002978 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002979 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2980 mem_alloc.pNext = NULL;
2981 mem_alloc.allocationSize = 0;
2982 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002983
Chia-I Wuf7458c52015-10-26 21:10:41 +08002984 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002985 ASSERT_VK_SUCCESS(err);
2986
Karl Schultz6addd812016-02-02 17:17:23 -07002987 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002988
2989 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002990 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002991 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002992
2993 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002994 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002995 ASSERT_VK_SUCCESS(err);
2996
2997 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002998 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002999 ASSERT_VK_SUCCESS(err);
3000
3001 // Now Try to bind memory to this destroyed object
3002 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3003 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003004 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003005
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003006 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003007
Chia-I Wuf7458c52015-10-26 21:10:41 +08003008 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003009}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003010
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003011TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3012 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3013
3014 ASSERT_NO_FATAL_FAILURE(InitState());
3015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3016
3017 VkVertexInputBindingDescription input_binding;
3018 memset(&input_binding, 0, sizeof(input_binding));
3019
3020 VkVertexInputAttributeDescription input_attribs;
3021 memset(&input_attribs, 0, sizeof(input_attribs));
3022
3023 // Pick a really bad format for this purpose and make sure it should fail
3024 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3025 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3026 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003027 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003028 return;
3029 }
3030
3031 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003032 char const *vsSource =
3033 "#version 450\n"
3034 "\n"
3035 "out gl_PerVertex {\n"
3036 " vec4 gl_Position;\n"
3037 "};\n"
3038 "void main(){\n"
3039 " gl_Position = vec4(1);\n"
3040 "}\n";
3041 char const *fsSource =
3042 "#version 450\n"
3043 "\n"
3044 "layout(location=0) out vec4 color;\n"
3045 "void main(){\n"
3046 " color = vec4(1);\n"
3047 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003048
3049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3050 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3051 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3052
3053 VkPipelineObj pipe(m_device);
3054 pipe.AddColorAttachment();
3055 pipe.AddShader(&vs);
3056 pipe.AddShader(&fs);
3057
3058 pipe.AddVertexInputBindings(&input_binding, 1);
3059 pipe.AddVertexInputAttribs(&input_attribs, 1);
3060
3061 VkDescriptorSetObj descriptorSet(m_device);
3062 descriptorSet.AppendDummy();
3063 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3064
3065 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3066
3067 m_errorMonitor->VerifyFound();
3068}
3069
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003070TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003071 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3072 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003073
3074 VkMemoryPropertyFlags reqs = 0;
3075 VkImageCreateInfo image_create_info = {};
3076 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3077 image_create_info.pNext = NULL;
3078 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3079 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3080 image_create_info.extent.width = 256;
3081 image_create_info.extent.height = 256;
3082 image_create_info.extent.depth = 1;
3083 image_create_info.mipLevels = 1;
3084 image_create_info.arrayLayers = 1;
3085 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3086 image_create_info.flags = 0;
3087
3088 VkImageBlit blit_region = {};
3089 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3090 blit_region.srcSubresource.baseArrayLayer = 0;
3091 blit_region.srcSubresource.layerCount = 1;
3092 blit_region.srcSubresource.mipLevel = 0;
3093 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3094 blit_region.dstSubresource.baseArrayLayer = 0;
3095 blit_region.dstSubresource.layerCount = 1;
3096 blit_region.dstSubresource.mipLevel = 0;
3097
3098 // Create two images, the source with sampleCount = 2, and attempt to blit
3099 // between them
3100 {
3101 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003102 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003103 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003105 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003107 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003109 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003110 m_errorMonitor->SetDesiredFailureMsg(
3111 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3112 "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 -06003113 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3114 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003115 m_errorMonitor->VerifyFound();
3116 m_commandBuffer->EndCommandBuffer();
3117 }
3118
3119 // Create two images, the dest with sampleCount = 4, and attempt to blit
3120 // between them
3121 {
3122 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003123 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003124 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003125 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003126 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003128 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003130 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003131 m_errorMonitor->SetDesiredFailureMsg(
3132 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3133 "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 -06003134 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3135 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003136 m_errorMonitor->VerifyFound();
3137 m_commandBuffer->EndCommandBuffer();
3138 }
3139
3140 VkBufferImageCopy copy_region = {};
3141 copy_region.bufferRowLength = 128;
3142 copy_region.bufferImageHeight = 128;
3143 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3144 copy_region.imageSubresource.layerCount = 1;
3145 copy_region.imageExtent.height = 64;
3146 copy_region.imageExtent.width = 64;
3147 copy_region.imageExtent.depth = 1;
3148
3149 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3150 // buffer to image
3151 {
3152 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003153 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3154 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003156 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 dst_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_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003162 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3163 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003164 m_errorMonitor->VerifyFound();
3165 m_commandBuffer->EndCommandBuffer();
3166 }
3167
3168 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3169 // image to buffer
3170 {
3171 vk_testing::Buffer dst_buffer;
3172 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3173 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003175 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003177 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003178 m_errorMonitor->SetDesiredFailureMsg(
3179 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3180 "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 -06003181 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003182 dst_buffer.handle(), 1, &copy_region);
3183 m_errorMonitor->VerifyFound();
3184 m_commandBuffer->EndCommandBuffer();
3185 }
3186}
3187
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003188TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003189 ASSERT_NO_FATAL_FAILURE(InitState());
3190
3191 VkImageObj src_image(m_device);
3192 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3193 VkImageObj dst_image(m_device);
3194 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3195 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003196 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 -06003197
3198 VkImageBlit blitRegion = {};
3199 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3200 blitRegion.srcSubresource.baseArrayLayer = 0;
3201 blitRegion.srcSubresource.layerCount = 1;
3202 blitRegion.srcSubresource.mipLevel = 0;
3203 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3204 blitRegion.dstSubresource.baseArrayLayer = 0;
3205 blitRegion.dstSubresource.layerCount = 1;
3206 blitRegion.dstSubresource.mipLevel = 0;
3207
Dave Houlton34df4cb2016-12-01 16:43:06 -07003208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3209
3210 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3211 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
3213 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003214 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003215 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3216 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003217
3218 m_errorMonitor->VerifyFound();
3219
Dave Houlton34df4cb2016-12-01 16:43:06 -07003220 // Test should generate 2 VU failures
3221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003223
3224 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003225 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3226 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003227
Dave Houlton34df4cb2016-12-01 16:43:06 -07003228 // TODO: Note that this only verifies that at least one of the VU enums was found
3229 // 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 -06003230 m_errorMonitor->VerifyFound();
3231
Tony Barbour552f6c02016-12-21 14:34:07 -07003232 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003233}
3234
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003235TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3236 VkResult err;
3237 bool pass;
3238
3239 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3240 ASSERT_NO_FATAL_FAILURE(InitState());
3241
3242 // If w/d/h granularity is 1, test is not meaningful
3243 // TODO: When virtual device limits are available, create a set of limits for this test that
3244 // will always have a granularity of > 1 for w, h, and d
3245 auto index = m_device->graphics_queue_node_index_;
3246 auto queue_family_properties = m_device->phy().queue_properties();
3247
3248 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3249 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3250 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3251 return;
3252 }
3253
3254 // Create two images of different types and try to copy between them
3255 VkImage srcImage;
3256 VkImage dstImage;
3257 VkDeviceMemory srcMem;
3258 VkDeviceMemory destMem;
3259 VkMemoryRequirements memReqs;
3260
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003261 VkImageCreateInfo image_create_info = {};
3262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3263 image_create_info.pNext = NULL;
3264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3265 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3266 image_create_info.extent.width = 32;
3267 image_create_info.extent.height = 32;
3268 image_create_info.extent.depth = 1;
3269 image_create_info.mipLevels = 1;
3270 image_create_info.arrayLayers = 4;
3271 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3273 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3274 image_create_info.flags = 0;
3275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003276 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003277 ASSERT_VK_SUCCESS(err);
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 ASSERT_VK_SUCCESS(err);
3281
3282 // Allocate memory
3283 VkMemoryAllocateInfo memAlloc = {};
3284 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3285 memAlloc.pNext = NULL;
3286 memAlloc.allocationSize = 0;
3287 memAlloc.memoryTypeIndex = 0;
3288
3289 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3290 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003291 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003292 ASSERT_TRUE(pass);
3293 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3294 ASSERT_VK_SUCCESS(err);
3295
3296 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3297 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003298 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003299 ASSERT_VK_SUCCESS(err);
3300 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3301 ASSERT_VK_SUCCESS(err);
3302
3303 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3304 ASSERT_VK_SUCCESS(err);
3305 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3306 ASSERT_VK_SUCCESS(err);
3307
Tony Barbour552f6c02016-12-21 14:34:07 -07003308 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003309 VkImageCopy copyRegion;
3310 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3311 copyRegion.srcSubresource.mipLevel = 0;
3312 copyRegion.srcSubresource.baseArrayLayer = 0;
3313 copyRegion.srcSubresource.layerCount = 1;
3314 copyRegion.srcOffset.x = 0;
3315 copyRegion.srcOffset.y = 0;
3316 copyRegion.srcOffset.z = 0;
3317 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3318 copyRegion.dstSubresource.mipLevel = 0;
3319 copyRegion.dstSubresource.baseArrayLayer = 0;
3320 copyRegion.dstSubresource.layerCount = 1;
3321 copyRegion.dstOffset.x = 0;
3322 copyRegion.dstOffset.y = 0;
3323 copyRegion.dstOffset.z = 0;
3324 copyRegion.extent.width = 1;
3325 copyRegion.extent.height = 1;
3326 copyRegion.extent.depth = 1;
3327
3328 // Introduce failure by setting srcOffset to a bad granularity value
3329 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3331 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003332 m_errorMonitor->VerifyFound();
3333
3334 // Introduce failure by setting extent to a bad granularity value
3335 copyRegion.srcOffset.y = 0;
3336 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3338 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003339 m_errorMonitor->VerifyFound();
3340
3341 // Now do some buffer/image copies
3342 vk_testing::Buffer buffer;
3343 VkMemoryPropertyFlags reqs = 0;
3344 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3345 VkBufferImageCopy region = {};
3346 region.bufferOffset = 0;
3347 region.bufferRowLength = 3;
3348 region.bufferImageHeight = 128;
3349 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3350 region.imageSubresource.layerCount = 1;
3351 region.imageExtent.height = 16;
3352 region.imageExtent.width = 16;
3353 region.imageExtent.depth = 1;
3354 region.imageOffset.x = 0;
3355 region.imageOffset.y = 0;
3356 region.imageOffset.z = 0;
3357
3358 // Introduce failure by setting bufferRowLength to a bad granularity value
3359 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3361 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3362 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003363 m_errorMonitor->VerifyFound();
3364 region.bufferRowLength = 128;
3365
3366 // Introduce failure by setting bufferOffset to a bad granularity value
3367 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3369 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3370 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003371 m_errorMonitor->VerifyFound();
3372 region.bufferOffset = 0;
3373
3374 // Introduce failure by setting bufferImageHeight to a bad granularity value
3375 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3377 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3378 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003379 m_errorMonitor->VerifyFound();
3380 region.bufferImageHeight = 128;
3381
3382 // Introduce failure by setting imageExtent to a bad granularity value
3383 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3385 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3386 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003387 m_errorMonitor->VerifyFound();
3388 region.imageExtent.width = 16;
3389
3390 // Introduce failure by setting imageOffset to a bad granularity value
3391 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3393 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3394 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003395 m_errorMonitor->VerifyFound();
3396
Tony Barbour552f6c02016-12-21 14:34:07 -07003397 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003398
3399 vkDestroyImage(m_device->device(), srcImage, NULL);
3400 vkDestroyImage(m_device->device(), dstImage, NULL);
3401 vkFreeMemory(m_device->device(), srcMem, NULL);
3402 vkFreeMemory(m_device->device(), destMem, NULL);
3403}
3404
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003405TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003406 TEST_DESCRIPTION(
3407 "Submit command buffer created using one queue family and "
3408 "attempt to submit them on a queue created in a different "
3409 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003410
Cody Northropc31a84f2016-08-22 10:41:47 -06003411 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003412
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003413 // This test is meaningless unless we have multiple queue families
3414 auto queue_family_properties = m_device->phy().queue_properties();
3415 if (queue_family_properties.size() < 2) {
3416 return;
3417 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003419 // Get safe index of another queue family
3420 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3421 ASSERT_NO_FATAL_FAILURE(InitState());
3422 // Create a second queue using a different queue family
3423 VkQueue other_queue;
3424 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3425
3426 // Record an empty cmd buffer
3427 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3428 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3429 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3430 vkEndCommandBuffer(m_commandBuffer->handle());
3431
3432 // And submit on the wrong queue
3433 VkSubmitInfo submit_info = {};
3434 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3435 submit_info.commandBufferCount = 1;
3436 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003437 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003438
3439 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003440}
3441
Chris Forbes4c24a922016-11-16 08:59:10 +13003442TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3443 ASSERT_NO_FATAL_FAILURE(InitState());
3444
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003445 // There are no attachments, but refer to attachment 0.
3446 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003447 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003448 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003449 };
3450
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003451 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003452 VkRenderPass rp;
3453
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003454 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003456 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3457 m_errorMonitor->VerifyFound();
3458}
3459
Chris Forbesa58c4522016-09-28 15:19:39 +13003460TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3461 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3462 ASSERT_NO_FATAL_FAILURE(InitState());
3463
3464 // A renderpass with two subpasses, both writing the same attachment.
3465 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003466 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3467 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3468 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003469 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003470 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003471 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003472 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3473 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003474 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003475 VkSubpassDependency dep = {0,
3476 1,
3477 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3478 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3479 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3480 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3481 VK_DEPENDENCY_BY_REGION_BIT};
3482 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003483 VkRenderPass rp;
3484 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3485 ASSERT_VK_SUCCESS(err);
3486
3487 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003488 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 +13003489 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3490
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003491 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003492 VkFramebuffer fb;
3493 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3494 ASSERT_VK_SUCCESS(err);
3495
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003496 char const *vsSource =
3497 "#version 450\n"
3498 "void main() { gl_Position = vec4(1); }\n";
3499 char const *fsSource =
3500 "#version 450\n"
3501 "layout(location=0) out vec4 color;\n"
3502 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003503
3504 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3505 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3506 VkPipelineObj pipe(m_device);
3507 pipe.AddColorAttachment();
3508 pipe.AddShader(&vs);
3509 pipe.AddShader(&fs);
3510 VkViewport view_port = {};
3511 m_viewports.push_back(view_port);
3512 pipe.SetViewport(m_viewports);
3513 VkRect2D rect = {};
3514 m_scissors.push_back(rect);
3515 pipe.SetScissor(m_scissors);
3516
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003517 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003518 VkPipelineLayout pl;
3519 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3520 ASSERT_VK_SUCCESS(err);
3521 pipe.CreateVKPipeline(pl, rp);
3522
Tony Barbour552f6c02016-12-21 14:34:07 -07003523 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003524
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003525 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3526 nullptr,
3527 rp,
3528 fb,
3529 {{
3530 0, 0,
3531 },
3532 {32, 32}},
3533 0,
3534 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003535
3536 // subtest 1: bind in the wrong subpass
3537 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3538 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003539 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 +13003540 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3541 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3542 m_errorMonitor->VerifyFound();
3543
3544 vkCmdEndRenderPass(m_commandBuffer->handle());
3545
3546 // subtest 2: bind in correct subpass, then transition to next subpass
3547 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3548 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3549 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003550 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 +13003551 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3552 m_errorMonitor->VerifyFound();
3553
3554 vkCmdEndRenderPass(m_commandBuffer->handle());
3555
Tony Barbour552f6c02016-12-21 14:34:07 -07003556 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003557
3558 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3559 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3560 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3561}
3562
Tony Barbour4e919972016-08-09 13:27:40 -06003563TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003564 TEST_DESCRIPTION(
3565 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3566 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003567 ASSERT_NO_FATAL_FAILURE(InitState());
3568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3569
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3571 "Cannot execute a render pass with renderArea "
3572 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003573
3574 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3575 m_renderPassBeginInfo.renderArea.extent.width = 257;
3576 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003577 m_commandBuffer->BeginCommandBuffer();
3578 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003579 m_errorMonitor->VerifyFound();
3580}
3581
3582TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003583 TEST_DESCRIPTION(
3584 "Generate INDEPENDENT_BLEND by disabling independent "
3585 "blend and then specifying different blend states for two "
3586 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003587 VkPhysicalDeviceFeatures features = {};
3588 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003589 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3592 "Invalid Pipeline CreateInfo: If independent blend feature not "
3593 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003594
Cody Northropc31a84f2016-08-22 10:41:47 -06003595 VkDescriptorSetObj descriptorSet(m_device);
3596 descriptorSet.AppendDummy();
3597 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003598
Cody Northropc31a84f2016-08-22 10:41:47 -06003599 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003600 // Create a renderPass with two color attachments
3601 VkAttachmentReference attachments[2] = {};
3602 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003603 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003604 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3605
3606 VkSubpassDescription subpass = {};
3607 subpass.pColorAttachments = attachments;
3608 subpass.colorAttachmentCount = 2;
3609
3610 VkRenderPassCreateInfo rpci = {};
3611 rpci.subpassCount = 1;
3612 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003613 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003614
Tony Barbourffd60bd2017-03-09 12:04:55 -07003615 VkAttachmentDescription attach_desc[2] = {};
3616 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3617 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3618 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3619 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3620 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3621 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3622 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3623 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003624
Tony Barbourffd60bd2017-03-09 12:04:55 -07003625 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003626 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3627
3628 VkRenderPass renderpass;
3629 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003630 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003631 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003632
Cody Northropc31a84f2016-08-22 10:41:47 -06003633 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3634 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3635 att_state1.blendEnable = VK_TRUE;
3636 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3637 att_state2.blendEnable = VK_FALSE;
3638 pipeline.AddColorAttachment(0, &att_state1);
3639 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003640 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003641 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003642 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003643}
3644
Mike Weiblen40b160e2017-02-06 19:21:52 -07003645// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3646TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3647 TEST_DESCRIPTION(
3648 "Create a graphics pipeline that is incompatible with the requirements "
3649 "of its contained Renderpass/subpasses.");
3650 ASSERT_NO_FATAL_FAILURE(InitState());
3651
3652 VkDescriptorSetObj ds_obj(m_device);
3653 ds_obj.AppendDummy();
3654 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3655
3656 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3657
3658 VkPipelineColorBlendAttachmentState att_state1 = {};
3659 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3660 att_state1.blendEnable = VK_TRUE;
3661
3662 VkRenderpassObj rp_obj(m_device);
3663
3664 {
3665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3666 VkPipelineObj pipeline(m_device);
3667 pipeline.AddShader(&vs_obj);
3668 pipeline.AddColorAttachment(0, &att_state1);
3669
3670 VkGraphicsPipelineCreateInfo info = {};
3671 pipeline.InitGraphicsPipelineCreateInfo(&info);
3672 info.pColorBlendState = nullptr;
3673
3674 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3675 m_errorMonitor->VerifyFound();
3676 }
3677}
3678
Chris Forbes26ec2122016-11-29 08:58:33 +13003679#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003680TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3681 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3682 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003683 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3686 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003687
3688 // Create a renderPass with a single color attachment
3689 VkAttachmentReference attach = {};
3690 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3691 VkSubpassDescription subpass = {};
3692 VkRenderPassCreateInfo rpci = {};
3693 rpci.subpassCount = 1;
3694 rpci.pSubpasses = &subpass;
3695 rpci.attachmentCount = 1;
3696 VkAttachmentDescription attach_desc = {};
3697 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3698 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3699 rpci.pAttachments = &attach_desc;
3700 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3701 VkRenderPass rp;
3702 subpass.pDepthStencilAttachment = &attach;
3703 subpass.pColorAttachments = NULL;
3704 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3705 m_errorMonitor->VerifyFound();
3706}
Chris Forbes26ec2122016-11-29 08:58:33 +13003707#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003708
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003709TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003710 TEST_DESCRIPTION(
3711 "Create a framebuffer where a subpass has a preserve "
3712 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003713
3714 ASSERT_NO_FATAL_FAILURE(InitState());
3715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003718
3719 VkAttachmentReference color_attach = {};
3720 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3721 color_attach.attachment = 0;
3722 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3723 VkSubpassDescription subpass = {};
3724 subpass.colorAttachmentCount = 1;
3725 subpass.pColorAttachments = &color_attach;
3726 subpass.preserveAttachmentCount = 1;
3727 subpass.pPreserveAttachments = &preserve_attachment;
3728
3729 VkRenderPassCreateInfo rpci = {};
3730 rpci.subpassCount = 1;
3731 rpci.pSubpasses = &subpass;
3732 rpci.attachmentCount = 1;
3733 VkAttachmentDescription attach_desc = {};
3734 attach_desc.format = VK_FORMAT_UNDEFINED;
3735 rpci.pAttachments = &attach_desc;
3736 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3737 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003738 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003739
3740 m_errorMonitor->VerifyFound();
3741
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003742 if (result == VK_SUCCESS) {
3743 vkDestroyRenderPass(m_device->device(), rp, NULL);
3744 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003745}
3746
Chris Forbesc5389742016-06-29 11:49:23 +12003747TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003748 TEST_DESCRIPTION(
3749 "Ensure that CreateRenderPass produces a validation error "
3750 "when the source of a subpass multisample resolve "
3751 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003752
Chris Forbesc5389742016-06-29 11:49:23 +12003753 ASSERT_NO_FATAL_FAILURE(InitState());
3754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3756 "Subpass 0 requests multisample resolve from attachment 0 which has "
3757 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003758
3759 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003760 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3761 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3762 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3763 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3764 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3765 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003766 };
3767
3768 VkAttachmentReference color = {
3769 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3770 };
3771
3772 VkAttachmentReference resolve = {
3773 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3774 };
3775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003776 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003779
3780 VkRenderPass rp;
3781 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3782
3783 m_errorMonitor->VerifyFound();
3784
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003785 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003786}
3787
3788TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003789 TEST_DESCRIPTION(
3790 "Ensure CreateRenderPass produces a validation error "
3791 "when a subpass multisample resolve operation is "
3792 "requested, and the destination of that resolve has "
3793 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003794
Chris Forbesc5389742016-06-29 11:49:23 +12003795 ASSERT_NO_FATAL_FAILURE(InitState());
3796
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3798 "Subpass 0 requests multisample resolve into attachment 1, which "
3799 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003800
3801 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003802 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3803 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3804 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3805 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3806 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3807 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003808 };
3809
3810 VkAttachmentReference color = {
3811 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3812 };
3813
3814 VkAttachmentReference resolve = {
3815 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3816 };
3817
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003818 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003821
3822 VkRenderPass rp;
3823 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3824
3825 m_errorMonitor->VerifyFound();
3826
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003827 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003828}
3829
Chris Forbes3f128ef2016-06-29 14:58:53 +12003830TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003831 TEST_DESCRIPTION(
3832 "Ensure CreateRenderPass produces a validation error "
3833 "when the color and depth attachments used by a subpass "
3834 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003835
Chris Forbes3f128ef2016-06-29 14:58:53 +12003836 ASSERT_NO_FATAL_FAILURE(InitState());
3837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3839 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003840
3841 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003842 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3843 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3844 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3845 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3846 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3847 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003848 };
3849
3850 VkAttachmentReference color[] = {
3851 {
3852 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3853 },
3854 {
3855 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3856 },
3857 };
3858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003859 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003861 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003862
3863 VkRenderPass rp;
3864 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3865
3866 m_errorMonitor->VerifyFound();
3867
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003868 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003869}
3870
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003871TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003872 TEST_DESCRIPTION(
3873 "Hit errors when attempting to create a framebuffer :\n"
3874 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3875 " 2. Use a color image as depthStencil attachment\n"
3876 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3877 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3878 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3879 " 6. Framebuffer attachment where dimensions don't match\n"
3880 " 7. Framebuffer attachment w/o identity swizzle\n"
3881 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003882
3883 ASSERT_NO_FATAL_FAILURE(InitState());
3884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3885
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003886 m_errorMonitor->SetDesiredFailureMsg(
3887 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3888 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003889
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003890 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003891 VkAttachmentReference attach = {};
3892 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3893 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003894 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003895 VkRenderPassCreateInfo rpci = {};
3896 rpci.subpassCount = 1;
3897 rpci.pSubpasses = &subpass;
3898 rpci.attachmentCount = 1;
3899 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003900 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003901 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003902 rpci.pAttachments = &attach_desc;
3903 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3904 VkRenderPass rp;
3905 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3906 ASSERT_VK_SUCCESS(err);
3907
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003908 VkImageView ivs[2];
3909 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3910 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003911 VkFramebufferCreateInfo fb_info = {};
3912 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3913 fb_info.pNext = NULL;
3914 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003915 // Set mis-matching attachmentCount
3916 fb_info.attachmentCount = 2;
3917 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003918 fb_info.width = 100;
3919 fb_info.height = 100;
3920 fb_info.layers = 1;
3921
3922 VkFramebuffer fb;
3923 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3924
3925 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003926 if (err == VK_SUCCESS) {
3927 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3928 }
3929 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003930
3931 // Create a renderPass with a depth-stencil attachment created with
3932 // IMAGE_USAGE_COLOR_ATTACHMENT
3933 // Add our color attachment to pDepthStencilAttachment
3934 subpass.pDepthStencilAttachment = &attach;
3935 subpass.pColorAttachments = NULL;
3936 VkRenderPass rp_ds;
3937 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3938 ASSERT_VK_SUCCESS(err);
3939 // Set correct attachment count, but attachment has COLOR usage bit set
3940 fb_info.attachmentCount = 1;
3941 fb_info.renderPass = rp_ds;
3942
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003944 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3945
3946 m_errorMonitor->VerifyFound();
3947 if (err == VK_SUCCESS) {
3948 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3949 }
3950 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003951
3952 // Create new renderpass with alternate attachment format from fb
3953 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3954 subpass.pDepthStencilAttachment = NULL;
3955 subpass.pColorAttachments = &attach;
3956 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3957 ASSERT_VK_SUCCESS(err);
3958
3959 // Cause error due to mis-matched formats between rp & fb
3960 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3961 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3963 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003964 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3965
3966 m_errorMonitor->VerifyFound();
3967 if (err == VK_SUCCESS) {
3968 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3969 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003970 vkDestroyRenderPass(m_device->device(), rp, NULL);
3971
3972 // Create new renderpass with alternate sample count from fb
3973 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3974 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3975 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3976 ASSERT_VK_SUCCESS(err);
3977
3978 // Cause error due to mis-matched sample count between rp & fb
3979 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003981 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003982 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3983
3984 m_errorMonitor->VerifyFound();
3985 if (err == VK_SUCCESS) {
3986 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3987 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003988
3989 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003990
3991 // Create a custom imageView with non-1 mip levels
3992 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003993 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 -06003994 ASSERT_TRUE(image.initialized());
3995
3996 VkImageView view;
3997 VkImageViewCreateInfo ivci = {};
3998 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3999 ivci.image = image.handle();
4000 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4001 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4002 ivci.subresourceRange.layerCount = 1;
4003 ivci.subresourceRange.baseMipLevel = 0;
4004 // Set level count 2 (only 1 is allowed for FB attachment)
4005 ivci.subresourceRange.levelCount = 2;
4006 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4007 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4008 ASSERT_VK_SUCCESS(err);
4009 // Re-create renderpass to have matching sample count
4010 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4011 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4012 ASSERT_VK_SUCCESS(err);
4013
4014 fb_info.renderPass = rp;
4015 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004017 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4018
4019 m_errorMonitor->VerifyFound();
4020 if (err == VK_SUCCESS) {
4021 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4022 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004023 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004024 // Update view to original color buffer and grow FB dimensions too big
4025 fb_info.pAttachments = ivs;
4026 fb_info.height = 1024;
4027 fb_info.width = 1024;
4028 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004030 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4031
4032 m_errorMonitor->VerifyFound();
4033 if (err == VK_SUCCESS) {
4034 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4035 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004036 // Create view attachment with non-identity swizzle
4037 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4038 ivci.image = image.handle();
4039 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4040 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4041 ivci.subresourceRange.layerCount = 1;
4042 ivci.subresourceRange.baseMipLevel = 0;
4043 ivci.subresourceRange.levelCount = 1;
4044 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4045 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4046 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4047 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4048 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4049 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4050 ASSERT_VK_SUCCESS(err);
4051
4052 fb_info.pAttachments = &view;
4053 fb_info.height = 100;
4054 fb_info.width = 100;
4055 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004056 m_errorMonitor->SetDesiredFailureMsg(
4057 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4058 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004059 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4060
4061 m_errorMonitor->VerifyFound();
4062 if (err == VK_SUCCESS) {
4063 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4064 }
4065 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004066 // reset attachment to color attachment
4067 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004068
4069 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004070 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004071 fb_info.height = 100;
4072 fb_info.layers = 1;
4073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004074 m_errorMonitor->SetDesiredFailureMsg(
4075 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004076 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4077 "Here are the respective dimensions for attachment");
4078
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004079 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4080
4081 m_errorMonitor->VerifyFound();
4082 if (err == VK_SUCCESS) {
4083 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4084 }
4085
4086 // Request fb that exceeds max height
4087 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004088 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004089 fb_info.layers = 1;
4090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004091 m_errorMonitor->SetDesiredFailureMsg(
4092 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004093 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4094 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004095 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4096
4097 m_errorMonitor->VerifyFound();
4098 if (err == VK_SUCCESS) {
4099 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4100 }
4101
4102 // Request fb that exceeds max layers
4103 fb_info.width = 100;
4104 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004105 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004107 m_errorMonitor->SetDesiredFailureMsg(
4108 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004109 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4110 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004111 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4112
4113 m_errorMonitor->VerifyFound();
4114 if (err == VK_SUCCESS) {
4115 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4116 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004117
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004118 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004119}
4120
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004121TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004122 TEST_DESCRIPTION(
4123 "Run a simple draw calls to validate failure when Depth Bias 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 Ehlisb1a87992016-05-25 16:42:47 -06004127 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4129 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004130 m_errorMonitor->VerifyFound();
4131}
4132
4133TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004134 TEST_DESCRIPTION(
4135 "Run a simple draw calls to validate failure when Line Width dynamic "
4136 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004137
Cody Northropc31a84f2016-08-22 10:41:47 -06004138 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004139 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4141 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004142 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004143}
4144
4145TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004146 TEST_DESCRIPTION(
4147 "Run a simple draw calls to validate failure when Viewport dynamic "
4148 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004149
Cody Northropc31a84f2016-08-22 10:41:47 -06004150 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004151 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4153 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004154 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004155 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004156}
4157
4158TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004159 TEST_DESCRIPTION(
4160 "Run a simple draw calls to validate failure when Scissor dynamic "
4161 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004162
Cody Northropc31a84f2016-08-22 10:41:47 -06004163 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004164 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4166 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004167 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004168 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004169}
4170
Cortd713fe82016-07-27 09:51:27 -07004171TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004172 TEST_DESCRIPTION(
4173 "Run a simple draw calls to validate failure when Blend Constants "
4174 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004175
4176 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004177 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4179 "Dynamic blend constants state not set for this command buffer");
4180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004181 m_errorMonitor->VerifyFound();
4182}
4183
4184TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004185 TEST_DESCRIPTION(
4186 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4187 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004188
4189 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004190 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004191 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004192 return;
4193 }
4194 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4196 "Dynamic depth bounds state not set for this command buffer");
4197 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004198 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004199}
4200
4201TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004202 TEST_DESCRIPTION(
4203 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4204 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004205
4206 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004207 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4209 "Dynamic stencil read mask state not set for this command buffer");
4210 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004211 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004212}
4213
4214TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004215 TEST_DESCRIPTION(
4216 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4217 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004218
4219 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004220 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4222 "Dynamic stencil write mask state not set for this command buffer");
4223 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004224 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004225}
4226
4227TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004228 TEST_DESCRIPTION(
4229 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4230 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004231
4232 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004233 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4235 "Dynamic stencil reference state not set for this command buffer");
4236 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004237 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004238}
4239
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004240TEST_F(VkLayerTest, IndexBufferNotBound) {
4241 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004242
4243 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4245 "Index buffer object not bound to this command buffer when Indexed ");
4246 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004247 m_errorMonitor->VerifyFound();
4248}
4249
Karl Schultz6addd812016-02-02 17:17:23 -07004250TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4252 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4253 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004254
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004255 ASSERT_NO_FATAL_FAILURE(InitState());
4256 ASSERT_NO_FATAL_FAILURE(InitViewport());
4257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4258
Karl Schultz6addd812016-02-02 17:17:23 -07004259 // We luck out b/c by default the framework creates CB w/ the
4260 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004261 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004263 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004264
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004265 // Bypass framework since it does the waits automatically
4266 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004267 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004268 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4269 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004270 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004271 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004272 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004273 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004274 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004275 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004276 submit_info.pSignalSemaphores = NULL;
4277
Chris Forbes40028e22016-06-13 09:59:34 +12004278 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004279 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004280 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004281
Karl Schultz6addd812016-02-02 17:17:23 -07004282 // Cause validation error by re-submitting cmd buffer that should only be
4283 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004284 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004285 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004287 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004288}
4289
Karl Schultz6addd812016-02-02 17:17:23 -07004290TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004292 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004293
4294 ASSERT_NO_FATAL_FAILURE(InitState());
4295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004296
Karl Schultz6addd812016-02-02 17:17:23 -07004297 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4298 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004299 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004300 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004301 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004302
4303 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004304 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4305 ds_pool_ci.pNext = NULL;
4306 ds_pool_ci.flags = 0;
4307 ds_pool_ci.maxSets = 1;
4308 ds_pool_ci.poolSizeCount = 1;
4309 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004310
4311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004313 ASSERT_VK_SUCCESS(err);
4314
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004315 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4316 dsl_binding_samp.binding = 0;
4317 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4318 dsl_binding_samp.descriptorCount = 1;
4319 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4320 dsl_binding_samp.pImmutableSamplers = NULL;
4321
4322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4324 ds_layout_ci.pNext = NULL;
4325 ds_layout_ci.bindingCount = 1;
4326 ds_layout_ci.pBindings = &dsl_binding_samp;
4327
4328 VkDescriptorSetLayout ds_layout_samp;
4329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4330 ASSERT_VK_SUCCESS(err);
4331
4332 // Try to allocate 2 sets when pool only has 1 set
4333 VkDescriptorSet descriptor_sets[2];
4334 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4335 VkDescriptorSetAllocateInfo alloc_info = {};
4336 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4337 alloc_info.descriptorSetCount = 2;
4338 alloc_info.descriptorPool = ds_pool;
4339 alloc_info.pSetLayouts = set_layouts;
4340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4341 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4342 m_errorMonitor->VerifyFound();
4343
4344 alloc_info.descriptorSetCount = 1;
4345 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004346 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004347 dsl_binding.binding = 0;
4348 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4349 dsl_binding.descriptorCount = 1;
4350 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4351 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004352
Karl Schultz6addd812016-02-02 17:17:23 -07004353 ds_layout_ci.bindingCount = 1;
4354 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004355
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004356 VkDescriptorSetLayout ds_layout_ub;
4357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004358 ASSERT_VK_SUCCESS(err);
4359
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004360 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004361 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004362 alloc_info.pSetLayouts = &ds_layout_ub;
4363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4364 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004366 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004367
Karl Schultz2825ab92016-12-02 08:23:14 -07004368 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004370 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004371}
4372
Karl Schultz6addd812016-02-02 17:17:23 -07004373TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4374 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004375
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004377
Tobin Ehlise735c692015-10-08 13:13:50 -06004378 ASSERT_NO_FATAL_FAILURE(InitState());
4379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004380
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004381 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004382 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4383 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004384
4385 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004386 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4387 ds_pool_ci.pNext = NULL;
4388 ds_pool_ci.maxSets = 1;
4389 ds_pool_ci.poolSizeCount = 1;
4390 ds_pool_ci.flags = 0;
4391 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4392 // app can only call vkResetDescriptorPool on this pool.;
4393 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004394
4395 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004396 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004397 ASSERT_VK_SUCCESS(err);
4398
4399 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004400 dsl_binding.binding = 0;
4401 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4402 dsl_binding.descriptorCount = 1;
4403 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4404 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004405
4406 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004407 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4408 ds_layout_ci.pNext = NULL;
4409 ds_layout_ci.bindingCount = 1;
4410 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004411
4412 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004413 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004414 ASSERT_VK_SUCCESS(err);
4415
4416 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004417 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004418 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004419 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004420 alloc_info.descriptorPool = ds_pool;
4421 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004422 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004423 ASSERT_VK_SUCCESS(err);
4424
4425 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004426 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004427
Chia-I Wuf7458c52015-10-26 21:10:41 +08004428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004430}
4431
Karl Schultz6addd812016-02-02 17:17:23 -07004432TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004433 // Attempt to clear Descriptor Pool with bad object.
4434 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004435
4436 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004438 uint64_t fake_pool_handle = 0xbaad6001;
4439 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4440 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004441 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004442}
4443
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004444TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004445 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4446 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004447 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004448 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004449
4450 uint64_t fake_set_handle = 0xbaad6001;
4451 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004452 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004454
4455 ASSERT_NO_FATAL_FAILURE(InitState());
4456
4457 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4458 layout_bindings[0].binding = 0;
4459 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4460 layout_bindings[0].descriptorCount = 1;
4461 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4462 layout_bindings[0].pImmutableSamplers = NULL;
4463
4464 VkDescriptorSetLayout descriptor_set_layout;
4465 VkDescriptorSetLayoutCreateInfo dslci = {};
4466 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4467 dslci.pNext = NULL;
4468 dslci.bindingCount = 1;
4469 dslci.pBindings = layout_bindings;
4470 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004471 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004472
4473 VkPipelineLayout pipeline_layout;
4474 VkPipelineLayoutCreateInfo plci = {};
4475 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4476 plci.pNext = NULL;
4477 plci.setLayoutCount = 1;
4478 plci.pSetLayouts = &descriptor_set_layout;
4479 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004480 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004481
Tony Barbour552f6c02016-12-21 14:34:07 -07004482 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004483 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4484 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004485 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004486 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004487 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4488 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004489}
4490
Karl Schultz6addd812016-02-02 17:17:23 -07004491TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004492 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4493 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004494 uint64_t fake_layout_handle = 0xbaad6001;
4495 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004497 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004498 VkPipelineLayout pipeline_layout;
4499 VkPipelineLayoutCreateInfo plci = {};
4500 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4501 plci.pNext = NULL;
4502 plci.setLayoutCount = 1;
4503 plci.pSetLayouts = &bad_layout;
4504 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4505
4506 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004507}
4508
Mark Muellerd4914412016-06-13 17:52:06 -06004509TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004510 TEST_DESCRIPTION(
4511 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4512 "1) A uniform buffer update must have a valid buffer index."
4513 "2) When using an array of descriptors in a single WriteDescriptor,"
4514 " the descriptor types and stageflags must all be the same."
4515 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004516
Mike Weiblena6666382017-01-05 15:16:11 -07004517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004518
4519 ASSERT_NO_FATAL_FAILURE(InitState());
4520 VkDescriptorPoolSize ds_type_count[4] = {};
4521 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4522 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004523 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004524 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004525 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004526 ds_type_count[2].descriptorCount = 1;
4527 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4528 ds_type_count[3].descriptorCount = 1;
4529
4530 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4531 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4532 ds_pool_ci.maxSets = 1;
4533 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4534 ds_pool_ci.pPoolSizes = ds_type_count;
4535
4536 VkDescriptorPool ds_pool;
4537 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4538 ASSERT_VK_SUCCESS(err);
4539
Mark Muellerb9896722016-06-16 09:54:29 -06004540 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004541 layout_binding[0].binding = 0;
4542 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4543 layout_binding[0].descriptorCount = 1;
4544 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4545 layout_binding[0].pImmutableSamplers = NULL;
4546
4547 layout_binding[1].binding = 1;
4548 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4549 layout_binding[1].descriptorCount = 1;
4550 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4551 layout_binding[1].pImmutableSamplers = NULL;
4552
4553 VkSamplerCreateInfo sampler_ci = {};
4554 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4555 sampler_ci.pNext = NULL;
4556 sampler_ci.magFilter = VK_FILTER_NEAREST;
4557 sampler_ci.minFilter = VK_FILTER_NEAREST;
4558 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4559 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4560 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4561 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4562 sampler_ci.mipLodBias = 1.0;
4563 sampler_ci.anisotropyEnable = VK_FALSE;
4564 sampler_ci.maxAnisotropy = 1;
4565 sampler_ci.compareEnable = VK_FALSE;
4566 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4567 sampler_ci.minLod = 1.0;
4568 sampler_ci.maxLod = 1.0;
4569 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4570 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4571 VkSampler sampler;
4572
4573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4574 ASSERT_VK_SUCCESS(err);
4575
4576 layout_binding[2].binding = 2;
4577 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4578 layout_binding[2].descriptorCount = 1;
4579 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4580 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4581
Mark Muellerd4914412016-06-13 17:52:06 -06004582 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4583 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4584 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4585 ds_layout_ci.pBindings = layout_binding;
4586 VkDescriptorSetLayout ds_layout;
4587 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4588 ASSERT_VK_SUCCESS(err);
4589
4590 VkDescriptorSetAllocateInfo alloc_info = {};
4591 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4592 alloc_info.descriptorSetCount = 1;
4593 alloc_info.descriptorPool = ds_pool;
4594 alloc_info.pSetLayouts = &ds_layout;
4595 VkDescriptorSet descriptorSet;
4596 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4597 ASSERT_VK_SUCCESS(err);
4598
4599 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4600 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4601 pipeline_layout_ci.pNext = NULL;
4602 pipeline_layout_ci.setLayoutCount = 1;
4603 pipeline_layout_ci.pSetLayouts = &ds_layout;
4604
4605 VkPipelineLayout pipeline_layout;
4606 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4607 ASSERT_VK_SUCCESS(err);
4608
Mark Mueller5c838ce2016-06-16 09:54:29 -06004609 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004610 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4611 descriptor_write.dstSet = descriptorSet;
4612 descriptor_write.dstBinding = 0;
4613 descriptor_write.descriptorCount = 1;
4614 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4615
Mark Mueller5c838ce2016-06-16 09:54:29 -06004616 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4618 m_errorMonitor->VerifyFound();
4619
4620 // Create a buffer to update the descriptor with
4621 uint32_t qfi = 0;
4622 VkBufferCreateInfo buffCI = {};
4623 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4624 buffCI.size = 1024;
4625 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4626 buffCI.queueFamilyIndexCount = 1;
4627 buffCI.pQueueFamilyIndices = &qfi;
4628
4629 VkBuffer dyub;
4630 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4631 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004632
Tony Barboure132c5f2016-12-12 11:50:20 -07004633 VkDeviceMemory mem;
4634 VkMemoryRequirements mem_reqs;
4635 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4636
4637 VkMemoryAllocateInfo mem_alloc_info = {};
4638 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4639 mem_alloc_info.allocationSize = mem_reqs.size;
4640 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4641 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4642 ASSERT_VK_SUCCESS(err);
4643
4644 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4645 ASSERT_VK_SUCCESS(err);
4646
4647 VkDescriptorBufferInfo buffInfo[2] = {};
4648 buffInfo[0].buffer = dyub;
4649 buffInfo[0].offset = 0;
4650 buffInfo[0].range = 1024;
4651 buffInfo[1].buffer = dyub;
4652 buffInfo[1].offset = 0;
4653 buffInfo[1].range = 1024;
4654 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004655 descriptor_write.descriptorCount = 2;
4656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004659 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4660 m_errorMonitor->VerifyFound();
4661
Mark Mueller5c838ce2016-06-16 09:54:29 -06004662 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4663 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004664 descriptor_write.dstBinding = 1;
4665 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004666
Mark Mueller5c838ce2016-06-16 09:54:29 -06004667 // Make pImageInfo index non-null to avoid complaints of it missing
4668 VkDescriptorImageInfo imageInfo = {};
4669 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4670 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004672 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4673 m_errorMonitor->VerifyFound();
4674
Mark Muellerd4914412016-06-13 17:52:06 -06004675 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004676 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004677 vkDestroySampler(m_device->device(), sampler, NULL);
4678 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4681}
4682
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004683TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004684 TEST_DESCRIPTION(
4685 "Attempt to draw with a command buffer that is invalid "
4686 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004687 ASSERT_NO_FATAL_FAILURE(InitState());
4688
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004689 VkBuffer buffer;
4690 VkDeviceMemory mem;
4691 VkMemoryRequirements mem_reqs;
4692
4693 VkBufferCreateInfo buf_info = {};
4694 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004695 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004696 buf_info.size = 256;
4697 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4698 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4699 ASSERT_VK_SUCCESS(err);
4700
4701 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4702
4703 VkMemoryAllocateInfo alloc_info = {};
4704 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4705 alloc_info.allocationSize = 256;
4706 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004707 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 -06004708 if (!pass) {
4709 vkDestroyBuffer(m_device->device(), buffer, NULL);
4710 return;
4711 }
4712 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4713 ASSERT_VK_SUCCESS(err);
4714
4715 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4716 ASSERT_VK_SUCCESS(err);
4717
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004718 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004719 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004720 m_commandBuffer->EndCommandBuffer();
4721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004723 // Destroy buffer dependency prior to submit to cause ERROR
4724 vkDestroyBuffer(m_device->device(), buffer, NULL);
4725
4726 VkSubmitInfo submit_info = {};
4727 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4728 submit_info.commandBufferCount = 1;
4729 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4730 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4731
4732 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004733 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004734 vkFreeMemory(m_device->handle(), mem, NULL);
4735}
4736
Tobin Ehlisea413442016-09-28 10:23:59 -06004737TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4738 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4739
4740 ASSERT_NO_FATAL_FAILURE(InitState());
4741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4742
4743 VkDescriptorPoolSize ds_type_count;
4744 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4745 ds_type_count.descriptorCount = 1;
4746
4747 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4748 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4749 ds_pool_ci.maxSets = 1;
4750 ds_pool_ci.poolSizeCount = 1;
4751 ds_pool_ci.pPoolSizes = &ds_type_count;
4752
4753 VkDescriptorPool ds_pool;
4754 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4755 ASSERT_VK_SUCCESS(err);
4756
4757 VkDescriptorSetLayoutBinding layout_binding;
4758 layout_binding.binding = 0;
4759 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4760 layout_binding.descriptorCount = 1;
4761 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4762 layout_binding.pImmutableSamplers = NULL;
4763
4764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4766 ds_layout_ci.bindingCount = 1;
4767 ds_layout_ci.pBindings = &layout_binding;
4768 VkDescriptorSetLayout ds_layout;
4769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4770 ASSERT_VK_SUCCESS(err);
4771
4772 VkDescriptorSetAllocateInfo alloc_info = {};
4773 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4774 alloc_info.descriptorSetCount = 1;
4775 alloc_info.descriptorPool = ds_pool;
4776 alloc_info.pSetLayouts = &ds_layout;
4777 VkDescriptorSet descriptor_set;
4778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4779 ASSERT_VK_SUCCESS(err);
4780
4781 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4782 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4783 pipeline_layout_ci.pNext = NULL;
4784 pipeline_layout_ci.setLayoutCount = 1;
4785 pipeline_layout_ci.pSetLayouts = &ds_layout;
4786
4787 VkPipelineLayout pipeline_layout;
4788 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4789 ASSERT_VK_SUCCESS(err);
4790
4791 VkBuffer buffer;
4792 uint32_t queue_family_index = 0;
4793 VkBufferCreateInfo buffer_create_info = {};
4794 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4795 buffer_create_info.size = 1024;
4796 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4797 buffer_create_info.queueFamilyIndexCount = 1;
4798 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4799
4800 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4801 ASSERT_VK_SUCCESS(err);
4802
4803 VkMemoryRequirements memory_reqs;
4804 VkDeviceMemory buffer_memory;
4805
4806 VkMemoryAllocateInfo memory_info = {};
4807 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4808 memory_info.allocationSize = 0;
4809 memory_info.memoryTypeIndex = 0;
4810
4811 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4812 memory_info.allocationSize = memory_reqs.size;
4813 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4814 ASSERT_TRUE(pass);
4815
4816 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4817 ASSERT_VK_SUCCESS(err);
4818 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4819 ASSERT_VK_SUCCESS(err);
4820
4821 VkBufferView view;
4822 VkBufferViewCreateInfo bvci = {};
4823 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4824 bvci.buffer = buffer;
4825 bvci.format = VK_FORMAT_R8_UNORM;
4826 bvci.range = VK_WHOLE_SIZE;
4827
4828 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4829 ASSERT_VK_SUCCESS(err);
4830
4831 VkWriteDescriptorSet descriptor_write = {};
4832 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4833 descriptor_write.dstSet = descriptor_set;
4834 descriptor_write.dstBinding = 0;
4835 descriptor_write.descriptorCount = 1;
4836 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4837 descriptor_write.pTexelBufferView = &view;
4838
4839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4840
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004841 char const *vsSource =
4842 "#version 450\n"
4843 "\n"
4844 "out gl_PerVertex { \n"
4845 " vec4 gl_Position;\n"
4846 "};\n"
4847 "void main(){\n"
4848 " gl_Position = vec4(1);\n"
4849 "}\n";
4850 char const *fsSource =
4851 "#version 450\n"
4852 "\n"
4853 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4854 "layout(location=0) out vec4 x;\n"
4855 "void main(){\n"
4856 " x = imageLoad(s, 0);\n"
4857 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4860 VkPipelineObj pipe(m_device);
4861 pipe.AddShader(&vs);
4862 pipe.AddShader(&fs);
4863 pipe.AddColorAttachment();
4864 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4865
Tobin Ehlisea413442016-09-28 10:23:59 -06004866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4867
Tony Barbour552f6c02016-12-21 14:34:07 -07004868 m_commandBuffer->BeginCommandBuffer();
4869 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4870
Tobin Ehlisea413442016-09-28 10:23:59 -06004871 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4872 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4873 VkRect2D scissor = {{0, 0}, {16, 16}};
4874 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4875 // Bind pipeline to cmd buffer
4876 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4877 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4878 &descriptor_set, 0, nullptr);
4879 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004880 m_commandBuffer->EndRenderPass();
4881 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004882
4883 // Delete BufferView in order to invalidate cmd buffer
4884 vkDestroyBufferView(m_device->device(), view, NULL);
4885 // Now attempt submit of cmd buffer
4886 VkSubmitInfo submit_info = {};
4887 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4888 submit_info.commandBufferCount = 1;
4889 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4890 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4891 m_errorMonitor->VerifyFound();
4892
4893 // Clean-up
4894 vkDestroyBuffer(m_device->device(), buffer, NULL);
4895 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4896 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4897 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4898 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4899}
4900
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004901TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004902 TEST_DESCRIPTION(
4903 "Attempt to draw with a command buffer that is invalid "
4904 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004905 ASSERT_NO_FATAL_FAILURE(InitState());
4906
4907 VkImage image;
4908 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4909 VkImageCreateInfo image_create_info = {};
4910 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4911 image_create_info.pNext = NULL;
4912 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4913 image_create_info.format = tex_format;
4914 image_create_info.extent.width = 32;
4915 image_create_info.extent.height = 32;
4916 image_create_info.extent.depth = 1;
4917 image_create_info.mipLevels = 1;
4918 image_create_info.arrayLayers = 1;
4919 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4920 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004921 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004922 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004923 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004924 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004925 // Have to bind memory to image before recording cmd in cmd buffer using it
4926 VkMemoryRequirements mem_reqs;
4927 VkDeviceMemory image_mem;
4928 bool pass;
4929 VkMemoryAllocateInfo mem_alloc = {};
4930 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4931 mem_alloc.pNext = NULL;
4932 mem_alloc.memoryTypeIndex = 0;
4933 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4934 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004936 ASSERT_TRUE(pass);
4937 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4938 ASSERT_VK_SUCCESS(err);
4939 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4940 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004941
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004942 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004943 VkClearColorValue ccv;
4944 ccv.float32[0] = 1.0f;
4945 ccv.float32[1] = 1.0f;
4946 ccv.float32[2] = 1.0f;
4947 ccv.float32[3] = 1.0f;
4948 VkImageSubresourceRange isr = {};
4949 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004950 isr.baseArrayLayer = 0;
4951 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004952 isr.layerCount = 1;
4953 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004954 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004955 m_commandBuffer->EndCommandBuffer();
4956
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004958 // Destroy image dependency prior to submit to cause ERROR
4959 vkDestroyImage(m_device->device(), image, NULL);
4960
4961 VkSubmitInfo submit_info = {};
4962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4963 submit_info.commandBufferCount = 1;
4964 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4965 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4966
4967 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004968 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004969}
4970
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004971TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004972 TEST_DESCRIPTION(
4973 "Attempt to draw with a command buffer that is invalid "
4974 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004975 VkFormatProperties format_properties;
4976 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004977 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4978 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004979 return;
4980 }
4981
4982 ASSERT_NO_FATAL_FAILURE(InitState());
4983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4984
4985 VkImageCreateInfo image_ci = {};
4986 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4987 image_ci.pNext = NULL;
4988 image_ci.imageType = VK_IMAGE_TYPE_2D;
4989 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4990 image_ci.extent.width = 32;
4991 image_ci.extent.height = 32;
4992 image_ci.extent.depth = 1;
4993 image_ci.mipLevels = 1;
4994 image_ci.arrayLayers = 1;
4995 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4996 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004997 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004998 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4999 image_ci.flags = 0;
5000 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005001 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005002
5003 VkMemoryRequirements memory_reqs;
5004 VkDeviceMemory image_memory;
5005 bool pass;
5006 VkMemoryAllocateInfo memory_info = {};
5007 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5008 memory_info.pNext = NULL;
5009 memory_info.allocationSize = 0;
5010 memory_info.memoryTypeIndex = 0;
5011 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5012 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005013 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005014 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005015 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005016 ASSERT_VK_SUCCESS(err);
5017 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5018 ASSERT_VK_SUCCESS(err);
5019
5020 VkImageViewCreateInfo ivci = {
5021 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5022 nullptr,
5023 0,
5024 image,
5025 VK_IMAGE_VIEW_TYPE_2D,
5026 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005027 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005028 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5029 };
5030 VkImageView view;
5031 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5032 ASSERT_VK_SUCCESS(err);
5033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005034 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005035 VkFramebuffer fb;
5036 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5037 ASSERT_VK_SUCCESS(err);
5038
5039 // Just use default renderpass with our framebuffer
5040 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005041 m_renderPassBeginInfo.renderArea.extent.width = 32;
5042 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005043 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005044 m_commandBuffer->BeginCommandBuffer();
5045 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5046 m_commandBuffer->EndRenderPass();
5047 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005048 // Destroy image attached to framebuffer to invalidate cmd buffer
5049 vkDestroyImage(m_device->device(), image, NULL);
5050 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005052 QueueCommandBuffer(false);
5053 m_errorMonitor->VerifyFound();
5054
5055 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5056 vkDestroyImageView(m_device->device(), view, nullptr);
5057 vkFreeMemory(m_device->device(), image_memory, nullptr);
5058}
5059
Tobin Ehlisb329f992016-10-12 13:20:29 -06005060TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5061 TEST_DESCRIPTION("Delete in-use framebuffer.");
5062 VkFormatProperties format_properties;
5063 VkResult err = VK_SUCCESS;
5064 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5065
5066 ASSERT_NO_FATAL_FAILURE(InitState());
5067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5068
5069 VkImageObj image(m_device);
5070 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5071 ASSERT_TRUE(image.initialized());
5072 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5073
5074 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5075 VkFramebuffer fb;
5076 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5077 ASSERT_VK_SUCCESS(err);
5078
5079 // Just use default renderpass with our framebuffer
5080 m_renderPassBeginInfo.framebuffer = fb;
5081 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005082 m_commandBuffer->BeginCommandBuffer();
5083 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5084 m_commandBuffer->EndRenderPass();
5085 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005086 // Submit cmd buffer to put it in-flight
5087 VkSubmitInfo submit_info = {};
5088 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5089 submit_info.commandBufferCount = 1;
5090 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5091 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5092 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005094 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5095 m_errorMonitor->VerifyFound();
5096 // Wait for queue to complete so we can safely destroy everything
5097 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005098 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5099 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005100 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5101}
5102
Tobin Ehlis88becd72016-09-21 14:33:41 -06005103TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5104 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5105 VkFormatProperties format_properties;
5106 VkResult err = VK_SUCCESS;
5107 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005108
5109 ASSERT_NO_FATAL_FAILURE(InitState());
5110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5111
5112 VkImageCreateInfo image_ci = {};
5113 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5114 image_ci.pNext = NULL;
5115 image_ci.imageType = VK_IMAGE_TYPE_2D;
5116 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5117 image_ci.extent.width = 256;
5118 image_ci.extent.height = 256;
5119 image_ci.extent.depth = 1;
5120 image_ci.mipLevels = 1;
5121 image_ci.arrayLayers = 1;
5122 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5123 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005124 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005125 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5126 image_ci.flags = 0;
5127 VkImage image;
5128 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5129
5130 VkMemoryRequirements memory_reqs;
5131 VkDeviceMemory image_memory;
5132 bool pass;
5133 VkMemoryAllocateInfo memory_info = {};
5134 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5135 memory_info.pNext = NULL;
5136 memory_info.allocationSize = 0;
5137 memory_info.memoryTypeIndex = 0;
5138 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5139 memory_info.allocationSize = memory_reqs.size;
5140 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5141 ASSERT_TRUE(pass);
5142 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5143 ASSERT_VK_SUCCESS(err);
5144 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5145 ASSERT_VK_SUCCESS(err);
5146
5147 VkImageViewCreateInfo ivci = {
5148 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5149 nullptr,
5150 0,
5151 image,
5152 VK_IMAGE_VIEW_TYPE_2D,
5153 VK_FORMAT_B8G8R8A8_UNORM,
5154 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5155 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5156 };
5157 VkImageView view;
5158 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5159 ASSERT_VK_SUCCESS(err);
5160
5161 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5162 VkFramebuffer fb;
5163 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5164 ASSERT_VK_SUCCESS(err);
5165
5166 // Just use default renderpass with our framebuffer
5167 m_renderPassBeginInfo.framebuffer = fb;
5168 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005169 m_commandBuffer->BeginCommandBuffer();
5170 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5171 m_commandBuffer->EndRenderPass();
5172 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005173 // Submit cmd buffer to put it (and attached imageView) in-flight
5174 VkSubmitInfo submit_info = {};
5175 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5176 submit_info.commandBufferCount = 1;
5177 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5178 // Submit cmd buffer to put framebuffer and children in-flight
5179 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5180 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005182 vkDestroyImage(m_device->device(), image, NULL);
5183 m_errorMonitor->VerifyFound();
5184 // Wait for queue to complete so we can safely destroy image and other objects
5185 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005186 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5187 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005188 vkDestroyImage(m_device->device(), image, NULL);
5189 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5190 vkDestroyImageView(m_device->device(), view, nullptr);
5191 vkFreeMemory(m_device->device(), image_memory, nullptr);
5192}
5193
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005194TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5195 TEST_DESCRIPTION("Delete in-use renderPass.");
5196
5197 ASSERT_NO_FATAL_FAILURE(InitState());
5198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5199
5200 // Create simple renderpass
5201 VkAttachmentReference attach = {};
5202 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5203 VkSubpassDescription subpass = {};
5204 subpass.pColorAttachments = &attach;
5205 VkRenderPassCreateInfo rpci = {};
5206 rpci.subpassCount = 1;
5207 rpci.pSubpasses = &subpass;
5208 rpci.attachmentCount = 1;
5209 VkAttachmentDescription attach_desc = {};
5210 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5211 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5212 rpci.pAttachments = &attach_desc;
5213 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5214 VkRenderPass rp;
5215 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5216 ASSERT_VK_SUCCESS(err);
5217
5218 // Create a pipeline that uses the given renderpass
5219 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5220 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5221
5222 VkPipelineLayout pipeline_layout;
5223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5224 ASSERT_VK_SUCCESS(err);
5225
5226 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5227 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5228 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005229 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005230 vp_state_ci.pViewports = &vp;
5231 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005232 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005233 vp_state_ci.pScissors = &scissors;
5234
5235 VkPipelineShaderStageCreateInfo shaderStages[2];
5236 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5237
5238 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005239 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 -06005240 // but add it to be able to run on more devices
5241 shaderStages[0] = vs.GetStageCreateInfo();
5242 shaderStages[1] = fs.GetStageCreateInfo();
5243
5244 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5245 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5246
5247 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5248 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5249 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5250
5251 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5252 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5253 rs_ci.rasterizerDiscardEnable = true;
5254 rs_ci.lineWidth = 1.0f;
5255
5256 VkPipelineColorBlendAttachmentState att = {};
5257 att.blendEnable = VK_FALSE;
5258 att.colorWriteMask = 0xf;
5259
5260 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5261 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5262 cb_ci.attachmentCount = 1;
5263 cb_ci.pAttachments = &att;
5264
5265 VkGraphicsPipelineCreateInfo gp_ci = {};
5266 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5267 gp_ci.stageCount = 2;
5268 gp_ci.pStages = shaderStages;
5269 gp_ci.pVertexInputState = &vi_ci;
5270 gp_ci.pInputAssemblyState = &ia_ci;
5271 gp_ci.pViewportState = &vp_state_ci;
5272 gp_ci.pRasterizationState = &rs_ci;
5273 gp_ci.pColorBlendState = &cb_ci;
5274 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5275 gp_ci.layout = pipeline_layout;
5276 gp_ci.renderPass = rp;
5277
5278 VkPipelineCacheCreateInfo pc_ci = {};
5279 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5280
5281 VkPipeline pipeline;
5282 VkPipelineCache pipe_cache;
5283 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5284 ASSERT_VK_SUCCESS(err);
5285
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005286 m_errorMonitor->SetUnexpectedError(
5287 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5288 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005289 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5290 ASSERT_VK_SUCCESS(err);
5291 // Bind pipeline to cmd buffer, will also bind renderpass
5292 m_commandBuffer->BeginCommandBuffer();
5293 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5294 m_commandBuffer->EndCommandBuffer();
5295
5296 VkSubmitInfo submit_info = {};
5297 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5298 submit_info.commandBufferCount = 1;
5299 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5300 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5301
5302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5303 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5304 m_errorMonitor->VerifyFound();
5305
5306 // Wait for queue to complete so we can safely destroy everything
5307 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005308 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5309 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005310 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5311 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5312 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5313 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5314}
5315
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005316TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005317 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005318 ASSERT_NO_FATAL_FAILURE(InitState());
5319
5320 VkImage image;
5321 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5322 VkImageCreateInfo image_create_info = {};
5323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5324 image_create_info.pNext = NULL;
5325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5326 image_create_info.format = tex_format;
5327 image_create_info.extent.width = 32;
5328 image_create_info.extent.height = 32;
5329 image_create_info.extent.depth = 1;
5330 image_create_info.mipLevels = 1;
5331 image_create_info.arrayLayers = 1;
5332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005334 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005335 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005336 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005337 ASSERT_VK_SUCCESS(err);
5338 // Have to bind memory to image before recording cmd in cmd buffer using it
5339 VkMemoryRequirements mem_reqs;
5340 VkDeviceMemory image_mem;
5341 bool pass;
5342 VkMemoryAllocateInfo mem_alloc = {};
5343 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5344 mem_alloc.pNext = NULL;
5345 mem_alloc.memoryTypeIndex = 0;
5346 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5347 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005348 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005349 ASSERT_TRUE(pass);
5350 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5351 ASSERT_VK_SUCCESS(err);
5352
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005353 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005355 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005356
5357 m_commandBuffer->BeginCommandBuffer();
5358 VkClearColorValue ccv;
5359 ccv.float32[0] = 1.0f;
5360 ccv.float32[1] = 1.0f;
5361 ccv.float32[2] = 1.0f;
5362 ccv.float32[3] = 1.0f;
5363 VkImageSubresourceRange isr = {};
5364 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5365 isr.baseArrayLayer = 0;
5366 isr.baseMipLevel = 0;
5367 isr.layerCount = 1;
5368 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005369 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005370 m_commandBuffer->EndCommandBuffer();
5371
5372 m_errorMonitor->VerifyFound();
5373 vkDestroyImage(m_device->device(), image, NULL);
5374 vkFreeMemory(m_device->device(), image_mem, nullptr);
5375}
5376
5377TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005378 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005379 ASSERT_NO_FATAL_FAILURE(InitState());
5380
5381 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 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 -06005383 VK_IMAGE_TILING_OPTIMAL, 0);
5384 ASSERT_TRUE(image.initialized());
5385
5386 VkBuffer buffer;
5387 VkDeviceMemory mem;
5388 VkMemoryRequirements mem_reqs;
5389
5390 VkBufferCreateInfo buf_info = {};
5391 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005392 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005393 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005394 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5395 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5396 ASSERT_VK_SUCCESS(err);
5397
5398 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5399
5400 VkMemoryAllocateInfo alloc_info = {};
5401 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005402 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005403 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005404 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 -06005405 if (!pass) {
5406 vkDestroyBuffer(m_device->device(), buffer, NULL);
5407 return;
5408 }
5409 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5410 ASSERT_VK_SUCCESS(err);
5411
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005412 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005414 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005415 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005416 region.bufferRowLength = 16;
5417 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005418 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5419
5420 region.imageSubresource.layerCount = 1;
5421 region.imageExtent.height = 4;
5422 region.imageExtent.width = 4;
5423 region.imageExtent.depth = 1;
5424 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005425 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5426 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005427 m_commandBuffer->EndCommandBuffer();
5428
5429 m_errorMonitor->VerifyFound();
5430
5431 vkDestroyBuffer(m_device->device(), buffer, NULL);
5432 vkFreeMemory(m_device->handle(), mem, NULL);
5433}
5434
Tobin Ehlis85940f52016-07-07 16:57:21 -06005435TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005436 TEST_DESCRIPTION(
5437 "Attempt to draw with a command buffer that is invalid "
5438 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005439 ASSERT_NO_FATAL_FAILURE(InitState());
5440
5441 VkEvent event;
5442 VkEventCreateInfo evci = {};
5443 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5444 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5445 ASSERT_VK_SUCCESS(result);
5446
5447 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005448 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005449 m_commandBuffer->EndCommandBuffer();
5450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005452 // Destroy event dependency prior to submit to cause ERROR
5453 vkDestroyEvent(m_device->device(), event, NULL);
5454
5455 VkSubmitInfo submit_info = {};
5456 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5457 submit_info.commandBufferCount = 1;
5458 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5459 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5460
5461 m_errorMonitor->VerifyFound();
5462}
5463
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005464TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005465 TEST_DESCRIPTION(
5466 "Attempt to draw with a command buffer that is invalid "
5467 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005468 ASSERT_NO_FATAL_FAILURE(InitState());
5469
5470 VkQueryPool query_pool;
5471 VkQueryPoolCreateInfo qpci{};
5472 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5473 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5474 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005475 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005476 ASSERT_VK_SUCCESS(result);
5477
5478 m_commandBuffer->BeginCommandBuffer();
5479 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5480 m_commandBuffer->EndCommandBuffer();
5481
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005483 // Destroy query pool dependency prior to submit to cause ERROR
5484 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5485
5486 VkSubmitInfo submit_info = {};
5487 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5488 submit_info.commandBufferCount = 1;
5489 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5490 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5491
5492 m_errorMonitor->VerifyFound();
5493}
5494
Tobin Ehlis24130d92016-07-08 15:50:53 -06005495TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005496 TEST_DESCRIPTION(
5497 "Attempt to draw with a command buffer that is invalid "
5498 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005499 ASSERT_NO_FATAL_FAILURE(InitState());
5500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5501
5502 VkResult err;
5503
5504 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5505 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5506
5507 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005508 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005509 ASSERT_VK_SUCCESS(err);
5510
5511 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5512 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5513 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005514 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005515 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005516 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005517 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005518 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005519
5520 VkPipelineShaderStageCreateInfo shaderStages[2];
5521 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5522
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005523 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005524 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 -06005525 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005526 shaderStages[0] = vs.GetStageCreateInfo();
5527 shaderStages[1] = fs.GetStageCreateInfo();
5528
5529 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5530 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5531
5532 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5533 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5534 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5535
5536 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5537 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005538 rs_ci.rasterizerDiscardEnable = true;
5539 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005540
5541 VkPipelineColorBlendAttachmentState att = {};
5542 att.blendEnable = VK_FALSE;
5543 att.colorWriteMask = 0xf;
5544
5545 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5546 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5547 cb_ci.attachmentCount = 1;
5548 cb_ci.pAttachments = &att;
5549
5550 VkGraphicsPipelineCreateInfo gp_ci = {};
5551 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5552 gp_ci.stageCount = 2;
5553 gp_ci.pStages = shaderStages;
5554 gp_ci.pVertexInputState = &vi_ci;
5555 gp_ci.pInputAssemblyState = &ia_ci;
5556 gp_ci.pViewportState = &vp_state_ci;
5557 gp_ci.pRasterizationState = &rs_ci;
5558 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005559 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5560 gp_ci.layout = pipeline_layout;
5561 gp_ci.renderPass = renderPass();
5562
5563 VkPipelineCacheCreateInfo pc_ci = {};
5564 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5565
5566 VkPipeline pipeline;
5567 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005568 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005569 ASSERT_VK_SUCCESS(err);
5570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005571 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005572 ASSERT_VK_SUCCESS(err);
5573
5574 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005575 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005576 m_commandBuffer->EndCommandBuffer();
5577 // Now destroy pipeline in order to cause error when submitting
5578 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005581
5582 VkSubmitInfo submit_info = {};
5583 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5584 submit_info.commandBufferCount = 1;
5585 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5586 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5587
5588 m_errorMonitor->VerifyFound();
5589 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5590 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5591}
5592
Tobin Ehlis31289162016-08-17 14:57:58 -06005593TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005594 TEST_DESCRIPTION(
5595 "Attempt to draw with a command buffer that is invalid "
5596 "due to a bound descriptor set with a buffer dependency "
5597 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005598 ASSERT_NO_FATAL_FAILURE(InitState());
5599 ASSERT_NO_FATAL_FAILURE(InitViewport());
5600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5601
5602 VkDescriptorPoolSize ds_type_count = {};
5603 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5604 ds_type_count.descriptorCount = 1;
5605
5606 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5607 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5608 ds_pool_ci.pNext = NULL;
5609 ds_pool_ci.maxSets = 1;
5610 ds_pool_ci.poolSizeCount = 1;
5611 ds_pool_ci.pPoolSizes = &ds_type_count;
5612
5613 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005614 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005615 ASSERT_VK_SUCCESS(err);
5616
5617 VkDescriptorSetLayoutBinding dsl_binding = {};
5618 dsl_binding.binding = 0;
5619 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5620 dsl_binding.descriptorCount = 1;
5621 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5622 dsl_binding.pImmutableSamplers = NULL;
5623
5624 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5625 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5626 ds_layout_ci.pNext = NULL;
5627 ds_layout_ci.bindingCount = 1;
5628 ds_layout_ci.pBindings = &dsl_binding;
5629 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005630 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005631 ASSERT_VK_SUCCESS(err);
5632
5633 VkDescriptorSet descriptorSet;
5634 VkDescriptorSetAllocateInfo alloc_info = {};
5635 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5636 alloc_info.descriptorSetCount = 1;
5637 alloc_info.descriptorPool = ds_pool;
5638 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005639 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005640 ASSERT_VK_SUCCESS(err);
5641
5642 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5643 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5644 pipeline_layout_ci.pNext = NULL;
5645 pipeline_layout_ci.setLayoutCount = 1;
5646 pipeline_layout_ci.pSetLayouts = &ds_layout;
5647
5648 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 ASSERT_VK_SUCCESS(err);
5651
5652 // Create a buffer to update the descriptor with
5653 uint32_t qfi = 0;
5654 VkBufferCreateInfo buffCI = {};
5655 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5656 buffCI.size = 1024;
5657 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5658 buffCI.queueFamilyIndexCount = 1;
5659 buffCI.pQueueFamilyIndices = &qfi;
5660
5661 VkBuffer buffer;
5662 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5663 ASSERT_VK_SUCCESS(err);
5664 // Allocate memory and bind to buffer so we can make it to the appropriate
5665 // error
5666 VkMemoryAllocateInfo mem_alloc = {};
5667 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5668 mem_alloc.pNext = NULL;
5669 mem_alloc.allocationSize = 1024;
5670 mem_alloc.memoryTypeIndex = 0;
5671
5672 VkMemoryRequirements memReqs;
5673 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005674 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005675 if (!pass) {
5676 vkDestroyBuffer(m_device->device(), buffer, NULL);
5677 return;
5678 }
5679
5680 VkDeviceMemory mem;
5681 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5682 ASSERT_VK_SUCCESS(err);
5683 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5684 ASSERT_VK_SUCCESS(err);
5685 // Correctly update descriptor to avoid "NOT_UPDATED" error
5686 VkDescriptorBufferInfo buffInfo = {};
5687 buffInfo.buffer = buffer;
5688 buffInfo.offset = 0;
5689 buffInfo.range = 1024;
5690
5691 VkWriteDescriptorSet descriptor_write;
5692 memset(&descriptor_write, 0, sizeof(descriptor_write));
5693 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5694 descriptor_write.dstSet = descriptorSet;
5695 descriptor_write.dstBinding = 0;
5696 descriptor_write.descriptorCount = 1;
5697 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5698 descriptor_write.pBufferInfo = &buffInfo;
5699
5700 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5701
5702 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005703 char const *vsSource =
5704 "#version 450\n"
5705 "\n"
5706 "out gl_PerVertex { \n"
5707 " vec4 gl_Position;\n"
5708 "};\n"
5709 "void main(){\n"
5710 " gl_Position = vec4(1);\n"
5711 "}\n";
5712 char const *fsSource =
5713 "#version 450\n"
5714 "\n"
5715 "layout(location=0) out vec4 x;\n"
5716 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5717 "void main(){\n"
5718 " x = vec4(bar.y);\n"
5719 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005720 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5721 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5722 VkPipelineObj pipe(m_device);
5723 pipe.AddShader(&vs);
5724 pipe.AddShader(&fs);
5725 pipe.AddColorAttachment();
5726 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5727
Tony Barbour552f6c02016-12-21 14:34:07 -07005728 m_commandBuffer->BeginCommandBuffer();
5729 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005730 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5731 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5732 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005733
5734 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5735 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5736
Tobin Ehlis31289162016-08-17 14:57:58 -06005737 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005738 m_commandBuffer->EndRenderPass();
5739 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005741 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5742 vkDestroyBuffer(m_device->device(), buffer, NULL);
5743 // Attempt to submit cmd buffer
5744 VkSubmitInfo submit_info = {};
5745 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5746 submit_info.commandBufferCount = 1;
5747 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5748 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5749 m_errorMonitor->VerifyFound();
5750 // Cleanup
5751 vkFreeMemory(m_device->device(), mem, NULL);
5752
5753 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5756}
5757
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005758TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005759 TEST_DESCRIPTION(
5760 "Attempt to draw with a command buffer that is invalid "
5761 "due to a bound descriptor sets with a combined image "
5762 "sampler having their image, sampler, and descriptor set "
5763 "each respectively destroyed and then attempting to "
5764 "submit associated cmd buffers. Attempt to destroy a "
5765 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005766 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005767 ASSERT_NO_FATAL_FAILURE(InitViewport());
5768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5769
5770 VkDescriptorPoolSize ds_type_count = {};
5771 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5772 ds_type_count.descriptorCount = 1;
5773
5774 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5775 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5776 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005777 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005778 ds_pool_ci.maxSets = 1;
5779 ds_pool_ci.poolSizeCount = 1;
5780 ds_pool_ci.pPoolSizes = &ds_type_count;
5781
5782 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005783 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005784 ASSERT_VK_SUCCESS(err);
5785
5786 VkDescriptorSetLayoutBinding dsl_binding = {};
5787 dsl_binding.binding = 0;
5788 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5789 dsl_binding.descriptorCount = 1;
5790 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5791 dsl_binding.pImmutableSamplers = NULL;
5792
5793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5795 ds_layout_ci.pNext = NULL;
5796 ds_layout_ci.bindingCount = 1;
5797 ds_layout_ci.pBindings = &dsl_binding;
5798 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005800 ASSERT_VK_SUCCESS(err);
5801
5802 VkDescriptorSet descriptorSet;
5803 VkDescriptorSetAllocateInfo alloc_info = {};
5804 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5805 alloc_info.descriptorSetCount = 1;
5806 alloc_info.descriptorPool = ds_pool;
5807 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005808 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005809 ASSERT_VK_SUCCESS(err);
5810
5811 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5812 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5813 pipeline_layout_ci.pNext = NULL;
5814 pipeline_layout_ci.setLayoutCount = 1;
5815 pipeline_layout_ci.pSetLayouts = &ds_layout;
5816
5817 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005818 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005819 ASSERT_VK_SUCCESS(err);
5820
5821 // Create images to update the descriptor with
5822 VkImage image;
5823 VkImage image2;
5824 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5825 const int32_t tex_width = 32;
5826 const int32_t tex_height = 32;
5827 VkImageCreateInfo image_create_info = {};
5828 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5829 image_create_info.pNext = NULL;
5830 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5831 image_create_info.format = tex_format;
5832 image_create_info.extent.width = tex_width;
5833 image_create_info.extent.height = tex_height;
5834 image_create_info.extent.depth = 1;
5835 image_create_info.mipLevels = 1;
5836 image_create_info.arrayLayers = 1;
5837 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5838 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5839 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5840 image_create_info.flags = 0;
5841 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5842 ASSERT_VK_SUCCESS(err);
5843 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5844 ASSERT_VK_SUCCESS(err);
5845
5846 VkMemoryRequirements memory_reqs;
5847 VkDeviceMemory image_memory;
5848 bool pass;
5849 VkMemoryAllocateInfo memory_info = {};
5850 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5851 memory_info.pNext = NULL;
5852 memory_info.allocationSize = 0;
5853 memory_info.memoryTypeIndex = 0;
5854 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5855 // Allocate enough memory for both images
5856 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005857 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005858 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005860 ASSERT_VK_SUCCESS(err);
5861 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5862 ASSERT_VK_SUCCESS(err);
5863 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005864 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005865 ASSERT_VK_SUCCESS(err);
5866
5867 VkImageViewCreateInfo image_view_create_info = {};
5868 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5869 image_view_create_info.image = image;
5870 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5871 image_view_create_info.format = tex_format;
5872 image_view_create_info.subresourceRange.layerCount = 1;
5873 image_view_create_info.subresourceRange.baseMipLevel = 0;
5874 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005875 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005876
5877 VkImageView view;
5878 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005880 ASSERT_VK_SUCCESS(err);
5881 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005882 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005883 ASSERT_VK_SUCCESS(err);
5884 // Create Samplers
5885 VkSamplerCreateInfo sampler_ci = {};
5886 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5887 sampler_ci.pNext = NULL;
5888 sampler_ci.magFilter = VK_FILTER_NEAREST;
5889 sampler_ci.minFilter = VK_FILTER_NEAREST;
5890 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5891 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5892 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5893 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5894 sampler_ci.mipLodBias = 1.0;
5895 sampler_ci.anisotropyEnable = VK_FALSE;
5896 sampler_ci.maxAnisotropy = 1;
5897 sampler_ci.compareEnable = VK_FALSE;
5898 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5899 sampler_ci.minLod = 1.0;
5900 sampler_ci.maxLod = 1.0;
5901 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5902 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5903 VkSampler sampler;
5904 VkSampler sampler2;
5905 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5906 ASSERT_VK_SUCCESS(err);
5907 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5908 ASSERT_VK_SUCCESS(err);
5909 // Update descriptor with image and sampler
5910 VkDescriptorImageInfo img_info = {};
5911 img_info.sampler = sampler;
5912 img_info.imageView = view;
5913 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5914
5915 VkWriteDescriptorSet descriptor_write;
5916 memset(&descriptor_write, 0, sizeof(descriptor_write));
5917 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5918 descriptor_write.dstSet = descriptorSet;
5919 descriptor_write.dstBinding = 0;
5920 descriptor_write.descriptorCount = 1;
5921 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5922 descriptor_write.pImageInfo = &img_info;
5923
5924 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5925
5926 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005927 char const *vsSource =
5928 "#version 450\n"
5929 "\n"
5930 "out gl_PerVertex { \n"
5931 " vec4 gl_Position;\n"
5932 "};\n"
5933 "void main(){\n"
5934 " gl_Position = vec4(1);\n"
5935 "}\n";
5936 char const *fsSource =
5937 "#version 450\n"
5938 "\n"
5939 "layout(set=0, binding=0) uniform sampler2D s;\n"
5940 "layout(location=0) out vec4 x;\n"
5941 "void main(){\n"
5942 " x = texture(s, vec2(1));\n"
5943 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005944 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5945 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5946 VkPipelineObj pipe(m_device);
5947 pipe.AddShader(&vs);
5948 pipe.AddShader(&fs);
5949 pipe.AddColorAttachment();
5950 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5951
5952 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005954 m_commandBuffer->BeginCommandBuffer();
5955 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005956 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5957 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5958 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005959 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5960 VkRect2D scissor = {{0, 0}, {16, 16}};
5961 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5962 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005963 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005964 m_commandBuffer->EndRenderPass();
5965 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005966 // Destroy sampler invalidates the cmd buffer, causing error on submit
5967 vkDestroySampler(m_device->device(), sampler, NULL);
5968 // Attempt to submit cmd buffer
5969 VkSubmitInfo submit_info = {};
5970 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5971 submit_info.commandBufferCount = 1;
5972 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5973 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5974 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005975
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005976 // Now re-update descriptor with valid sampler and delete image
5977 img_info.sampler = sampler2;
5978 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005979
5980 VkCommandBufferBeginInfo info = {};
5981 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5982 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005985 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005986 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005987 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5988 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5989 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005990 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5991 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005992 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005993 m_commandBuffer->EndRenderPass();
5994 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005995 // Destroy image invalidates the cmd buffer, causing error on submit
5996 vkDestroyImage(m_device->device(), image, NULL);
5997 // Attempt to submit cmd buffer
5998 submit_info = {};
5999 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6000 submit_info.commandBufferCount = 1;
6001 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6002 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6003 m_errorMonitor->VerifyFound();
6004 // Now update descriptor to be valid, but then free descriptor
6005 img_info.imageView = view2;
6006 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006007 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006008 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006009 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6010 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6011 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006012 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6013 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006014 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006015 m_commandBuffer->EndRenderPass();
6016 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006017 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006018
6019 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006021 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006022 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006023
6024 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006025 // 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 -07006026 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006027 m_errorMonitor->SetUnexpectedError(
6028 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6029 "either be a valid handle or VK_NULL_HANDLE");
6030 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006031 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6032
6033 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006034 submit_info = {};
6035 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6036 submit_info.commandBufferCount = 1;
6037 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006039 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6040 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006041
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006042 // Cleanup
6043 vkFreeMemory(m_device->device(), image_memory, NULL);
6044 vkDestroySampler(m_device->device(), sampler2, NULL);
6045 vkDestroyImage(m_device->device(), image2, NULL);
6046 vkDestroyImageView(m_device->device(), view, NULL);
6047 vkDestroyImageView(m_device->device(), view2, NULL);
6048 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6049 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6050 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6051}
6052
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006053TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6054 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6055 ASSERT_NO_FATAL_FAILURE(InitState());
6056 ASSERT_NO_FATAL_FAILURE(InitViewport());
6057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6058
6059 VkDescriptorPoolSize ds_type_count = {};
6060 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6061 ds_type_count.descriptorCount = 1;
6062
6063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6065 ds_pool_ci.pNext = NULL;
6066 ds_pool_ci.maxSets = 1;
6067 ds_pool_ci.poolSizeCount = 1;
6068 ds_pool_ci.pPoolSizes = &ds_type_count;
6069
6070 VkDescriptorPool ds_pool;
6071 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6072 ASSERT_VK_SUCCESS(err);
6073
6074 VkDescriptorSetLayoutBinding dsl_binding = {};
6075 dsl_binding.binding = 0;
6076 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6077 dsl_binding.descriptorCount = 1;
6078 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6079 dsl_binding.pImmutableSamplers = NULL;
6080
6081 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6082 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6083 ds_layout_ci.pNext = NULL;
6084 ds_layout_ci.bindingCount = 1;
6085 ds_layout_ci.pBindings = &dsl_binding;
6086 VkDescriptorSetLayout ds_layout;
6087 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6088 ASSERT_VK_SUCCESS(err);
6089
6090 VkDescriptorSet descriptor_set;
6091 VkDescriptorSetAllocateInfo alloc_info = {};
6092 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6093 alloc_info.descriptorSetCount = 1;
6094 alloc_info.descriptorPool = ds_pool;
6095 alloc_info.pSetLayouts = &ds_layout;
6096 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6097 ASSERT_VK_SUCCESS(err);
6098
6099 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6100 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6101 pipeline_layout_ci.pNext = NULL;
6102 pipeline_layout_ci.setLayoutCount = 1;
6103 pipeline_layout_ci.pSetLayouts = &ds_layout;
6104
6105 VkPipelineLayout pipeline_layout;
6106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6107 ASSERT_VK_SUCCESS(err);
6108
6109 // Create image to update the descriptor with
6110 VkImageObj image(m_device);
6111 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6112 ASSERT_TRUE(image.initialized());
6113
6114 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6115 // Create Sampler
6116 VkSamplerCreateInfo sampler_ci = {};
6117 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6118 sampler_ci.pNext = NULL;
6119 sampler_ci.magFilter = VK_FILTER_NEAREST;
6120 sampler_ci.minFilter = VK_FILTER_NEAREST;
6121 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6122 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6123 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6124 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6125 sampler_ci.mipLodBias = 1.0;
6126 sampler_ci.anisotropyEnable = VK_FALSE;
6127 sampler_ci.maxAnisotropy = 1;
6128 sampler_ci.compareEnable = VK_FALSE;
6129 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6130 sampler_ci.minLod = 1.0;
6131 sampler_ci.maxLod = 1.0;
6132 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6133 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6134 VkSampler sampler;
6135 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6136 ASSERT_VK_SUCCESS(err);
6137 // Update descriptor with image and sampler
6138 VkDescriptorImageInfo img_info = {};
6139 img_info.sampler = sampler;
6140 img_info.imageView = view;
6141 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6142
6143 VkWriteDescriptorSet descriptor_write;
6144 memset(&descriptor_write, 0, sizeof(descriptor_write));
6145 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6146 descriptor_write.dstSet = descriptor_set;
6147 descriptor_write.dstBinding = 0;
6148 descriptor_write.descriptorCount = 1;
6149 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6150 descriptor_write.pImageInfo = &img_info;
6151
6152 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6153
6154 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006155 char const *vsSource =
6156 "#version 450\n"
6157 "\n"
6158 "out gl_PerVertex { \n"
6159 " vec4 gl_Position;\n"
6160 "};\n"
6161 "void main(){\n"
6162 " gl_Position = vec4(1);\n"
6163 "}\n";
6164 char const *fsSource =
6165 "#version 450\n"
6166 "\n"
6167 "layout(set=0, binding=0) uniform sampler2D s;\n"
6168 "layout(location=0) out vec4 x;\n"
6169 "void main(){\n"
6170 " x = texture(s, vec2(1));\n"
6171 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006172 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6173 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6174 VkPipelineObj pipe(m_device);
6175 pipe.AddShader(&vs);
6176 pipe.AddShader(&fs);
6177 pipe.AddColorAttachment();
6178 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6179
Tony Barbour552f6c02016-12-21 14:34:07 -07006180 m_commandBuffer->BeginCommandBuffer();
6181 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006182 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6183 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6184 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006185
6186 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6187 VkRect2D scissor = {{0, 0}, {16, 16}};
6188 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6189 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6190
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006191 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006192 m_commandBuffer->EndRenderPass();
6193 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006194 // Submit cmd buffer to put pool in-flight
6195 VkSubmitInfo submit_info = {};
6196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6197 submit_info.commandBufferCount = 1;
6198 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6199 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6200 // Destroy pool while in-flight, causing error
6201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6203 m_errorMonitor->VerifyFound();
6204 vkQueueWaitIdle(m_device->m_queue);
6205 // Cleanup
6206 vkDestroySampler(m_device->device(), sampler, NULL);
6207 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6208 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006209 m_errorMonitor->SetUnexpectedError(
6210 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6211 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006212 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006213 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006214}
6215
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006216TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6217 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6218 ASSERT_NO_FATAL_FAILURE(InitState());
6219 ASSERT_NO_FATAL_FAILURE(InitViewport());
6220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6221
6222 VkDescriptorPoolSize ds_type_count = {};
6223 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6224 ds_type_count.descriptorCount = 1;
6225
6226 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6227 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6228 ds_pool_ci.pNext = NULL;
6229 ds_pool_ci.maxSets = 1;
6230 ds_pool_ci.poolSizeCount = 1;
6231 ds_pool_ci.pPoolSizes = &ds_type_count;
6232
6233 VkDescriptorPool ds_pool;
6234 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6235 ASSERT_VK_SUCCESS(err);
6236
6237 VkDescriptorSetLayoutBinding dsl_binding = {};
6238 dsl_binding.binding = 0;
6239 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6240 dsl_binding.descriptorCount = 1;
6241 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6242 dsl_binding.pImmutableSamplers = NULL;
6243
6244 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6245 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6246 ds_layout_ci.pNext = NULL;
6247 ds_layout_ci.bindingCount = 1;
6248 ds_layout_ci.pBindings = &dsl_binding;
6249 VkDescriptorSetLayout ds_layout;
6250 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6251 ASSERT_VK_SUCCESS(err);
6252
6253 VkDescriptorSet descriptorSet;
6254 VkDescriptorSetAllocateInfo alloc_info = {};
6255 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6256 alloc_info.descriptorSetCount = 1;
6257 alloc_info.descriptorPool = ds_pool;
6258 alloc_info.pSetLayouts = &ds_layout;
6259 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6260 ASSERT_VK_SUCCESS(err);
6261
6262 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6263 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6264 pipeline_layout_ci.pNext = NULL;
6265 pipeline_layout_ci.setLayoutCount = 1;
6266 pipeline_layout_ci.pSetLayouts = &ds_layout;
6267
6268 VkPipelineLayout pipeline_layout;
6269 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6270 ASSERT_VK_SUCCESS(err);
6271
6272 // Create images to update the descriptor with
6273 VkImage image;
6274 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6275 const int32_t tex_width = 32;
6276 const int32_t tex_height = 32;
6277 VkImageCreateInfo image_create_info = {};
6278 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6279 image_create_info.pNext = NULL;
6280 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6281 image_create_info.format = tex_format;
6282 image_create_info.extent.width = tex_width;
6283 image_create_info.extent.height = tex_height;
6284 image_create_info.extent.depth = 1;
6285 image_create_info.mipLevels = 1;
6286 image_create_info.arrayLayers = 1;
6287 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6288 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6289 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6290 image_create_info.flags = 0;
6291 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6292 ASSERT_VK_SUCCESS(err);
6293 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6294 VkMemoryRequirements memory_reqs;
6295 VkDeviceMemory image_memory;
6296 bool pass;
6297 VkMemoryAllocateInfo memory_info = {};
6298 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6299 memory_info.pNext = NULL;
6300 memory_info.allocationSize = 0;
6301 memory_info.memoryTypeIndex = 0;
6302 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6303 // Allocate enough memory for image
6304 memory_info.allocationSize = memory_reqs.size;
6305 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6306 ASSERT_TRUE(pass);
6307 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6308 ASSERT_VK_SUCCESS(err);
6309 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6310 ASSERT_VK_SUCCESS(err);
6311
6312 VkImageViewCreateInfo image_view_create_info = {};
6313 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6314 image_view_create_info.image = image;
6315 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6316 image_view_create_info.format = tex_format;
6317 image_view_create_info.subresourceRange.layerCount = 1;
6318 image_view_create_info.subresourceRange.baseMipLevel = 0;
6319 image_view_create_info.subresourceRange.levelCount = 1;
6320 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6321
6322 VkImageView view;
6323 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6324 ASSERT_VK_SUCCESS(err);
6325 // Create Samplers
6326 VkSamplerCreateInfo sampler_ci = {};
6327 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6328 sampler_ci.pNext = NULL;
6329 sampler_ci.magFilter = VK_FILTER_NEAREST;
6330 sampler_ci.minFilter = VK_FILTER_NEAREST;
6331 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6332 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6333 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6334 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6335 sampler_ci.mipLodBias = 1.0;
6336 sampler_ci.anisotropyEnable = VK_FALSE;
6337 sampler_ci.maxAnisotropy = 1;
6338 sampler_ci.compareEnable = VK_FALSE;
6339 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6340 sampler_ci.minLod = 1.0;
6341 sampler_ci.maxLod = 1.0;
6342 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6343 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6344 VkSampler sampler;
6345 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6346 ASSERT_VK_SUCCESS(err);
6347 // Update descriptor with image and sampler
6348 VkDescriptorImageInfo img_info = {};
6349 img_info.sampler = sampler;
6350 img_info.imageView = view;
6351 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6352
6353 VkWriteDescriptorSet descriptor_write;
6354 memset(&descriptor_write, 0, sizeof(descriptor_write));
6355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6356 descriptor_write.dstSet = descriptorSet;
6357 descriptor_write.dstBinding = 0;
6358 descriptor_write.descriptorCount = 1;
6359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6360 descriptor_write.pImageInfo = &img_info;
6361 // Break memory binding and attempt update
6362 vkFreeMemory(m_device->device(), image_memory, nullptr);
6363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006364 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6366 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6367 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6368 m_errorMonitor->VerifyFound();
6369 // Cleanup
6370 vkDestroyImage(m_device->device(), image, NULL);
6371 vkDestroySampler(m_device->device(), sampler, NULL);
6372 vkDestroyImageView(m_device->device(), view, NULL);
6373 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6376}
6377
Karl Schultz6addd812016-02-02 17:17:23 -07006378TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006379 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6380 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006381 // Create a valid cmd buffer
6382 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006383 uint64_t fake_pipeline_handle = 0xbaad6001;
6384 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006385 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6387
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006389 m_commandBuffer->BeginCommandBuffer();
6390 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006391 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006392 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006393
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006394 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006396 Draw(1, 0, 0, 0);
6397 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006398
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006399 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006400 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 -07006401 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006402 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6403 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006404}
6405
Karl Schultz6addd812016-02-02 17:17:23 -07006406TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006407 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006408 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006411
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006412 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006413 ASSERT_NO_FATAL_FAILURE(InitViewport());
6414 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006415 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006416 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6417 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006418
6419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6421 ds_pool_ci.pNext = NULL;
6422 ds_pool_ci.maxSets = 1;
6423 ds_pool_ci.poolSizeCount = 1;
6424 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006425
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006426 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006427 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006428 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006429
Tony Barboureb254902015-07-15 12:50:33 -06006430 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006431 dsl_binding.binding = 0;
6432 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6433 dsl_binding.descriptorCount = 1;
6434 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6435 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006436
Tony Barboureb254902015-07-15 12:50:33 -06006437 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006438 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6439 ds_layout_ci.pNext = NULL;
6440 ds_layout_ci.bindingCount = 1;
6441 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006442 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006444 ASSERT_VK_SUCCESS(err);
6445
6446 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006447 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006448 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006449 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006450 alloc_info.descriptorPool = ds_pool;
6451 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006452 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006453 ASSERT_VK_SUCCESS(err);
6454
Tony Barboureb254902015-07-15 12:50:33 -06006455 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006456 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6457 pipeline_layout_ci.pNext = NULL;
6458 pipeline_layout_ci.setLayoutCount = 1;
6459 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006460
6461 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006463 ASSERT_VK_SUCCESS(err);
6464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006466 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006467 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006468 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006469
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006470 VkPipelineObj pipe(m_device);
6471 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006472 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006473 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006474 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006475
Tony Barbour552f6c02016-12-21 14:34:07 -07006476 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006477 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6479 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006480
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006481 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006482
Chia-I Wuf7458c52015-10-26 21:10:41 +08006483 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006486}
6487
Karl Schultz6addd812016-02-02 17:17:23 -07006488TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006489 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006490 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006491
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006493
6494 ASSERT_NO_FATAL_FAILURE(InitState());
6495 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006496 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6497 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006498
6499 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006500 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6501 ds_pool_ci.pNext = NULL;
6502 ds_pool_ci.maxSets = 1;
6503 ds_pool_ci.poolSizeCount = 1;
6504 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006505
6506 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006508 ASSERT_VK_SUCCESS(err);
6509
6510 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006511 dsl_binding.binding = 0;
6512 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6513 dsl_binding.descriptorCount = 1;
6514 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6515 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006516
6517 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006518 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6519 ds_layout_ci.pNext = NULL;
6520 ds_layout_ci.bindingCount = 1;
6521 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006522 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006523 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006524 ASSERT_VK_SUCCESS(err);
6525
6526 VkDescriptorSet descriptorSet;
6527 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006528 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006529 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006530 alloc_info.descriptorPool = ds_pool;
6531 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006532 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006533 ASSERT_VK_SUCCESS(err);
6534
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006535 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006536 VkWriteDescriptorSet descriptor_write;
6537 memset(&descriptor_write, 0, sizeof(descriptor_write));
6538 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6539 descriptor_write.dstSet = descriptorSet;
6540 descriptor_write.dstBinding = 0;
6541 descriptor_write.descriptorCount = 1;
6542 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6543 descriptor_write.pTexelBufferView = &view;
6544
6545 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6546
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006547 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006548
6549 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6550 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6551}
6552
Mark Youngd339ba32016-05-30 13:28:35 -06006553TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006554 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 -06006555
6556 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006558 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006559
6560 ASSERT_NO_FATAL_FAILURE(InitState());
6561
6562 // Create a buffer with no bound memory and then attempt to create
6563 // a buffer view.
6564 VkBufferCreateInfo buff_ci = {};
6565 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006566 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006567 buff_ci.size = 256;
6568 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6569 VkBuffer buffer;
6570 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6571 ASSERT_VK_SUCCESS(err);
6572
6573 VkBufferViewCreateInfo buff_view_ci = {};
6574 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6575 buff_view_ci.buffer = buffer;
6576 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6577 buff_view_ci.range = VK_WHOLE_SIZE;
6578 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006579 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006580
6581 m_errorMonitor->VerifyFound();
6582 vkDestroyBuffer(m_device->device(), buffer, NULL);
6583 // If last error is success, it still created the view, so delete it.
6584 if (err == VK_SUCCESS) {
6585 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6586 }
6587}
6588
Karl Schultz6addd812016-02-02 17:17:23 -07006589TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6590 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6591 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006592 // 1. No dynamicOffset supplied
6593 // 2. Too many dynamicOffsets supplied
6594 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006595 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6597 " requires 1 dynamicOffsets, but only "
6598 "0 dynamicOffsets are left in "
6599 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006600
6601 ASSERT_NO_FATAL_FAILURE(InitState());
6602 ASSERT_NO_FATAL_FAILURE(InitViewport());
6603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6604
6605 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006606 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6607 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006608
6609 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006610 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6611 ds_pool_ci.pNext = NULL;
6612 ds_pool_ci.maxSets = 1;
6613 ds_pool_ci.poolSizeCount = 1;
6614 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006615
6616 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006618 ASSERT_VK_SUCCESS(err);
6619
6620 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006621 dsl_binding.binding = 0;
6622 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6623 dsl_binding.descriptorCount = 1;
6624 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6625 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006626
6627 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006628 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6629 ds_layout_ci.pNext = NULL;
6630 ds_layout_ci.bindingCount = 1;
6631 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006632 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006634 ASSERT_VK_SUCCESS(err);
6635
6636 VkDescriptorSet descriptorSet;
6637 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006638 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006639 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006640 alloc_info.descriptorPool = ds_pool;
6641 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006642 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006643 ASSERT_VK_SUCCESS(err);
6644
6645 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006646 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6647 pipeline_layout_ci.pNext = NULL;
6648 pipeline_layout_ci.setLayoutCount = 1;
6649 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006650
6651 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006652 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006653 ASSERT_VK_SUCCESS(err);
6654
6655 // Create a buffer to update the descriptor with
6656 uint32_t qfi = 0;
6657 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006658 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6659 buffCI.size = 1024;
6660 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6661 buffCI.queueFamilyIndexCount = 1;
6662 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006663
6664 VkBuffer dyub;
6665 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6666 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006667 // Allocate memory and bind to buffer so we can make it to the appropriate
6668 // error
6669 VkMemoryAllocateInfo mem_alloc = {};
6670 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6671 mem_alloc.pNext = NULL;
6672 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006673 mem_alloc.memoryTypeIndex = 0;
6674
6675 VkMemoryRequirements memReqs;
6676 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006677 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006678 if (!pass) {
6679 vkDestroyBuffer(m_device->device(), dyub, NULL);
6680 return;
6681 }
6682
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006683 VkDeviceMemory mem;
6684 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6685 ASSERT_VK_SUCCESS(err);
6686 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6687 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006688 // Correctly update descriptor to avoid "NOT_UPDATED" error
6689 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006690 buffInfo.buffer = dyub;
6691 buffInfo.offset = 0;
6692 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006693
6694 VkWriteDescriptorSet descriptor_write;
6695 memset(&descriptor_write, 0, sizeof(descriptor_write));
6696 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6697 descriptor_write.dstSet = descriptorSet;
6698 descriptor_write.dstBinding = 0;
6699 descriptor_write.descriptorCount = 1;
6700 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6701 descriptor_write.pBufferInfo = &buffInfo;
6702
6703 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6704
Tony Barbour552f6c02016-12-21 14:34:07 -07006705 m_commandBuffer->BeginCommandBuffer();
6706 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006707 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6708 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006709 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006710 uint32_t pDynOff[2] = {512, 756};
6711 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6713 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6714 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6715 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006716 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006717 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6719 " dynamic offset 512 combined with "
6720 "offset 0 and range 1024 that "
6721 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006722 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006723 char const *vsSource =
6724 "#version 450\n"
6725 "\n"
6726 "out gl_PerVertex { \n"
6727 " vec4 gl_Position;\n"
6728 "};\n"
6729 "void main(){\n"
6730 " gl_Position = vec4(1);\n"
6731 "}\n";
6732 char const *fsSource =
6733 "#version 450\n"
6734 "\n"
6735 "layout(location=0) out vec4 x;\n"
6736 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6737 "void main(){\n"
6738 " x = vec4(bar.y);\n"
6739 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6742 VkPipelineObj pipe(m_device);
6743 pipe.AddShader(&vs);
6744 pipe.AddShader(&fs);
6745 pipe.AddColorAttachment();
6746 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6747
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006748 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6749 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6750 VkRect2D scissor = {{0, 0}, {16, 16}};
6751 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006753 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006754 // This update should succeed, but offset size of 512 will overstep buffer
6755 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006756 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6757 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006758 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006760
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006761 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006762 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006763
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006764 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006765 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006766 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6767}
6768
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006769TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006770 TEST_DESCRIPTION(
6771 "Attempt to update a descriptor with a non-sparse buffer "
6772 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006773 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006775 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6777 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006778
6779 ASSERT_NO_FATAL_FAILURE(InitState());
6780 ASSERT_NO_FATAL_FAILURE(InitViewport());
6781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6782
6783 VkDescriptorPoolSize ds_type_count = {};
6784 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6785 ds_type_count.descriptorCount = 1;
6786
6787 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6788 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6789 ds_pool_ci.pNext = NULL;
6790 ds_pool_ci.maxSets = 1;
6791 ds_pool_ci.poolSizeCount = 1;
6792 ds_pool_ci.pPoolSizes = &ds_type_count;
6793
6794 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006795 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006796 ASSERT_VK_SUCCESS(err);
6797
6798 VkDescriptorSetLayoutBinding dsl_binding = {};
6799 dsl_binding.binding = 0;
6800 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6801 dsl_binding.descriptorCount = 1;
6802 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6803 dsl_binding.pImmutableSamplers = NULL;
6804
6805 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6806 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6807 ds_layout_ci.pNext = NULL;
6808 ds_layout_ci.bindingCount = 1;
6809 ds_layout_ci.pBindings = &dsl_binding;
6810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006812 ASSERT_VK_SUCCESS(err);
6813
6814 VkDescriptorSet descriptorSet;
6815 VkDescriptorSetAllocateInfo alloc_info = {};
6816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6817 alloc_info.descriptorSetCount = 1;
6818 alloc_info.descriptorPool = ds_pool;
6819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006821 ASSERT_VK_SUCCESS(err);
6822
6823 // Create a buffer to update the descriptor with
6824 uint32_t qfi = 0;
6825 VkBufferCreateInfo buffCI = {};
6826 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6827 buffCI.size = 1024;
6828 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6829 buffCI.queueFamilyIndexCount = 1;
6830 buffCI.pQueueFamilyIndices = &qfi;
6831
6832 VkBuffer dyub;
6833 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6834 ASSERT_VK_SUCCESS(err);
6835
6836 // Attempt to update descriptor without binding memory to it
6837 VkDescriptorBufferInfo buffInfo = {};
6838 buffInfo.buffer = dyub;
6839 buffInfo.offset = 0;
6840 buffInfo.range = 1024;
6841
6842 VkWriteDescriptorSet descriptor_write;
6843 memset(&descriptor_write, 0, sizeof(descriptor_write));
6844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6845 descriptor_write.dstSet = descriptorSet;
6846 descriptor_write.dstBinding = 0;
6847 descriptor_write.descriptorCount = 1;
6848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6849 descriptor_write.pBufferInfo = &buffInfo;
6850
6851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6852 m_errorMonitor->VerifyFound();
6853
6854 vkDestroyBuffer(m_device->device(), dyub, NULL);
6855 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6857}
6858
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006859TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006860 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006861 ASSERT_NO_FATAL_FAILURE(InitState());
6862 ASSERT_NO_FATAL_FAILURE(InitViewport());
6863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6864
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006865 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006866 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006867 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6868 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6869 pipeline_layout_ci.pushConstantRangeCount = 1;
6870 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6871
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006872 //
6873 // Check for invalid push constant ranges in pipeline layouts.
6874 //
6875 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006876 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006877 char const *msg;
6878 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006879
Karl Schultzc81037d2016-05-12 08:11:23 -06006880 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6881 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6882 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6883 "vkCreatePipelineLayout() call has push constants index 0 with "
6884 "size 0."},
6885 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6886 "vkCreatePipelineLayout() call has push constants index 0 with "
6887 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006888 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006889 "vkCreatePipelineLayout() call has push constants index 0 with "
6890 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006891 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006892 "vkCreatePipelineLayout() call has push constants index 0 with "
6893 "size 0."},
6894 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6895 "vkCreatePipelineLayout() call has push constants index 0 with "
6896 "offset 1. Offset must"},
6897 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6898 "vkCreatePipelineLayout() call has push constants index 0 "
6899 "with offset "},
6900 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6901 "vkCreatePipelineLayout() call has push constants "
6902 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006903 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006904 "vkCreatePipelineLayout() call has push constants index 0 "
6905 "with offset "},
6906 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6907 "vkCreatePipelineLayout() call has push "
6908 "constants index 0 with offset "},
6909 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6910 "vkCreatePipelineLayout() call has push "
6911 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006912 }};
6913
6914 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006915 for (const auto &iter : range_tests) {
6916 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6918 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006919 m_errorMonitor->VerifyFound();
6920 if (VK_SUCCESS == err) {
6921 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6922 }
6923 }
6924
6925 // Check for invalid stage flag
6926 pc_range.offset = 0;
6927 pc_range.size = 16;
6928 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006929 m_errorMonitor->SetDesiredFailureMsg(
6930 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6931 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006932 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006933 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006934 if (VK_SUCCESS == err) {
6935 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6936 }
6937
Karl Schultzc59b72d2017-02-24 15:45:05 -07006938 // Check for duplicate stage flags in a list of push constant ranges.
6939 // A shader can only have one push constant block and that block is mapped
6940 // to the push constant range that has that shader's stage flag set.
6941 // The shader's stage flag can only appear once in all the ranges, so the
6942 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006943 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006944 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006945 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006946 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006947 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006948 // Overlapping ranges are OK, but a stage flag can appear only once.
6949 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6950 {
6951 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6952 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6953 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6954 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006955 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006956 {
6957 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6960 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6961 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6962 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6963 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6964 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6965 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6966 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6967 }},
6968 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6969 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6970 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6971 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6972 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6973 {
6974 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6975 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6976 }},
6977 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6978 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6979 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6980 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6981 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6982 {
6983 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6984 }},
6985 },
6986 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006987
Karl Schultzc59b72d2017-02-24 15:45:05 -07006988 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006989 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006990 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006992 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006993 m_errorMonitor->VerifyFound();
6994 if (VK_SUCCESS == err) {
6995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6996 }
6997 }
6998
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006999 //
7000 // CmdPushConstants tests
7001 //
7002
Karl Schultzc59b72d2017-02-24 15:45:05 -07007003 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007004 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007005 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007006 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007007 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007008 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007010 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007011
7012 const uint8_t dummy_values[100] = {};
7013
7014 m_commandBuffer->BeginCommandBuffer();
7015 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007016
7017 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007018 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007020 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007021 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007022
Karl Schultzc59b72d2017-02-24 15:45:05 -07007023 m_errorMonitor->ExpectSuccess();
7024 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7025 m_errorMonitor->VerifyNotFound();
7026 m_errorMonitor->ExpectSuccess();
7027 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7028 m_errorMonitor->VerifyNotFound();
7029 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7030 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7031 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7032 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7033 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7034 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7035 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007036 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007037 for (const auto &iter : cmd_range_tests) {
7038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7039 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7040 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007041 m_errorMonitor->VerifyFound();
7042 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007043
Tony Barbour552f6c02016-12-21 14:34:07 -07007044 m_commandBuffer->EndRenderPass();
7045 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007046 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007047}
7048
Karl Schultz6addd812016-02-02 17:17:23 -07007049TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007050 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007051 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007052
7053 ASSERT_NO_FATAL_FAILURE(InitState());
7054 ASSERT_NO_FATAL_FAILURE(InitViewport());
7055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7056
7057 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7058 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7060 ds_type_count[0].descriptorCount = 10;
7061 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7062 ds_type_count[1].descriptorCount = 2;
7063 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7064 ds_type_count[2].descriptorCount = 2;
7065 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7066 ds_type_count[3].descriptorCount = 5;
7067 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7068 // type
7069 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7070 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7071 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007072
7073 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007074 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7075 ds_pool_ci.pNext = NULL;
7076 ds_pool_ci.maxSets = 5;
7077 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7078 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007079
7080 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007081 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007082 ASSERT_VK_SUCCESS(err);
7083
7084 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7085 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007086 dsl_binding[0].binding = 0;
7087 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7088 dsl_binding[0].descriptorCount = 5;
7089 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7090 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007091
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007092 // Create layout identical to set0 layout but w/ different stageFlags
7093 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007094 dsl_fs_stage_only.binding = 0;
7095 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7096 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007097 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7098 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007099 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7102 ds_layout_ci.pNext = NULL;
7103 ds_layout_ci.bindingCount = 1;
7104 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007105 static const uint32_t NUM_LAYOUTS = 4;
7106 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007107 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007108 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7109 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007111 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007112 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007113 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007114 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007115 dsl_binding[0].binding = 0;
7116 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007117 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007118 dsl_binding[1].binding = 1;
7119 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7120 dsl_binding[1].descriptorCount = 2;
7121 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7122 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007123 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007124 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007126 ASSERT_VK_SUCCESS(err);
7127 dsl_binding[0].binding = 0;
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007130 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007132 ASSERT_VK_SUCCESS(err);
7133 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007134 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007136 ASSERT_VK_SUCCESS(err);
7137
7138 static const uint32_t NUM_SETS = 4;
7139 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7140 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007142 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007143 alloc_info.descriptorPool = ds_pool;
7144 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007147 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007148 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007149 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007151 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007152
7153 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007154 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7155 pipeline_layout_ci.pNext = NULL;
7156 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7157 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007158
7159 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007161 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007162 // Create pipelineLayout with only one setLayout
7163 pipeline_layout_ci.setLayoutCount = 1;
7164 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout with 2 descriptor setLayout at index 0
7168 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7169 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007171 ASSERT_VK_SUCCESS(err);
7172 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7173 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7174 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
7177 // Create pipelineLayout with UB type, but stageFlags for FS only
7178 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7179 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007181 ASSERT_VK_SUCCESS(err);
7182 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7183 VkDescriptorSetLayout pl_bad_s0[2] = {};
7184 pl_bad_s0[0] = ds_layout_fs_only;
7185 pl_bad_s0[1] = ds_layout[1];
7186 pipeline_layout_ci.setLayoutCount = 2;
7187 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7188 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007189 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007190 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007191
Tobin Ehlis88452832015-12-03 09:40:56 -07007192 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007193 char const *vsSource =
7194 "#version 450\n"
7195 "\n"
7196 "out gl_PerVertex {\n"
7197 " vec4 gl_Position;\n"
7198 "};\n"
7199 "void main(){\n"
7200 " gl_Position = vec4(1);\n"
7201 "}\n";
7202 char const *fsSource =
7203 "#version 450\n"
7204 "\n"
7205 "layout(location=0) out vec4 x;\n"
7206 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7207 "void main(){\n"
7208 " x = vec4(bar.y);\n"
7209 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007212 VkPipelineObj pipe(m_device);
7213 pipe.AddShader(&vs);
7214 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007215 pipe.AddColorAttachment();
7216 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007217
Tony Barbour552f6c02016-12-21 14:34:07 -07007218 m_commandBuffer->BeginCommandBuffer();
7219 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007222 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7223 // of PSO
7224 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7225 // cmd_pipeline.c
7226 // due to the fact that cmd_alloc_dset_data() has not been called in
7227 // cmd_bind_graphics_pipeline()
7228 // TODO : Want to cause various binding incompatibility issues here to test
7229 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007230 // First cause various verify_layout_compatibility() fails
7231 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007232 // verify_set_layout_compatibility fail cases:
7233 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7236 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007237 m_errorMonitor->VerifyFound();
7238
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007239 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7241 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7242 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007243 m_errorMonitor->VerifyFound();
7244
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007245 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007246 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7247 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7250 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007251 m_errorMonitor->VerifyFound();
7252
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007253 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7254 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7257 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007258 m_errorMonitor->VerifyFound();
7259
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007260 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7261 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7263 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7264 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7265 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007266 m_errorMonitor->VerifyFound();
7267
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007268 // Cause INFO messages due to disturbing previously bound Sets
7269 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7271 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007272 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7275 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007276 m_errorMonitor->VerifyFound();
7277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7279 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007280 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7282 " newly bound as set #0 so set #1 and "
7283 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7285 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007286 m_errorMonitor->VerifyFound();
7287
Tobin Ehlis10fad692016-07-07 12:00:36 -06007288 // Now that we're done actively using the pipelineLayout that gfx pipeline
7289 // was created with, we should be able to delete it. Do that now to verify
7290 // that validation obeys pipelineLayout lifetime
7291 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7292
Tobin Ehlis88452832015-12-03 09:40:56 -07007293 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007294 // 1. Error due to not binding required set (we actually use same code as
7295 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7297 &descriptorSet[0], 0, NULL);
7298 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7299 &descriptorSet[1], 0, NULL);
7300 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 -07007301
7302 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7303 VkRect2D scissor = {{0, 0}, {16, 16}};
7304 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7305 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7306
Tobin Ehlis88452832015-12-03 09:40:56 -07007307 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007308 m_errorMonitor->VerifyFound();
7309
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007310 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007311 // 2. Error due to bound set not being compatible with PSO's
7312 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7314 &descriptorSet[0], 0, NULL);
7315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007316 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007317 m_errorMonitor->VerifyFound();
7318
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007319 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007320 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007321 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7322 }
7323 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007324 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7325 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7326}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007327
Karl Schultz6addd812016-02-02 17:17:23 -07007328TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7330 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007331
7332 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007333 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007334 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007335 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007336
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007337 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007338}
7339
Karl Schultz6addd812016-02-02 17:17:23 -07007340TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7341 VkResult err;
7342 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007343
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007345
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007346 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007347
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007348 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007349 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007350 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007351 cmd.commandPool = m_commandPool;
7352 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007353 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007354
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007355 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007356 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007357
7358 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007359 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007360 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7361
7362 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007363 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007364 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 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 -07007366 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007367
7368 // The error should be caught by validation of the BeginCommandBuffer call
7369 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7370
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007371 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007372 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007373}
7374
Karl Schultz6addd812016-02-02 17:17:23 -07007375TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376 // Cause error due to Begin while recording CB
7377 // Then cause 2 errors for attempting to reset CB w/o having
7378 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7379 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007381
7382 ASSERT_NO_FATAL_FAILURE(InitState());
7383
7384 // Calls AllocateCommandBuffers
7385 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7386
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007387 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007388 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007389 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7390 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007391 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7392 cmd_buf_info.pNext = NULL;
7393 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007394 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007395
7396 // Begin CB to transition to recording state
7397 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7398 // Can't re-begin. This should trigger error
7399 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007400 m_errorMonitor->VerifyFound();
7401
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007403 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007404 // Reset attempt will trigger error due to incorrect CommandPool state
7405 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007406 m_errorMonitor->VerifyFound();
7407
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007409 // Transition CB to RECORDED state
7410 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7411 // Now attempting to Begin will implicitly reset, which triggers error
7412 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007413 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007414}
7415
Karl Schultz6addd812016-02-02 17:17:23 -07007416TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007417 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007418 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007419
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7421 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007422
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007423 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007425
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007426 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007427 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7428 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007429
7430 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007431 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7432 ds_pool_ci.pNext = NULL;
7433 ds_pool_ci.maxSets = 1;
7434 ds_pool_ci.poolSizeCount = 1;
7435 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007436
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007437 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007438 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007439 ASSERT_VK_SUCCESS(err);
7440
Tony Barboureb254902015-07-15 12:50:33 -06007441 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007442 dsl_binding.binding = 0;
7443 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7444 dsl_binding.descriptorCount = 1;
7445 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7446 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007447
Tony Barboureb254902015-07-15 12:50:33 -06007448 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007449 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7450 ds_layout_ci.pNext = NULL;
7451 ds_layout_ci.bindingCount = 1;
7452 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007453
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007454 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007456 ASSERT_VK_SUCCESS(err);
7457
7458 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007459 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007460 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007461 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007462 alloc_info.descriptorPool = ds_pool;
7463 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007464 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007465 ASSERT_VK_SUCCESS(err);
7466
Tony Barboureb254902015-07-15 12:50:33 -06007467 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007468 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7469 pipeline_layout_ci.setLayoutCount = 1;
7470 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007471
7472 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007474 ASSERT_VK_SUCCESS(err);
7475
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007476 VkViewport vp = {}; // Just need dummy vp to point to
7477 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007478
7479 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007480 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7481 vp_state_ci.scissorCount = 1;
7482 vp_state_ci.pScissors = &sc;
7483 vp_state_ci.viewportCount = 1;
7484 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007486 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7487 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7488 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7489 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7490 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7491 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007492 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007493 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007494 rs_state_ci.lineWidth = 1.0f;
7495
7496 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7497 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7498 vi_ci.pNext = nullptr;
7499 vi_ci.vertexBindingDescriptionCount = 0;
7500 vi_ci.pVertexBindingDescriptions = nullptr;
7501 vi_ci.vertexAttributeDescriptionCount = 0;
7502 vi_ci.pVertexAttributeDescriptions = nullptr;
7503
7504 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7505 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7506 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7507
7508 VkPipelineShaderStageCreateInfo shaderStages[2];
7509 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7510
7511 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7512 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007513 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007514 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007515
Tony Barboureb254902015-07-15 12:50:33 -06007516 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007517 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7518 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007519 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007520 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7521 gp_ci.layout = pipeline_layout;
7522 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007523 gp_ci.pVertexInputState = &vi_ci;
7524 gp_ci.pInputAssemblyState = &ia_ci;
7525
7526 gp_ci.stageCount = 1;
7527 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007528
7529 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007530 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7531 pc_ci.initialDataSize = 0;
7532 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007533
7534 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007535 VkPipelineCache pipelineCache;
7536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007537 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007538 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007539 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007540 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007541
Chia-I Wuf7458c52015-10-26 21:10:41 +08007542 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7543 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007546}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007547
Tobin Ehlis912df022015-09-17 08:46:18 -06007548/*// TODO : This test should be good, but needs Tess support in compiler to run
7549TEST_F(VkLayerTest, InvalidPatchControlPoints)
7550{
7551 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007552 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007553
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007555 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7556primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007557
Tobin Ehlis912df022015-09-17 08:46:18 -06007558 ASSERT_NO_FATAL_FAILURE(InitState());
7559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007560
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007561 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007563 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007564
7565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7567 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007568 ds_pool_ci.poolSizeCount = 1;
7569 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007570
7571 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007572 err = vkCreateDescriptorPool(m_device->device(),
7573VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007574 ASSERT_VK_SUCCESS(err);
7575
7576 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007577 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007579 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007580 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7581 dsl_binding.pImmutableSamplers = NULL;
7582
7583 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007584 ds_layout_ci.sType =
7585VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007586 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007587 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007588 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007589
7590 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7592&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ASSERT_VK_SUCCESS(err);
7594
7595 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007596 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7597VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 ASSERT_VK_SUCCESS(err);
7599
7600 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007601 pipeline_layout_ci.sType =
7602VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007603 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007604 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 pipeline_layout_ci.pSetLayouts = &ds_layout;
7606
7607 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7609&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007610 ASSERT_VK_SUCCESS(err);
7611
7612 VkPipelineShaderStageCreateInfo shaderStages[3];
7613 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7614
Karl Schultz6addd812016-02-02 17:17:23 -07007615 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7616this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007617 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007618 VkShaderObj
7619tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7620this);
7621 VkShaderObj
7622te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7623this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007624
Karl Schultz6addd812016-02-02 17:17:23 -07007625 shaderStages[0].sType =
7626VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007627 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007628 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007629 shaderStages[1].sType =
7630VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007631 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007632 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007633 shaderStages[2].sType =
7634VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007635 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007636 shaderStages[2].shader = te.handle();
7637
7638 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007639 iaCI.sType =
7640VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007641 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007642
7643 VkPipelineTessellationStateCreateInfo tsCI = {};
7644 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7645 tsCI.patchControlPoints = 0; // This will cause an error
7646
7647 VkGraphicsPipelineCreateInfo gp_ci = {};
7648 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7649 gp_ci.pNext = NULL;
7650 gp_ci.stageCount = 3;
7651 gp_ci.pStages = shaderStages;
7652 gp_ci.pVertexInputState = NULL;
7653 gp_ci.pInputAssemblyState = &iaCI;
7654 gp_ci.pTessellationState = &tsCI;
7655 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007656 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007657 gp_ci.pMultisampleState = NULL;
7658 gp_ci.pDepthStencilState = NULL;
7659 gp_ci.pColorBlendState = NULL;
7660 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7661 gp_ci.layout = pipeline_layout;
7662 gp_ci.renderPass = renderPass();
7663
7664 VkPipelineCacheCreateInfo pc_ci = {};
7665 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7666 pc_ci.pNext = NULL;
7667 pc_ci.initialSize = 0;
7668 pc_ci.initialData = 0;
7669 pc_ci.maxSize = 0;
7670
7671 VkPipeline pipeline;
7672 VkPipelineCache pipelineCache;
7673
Karl Schultz6addd812016-02-02 17:17:23 -07007674 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7675&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007676 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007677 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7678&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007679
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007680 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007681
Chia-I Wuf7458c52015-10-26 21:10:41 +08007682 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7683 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007686}
7687*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007688
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007689TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007690 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007692 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007693
Tobin Ehlise68360f2015-10-01 11:15:13 -06007694 ASSERT_NO_FATAL_FAILURE(InitState());
7695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007696
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007697 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007698 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7699 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007700
7701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7703 ds_pool_ci.maxSets = 1;
7704 ds_pool_ci.poolSizeCount = 1;
7705 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706
7707 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007709 ASSERT_VK_SUCCESS(err);
7710
7711 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007712 dsl_binding.binding = 0;
7713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7714 dsl_binding.descriptorCount = 1;
7715 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716
7717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7719 ds_layout_ci.bindingCount = 1;
7720 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007721
7722 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007724 ASSERT_VK_SUCCESS(err);
7725
7726 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007727 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007728 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007729 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007730 alloc_info.descriptorPool = ds_pool;
7731 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007733 ASSERT_VK_SUCCESS(err);
7734
7735 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007736 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7737 pipeline_layout_ci.setLayoutCount = 1;
7738 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007739
7740 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007741 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007742 ASSERT_VK_SUCCESS(err);
7743
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007744 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007746 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007747 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007748 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007749 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007750
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007751 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7752 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7753 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7754 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7755 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7756 rs_state_ci.depthClampEnable = VK_FALSE;
7757 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7758 rs_state_ci.depthBiasEnable = VK_FALSE;
7759
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007760 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7761 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7762 vi_ci.pNext = nullptr;
7763 vi_ci.vertexBindingDescriptionCount = 0;
7764 vi_ci.pVertexBindingDescriptions = nullptr;
7765 vi_ci.vertexAttributeDescriptionCount = 0;
7766 vi_ci.pVertexAttributeDescriptions = nullptr;
7767
7768 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7769 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7770 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7771
7772 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7773 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7774 pipe_ms_state_ci.pNext = NULL;
7775 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7776 pipe_ms_state_ci.sampleShadingEnable = 0;
7777 pipe_ms_state_ci.minSampleShading = 1.0;
7778 pipe_ms_state_ci.pSampleMask = NULL;
7779
Cody Northropeb3a6c12015-10-05 14:44:45 -06007780 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007781 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007783 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007784 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007785 shaderStages[0] = vs.GetStageCreateInfo();
7786 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007787
7788 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7790 gp_ci.stageCount = 2;
7791 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007792 gp_ci.pVertexInputState = &vi_ci;
7793 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007794 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007795 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007796 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007797 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7798 gp_ci.layout = pipeline_layout;
7799 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007800
7801 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007802 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803
7804 VkPipeline pipeline;
7805 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007806 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007807 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007808
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007809 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007810 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007811
7812 // Check case where multiViewport is disabled and viewport count is not 1
7813 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7816 vp_state_ci.scissorCount = 0;
7817 vp_state_ci.viewportCount = 0;
7818 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7819 m_errorMonitor->VerifyFound();
7820 } else {
7821 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007822 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007823 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007824 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007825
7826 // Check is that viewportcount and scissorcount match
7827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7828 vp_state_ci.scissorCount = 1;
7829 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7830 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7831 m_errorMonitor->VerifyFound();
7832
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007833 // Check case where multiViewport is enabled and viewport count is greater than max
7834 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7837 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7838 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7839 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7840 m_errorMonitor->VerifyFound();
7841 }
7842 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843
Chia-I Wuf7458c52015-10-26 21:10:41 +08007844 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7845 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7846 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7847 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007848}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007849
7850// 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
7851// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007852TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007853 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007855 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7856
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007858
Tobin Ehlise68360f2015-10-01 11:15:13 -06007859 ASSERT_NO_FATAL_FAILURE(InitState());
7860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007861
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007862 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007863 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7864 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007865
7866 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007867 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7868 ds_pool_ci.maxSets = 1;
7869 ds_pool_ci.poolSizeCount = 1;
7870 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871
7872 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007874 ASSERT_VK_SUCCESS(err);
7875
7876 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007877 dsl_binding.binding = 0;
7878 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7879 dsl_binding.descriptorCount = 1;
7880 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007881
7882 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007883 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7884 ds_layout_ci.bindingCount = 1;
7885 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007886
7887 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007888 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007889 ASSERT_VK_SUCCESS(err);
7890
7891 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007892 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007893 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007894 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007895 alloc_info.descriptorPool = ds_pool;
7896 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007897 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007898 ASSERT_VK_SUCCESS(err);
7899
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007900 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7901 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7902 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7903
7904 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7905 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7906 vi_ci.pNext = nullptr;
7907 vi_ci.vertexBindingDescriptionCount = 0;
7908 vi_ci.pVertexBindingDescriptions = nullptr;
7909 vi_ci.vertexAttributeDescriptionCount = 0;
7910 vi_ci.pVertexAttributeDescriptions = nullptr;
7911
7912 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7913 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7914 pipe_ms_state_ci.pNext = NULL;
7915 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7916 pipe_ms_state_ci.sampleShadingEnable = 0;
7917 pipe_ms_state_ci.minSampleShading = 1.0;
7918 pipe_ms_state_ci.pSampleMask = NULL;
7919
Tobin Ehlise68360f2015-10-01 11:15:13 -06007920 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007921 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7922 pipeline_layout_ci.setLayoutCount = 1;
7923 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007924
7925 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007926 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007927 ASSERT_VK_SUCCESS(err);
7928
7929 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7930 // Set scissor as dynamic to avoid second error
7931 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007932 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7933 dyn_state_ci.dynamicStateCount = 1;
7934 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007935
Cody Northropeb3a6c12015-10-05 14:44:45 -06007936 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007937 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007940 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7941 // 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 +08007942 shaderStages[0] = vs.GetStageCreateInfo();
7943 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007944
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007945 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7946 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7947 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7948 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7949 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7950 rs_state_ci.depthClampEnable = VK_FALSE;
7951 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7952 rs_state_ci.depthBiasEnable = VK_FALSE;
7953
Tobin Ehlise68360f2015-10-01 11:15:13 -06007954 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7956 gp_ci.stageCount = 2;
7957 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007958 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007959 // Not setting VP state w/o dynamic vp state should cause validation error
7960 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007961 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007962 gp_ci.pVertexInputState = &vi_ci;
7963 gp_ci.pInputAssemblyState = &ia_ci;
7964 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007965 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7966 gp_ci.layout = pipeline_layout;
7967 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007968
7969 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007970 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971
7972 VkPipeline pipeline;
7973 VkPipelineCache pipelineCache;
7974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007976 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007978
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007979 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980
Chia-I Wuf7458c52015-10-26 21:10:41 +08007981 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7982 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007986
7987// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7988// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007989TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7990 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007991
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007993
Tobin Ehlise68360f2015-10-01 11:15:13 -06007994 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007995
7996 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007997 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007998 return;
7999 }
8000
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008002
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008003 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008004 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8005 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008006
8007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8009 ds_pool_ci.maxSets = 1;
8010 ds_pool_ci.poolSizeCount = 1;
8011 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012
8013 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008014 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008015 ASSERT_VK_SUCCESS(err);
8016
8017 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008018 dsl_binding.binding = 0;
8019 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8020 dsl_binding.descriptorCount = 1;
8021 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8025 ds_layout_ci.bindingCount = 1;
8026 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027
8028 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008029 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008030 ASSERT_VK_SUCCESS(err);
8031
8032 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008033 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008034 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008035 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008036 alloc_info.descriptorPool = ds_pool;
8037 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008039 ASSERT_VK_SUCCESS(err);
8040
8041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008042 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8043 pipeline_layout_ci.setLayoutCount = 1;
8044 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045
8046 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008048 ASSERT_VK_SUCCESS(err);
8049
8050 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008051 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8052 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008053 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008054 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008055 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008056
8057 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8058 // Set scissor as dynamic to avoid that error
8059 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008060 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8061 dyn_state_ci.dynamicStateCount = 1;
8062 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008063
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008064 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8065 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8066 pipe_ms_state_ci.pNext = NULL;
8067 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8068 pipe_ms_state_ci.sampleShadingEnable = 0;
8069 pipe_ms_state_ci.minSampleShading = 1.0;
8070 pipe_ms_state_ci.pSampleMask = NULL;
8071
Cody Northropeb3a6c12015-10-05 14:44:45 -06008072 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008073 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008074
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008076 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8077 // 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 +08008078 shaderStages[0] = vs.GetStageCreateInfo();
8079 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008080
Cody Northropf6622dc2015-10-06 10:33:21 -06008081 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8082 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8083 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008084 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008085 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008086 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008087 vi_ci.pVertexAttributeDescriptions = nullptr;
8088
8089 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8090 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8091 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8092
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008093 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008094 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008095 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008096 rs_ci.pNext = nullptr;
8097
Mark Youngc89c6312016-03-31 16:03:20 -06008098 VkPipelineColorBlendAttachmentState att = {};
8099 att.blendEnable = VK_FALSE;
8100 att.colorWriteMask = 0xf;
8101
Cody Northropf6622dc2015-10-06 10:33:21 -06008102 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8103 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8104 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008105 cb_ci.attachmentCount = 1;
8106 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008107
Tobin Ehlise68360f2015-10-01 11:15:13 -06008108 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008109 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8110 gp_ci.stageCount = 2;
8111 gp_ci.pStages = shaderStages;
8112 gp_ci.pVertexInputState = &vi_ci;
8113 gp_ci.pInputAssemblyState = &ia_ci;
8114 gp_ci.pViewportState = &vp_state_ci;
8115 gp_ci.pRasterizationState = &rs_ci;
8116 gp_ci.pColorBlendState = &cb_ci;
8117 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008118 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8120 gp_ci.layout = pipeline_layout;
8121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008122
8123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125
8126 VkPipeline pipeline;
8127 VkPipelineCache pipelineCache;
8128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008133 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008134
Tobin Ehlisd332f282015-10-02 11:00:56 -06008135 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008136 // First need to successfully create the PSO from above by setting
8137 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008138 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 -07008139
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008140 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008141 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008143 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008144 m_commandBuffer->BeginCommandBuffer();
8145 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008147 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008148 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008149 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008150 Draw(1, 0, 0, 0);
8151
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008152 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008153
8154 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8155 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8156 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8157 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008158 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008159}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008160
8161// 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 -07008162// viewportCount
8163TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8164 VkResult err;
8165
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008167
8168 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008169
8170 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008171 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008172 return;
8173 }
8174
Karl Schultz6addd812016-02-02 17:17:23 -07008175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8176
8177 VkDescriptorPoolSize ds_type_count = {};
8178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8179 ds_type_count.descriptorCount = 1;
8180
8181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8183 ds_pool_ci.maxSets = 1;
8184 ds_pool_ci.poolSizeCount = 1;
8185 ds_pool_ci.pPoolSizes = &ds_type_count;
8186
8187 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008189 ASSERT_VK_SUCCESS(err);
8190
8191 VkDescriptorSetLayoutBinding dsl_binding = {};
8192 dsl_binding.binding = 0;
8193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8194 dsl_binding.descriptorCount = 1;
8195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8196
8197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8199 ds_layout_ci.bindingCount = 1;
8200 ds_layout_ci.pBindings = &dsl_binding;
8201
8202 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008204 ASSERT_VK_SUCCESS(err);
8205
8206 VkDescriptorSet descriptorSet;
8207 VkDescriptorSetAllocateInfo alloc_info = {};
8208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8209 alloc_info.descriptorSetCount = 1;
8210 alloc_info.descriptorPool = ds_pool;
8211 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008213 ASSERT_VK_SUCCESS(err);
8214
8215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8217 pipeline_layout_ci.setLayoutCount = 1;
8218 pipeline_layout_ci.pSetLayouts = &ds_layout;
8219
8220 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008221 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008222 ASSERT_VK_SUCCESS(err);
8223
8224 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8225 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8226 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008227 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008228 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008229 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008230
8231 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8232 // Set scissor as dynamic to avoid that error
8233 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8234 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8235 dyn_state_ci.dynamicStateCount = 1;
8236 dyn_state_ci.pDynamicStates = &vp_state;
8237
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008238 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8239 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8240 pipe_ms_state_ci.pNext = NULL;
8241 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8242 pipe_ms_state_ci.sampleShadingEnable = 0;
8243 pipe_ms_state_ci.minSampleShading = 1.0;
8244 pipe_ms_state_ci.pSampleMask = NULL;
8245
Karl Schultz6addd812016-02-02 17:17:23 -07008246 VkPipelineShaderStageCreateInfo shaderStages[2];
8247 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008250 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8251 // 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 -07008252 shaderStages[0] = vs.GetStageCreateInfo();
8253 shaderStages[1] = fs.GetStageCreateInfo();
8254
8255 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8256 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8257 vi_ci.pNext = nullptr;
8258 vi_ci.vertexBindingDescriptionCount = 0;
8259 vi_ci.pVertexBindingDescriptions = nullptr;
8260 vi_ci.vertexAttributeDescriptionCount = 0;
8261 vi_ci.pVertexAttributeDescriptions = nullptr;
8262
8263 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8264 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8265 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8266
8267 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8268 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008269 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008270 rs_ci.pNext = nullptr;
8271
Mark Youngc89c6312016-03-31 16:03:20 -06008272 VkPipelineColorBlendAttachmentState att = {};
8273 att.blendEnable = VK_FALSE;
8274 att.colorWriteMask = 0xf;
8275
Karl Schultz6addd812016-02-02 17:17:23 -07008276 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8277 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8278 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008279 cb_ci.attachmentCount = 1;
8280 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008281
8282 VkGraphicsPipelineCreateInfo gp_ci = {};
8283 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8284 gp_ci.stageCount = 2;
8285 gp_ci.pStages = shaderStages;
8286 gp_ci.pVertexInputState = &vi_ci;
8287 gp_ci.pInputAssemblyState = &ia_ci;
8288 gp_ci.pViewportState = &vp_state_ci;
8289 gp_ci.pRasterizationState = &rs_ci;
8290 gp_ci.pColorBlendState = &cb_ci;
8291 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008292 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008293 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8294 gp_ci.layout = pipeline_layout;
8295 gp_ci.renderPass = renderPass();
8296
8297 VkPipelineCacheCreateInfo pc_ci = {};
8298 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8299
8300 VkPipeline pipeline;
8301 VkPipelineCache pipelineCache;
8302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008303 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008304 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008305 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008307 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008308
8309 // Now hit second fail case where we set scissor w/ different count than PSO
8310 // First need to successfully create the PSO from above by setting
8311 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8313 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008314
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008315 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008316 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008317 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008318 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008319 m_commandBuffer->BeginCommandBuffer();
8320 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008321 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008322 VkViewport viewports[1] = {};
8323 viewports[0].width = 8;
8324 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008325 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008326 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008327 Draw(1, 0, 0, 0);
8328
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008329 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008330
Chia-I Wuf7458c52015-10-26 21:10:41 +08008331 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8332 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8333 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8334 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008335 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008336}
8337
Mark Young7394fdd2016-03-31 14:56:43 -06008338TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8339 VkResult err;
8340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008342
8343 ASSERT_NO_FATAL_FAILURE(InitState());
8344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8345
8346 VkDescriptorPoolSize ds_type_count = {};
8347 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8348 ds_type_count.descriptorCount = 1;
8349
8350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8352 ds_pool_ci.maxSets = 1;
8353 ds_pool_ci.poolSizeCount = 1;
8354 ds_pool_ci.pPoolSizes = &ds_type_count;
8355
8356 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008358 ASSERT_VK_SUCCESS(err);
8359
8360 VkDescriptorSetLayoutBinding dsl_binding = {};
8361 dsl_binding.binding = 0;
8362 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8363 dsl_binding.descriptorCount = 1;
8364 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8365
8366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8368 ds_layout_ci.bindingCount = 1;
8369 ds_layout_ci.pBindings = &dsl_binding;
8370
8371 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008373 ASSERT_VK_SUCCESS(err);
8374
8375 VkDescriptorSet descriptorSet;
8376 VkDescriptorSetAllocateInfo alloc_info = {};
8377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8378 alloc_info.descriptorSetCount = 1;
8379 alloc_info.descriptorPool = ds_pool;
8380 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008382 ASSERT_VK_SUCCESS(err);
8383
8384 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8385 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8386 pipeline_layout_ci.setLayoutCount = 1;
8387 pipeline_layout_ci.pSetLayouts = &ds_layout;
8388
8389 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008391 ASSERT_VK_SUCCESS(err);
8392
8393 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8394 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8395 vp_state_ci.scissorCount = 1;
8396 vp_state_ci.pScissors = NULL;
8397 vp_state_ci.viewportCount = 1;
8398 vp_state_ci.pViewports = NULL;
8399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008401 // Set scissor as dynamic to avoid that error
8402 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8403 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8404 dyn_state_ci.dynamicStateCount = 2;
8405 dyn_state_ci.pDynamicStates = dynamic_states;
8406
8407 VkPipelineShaderStageCreateInfo shaderStages[2];
8408 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8411 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008412 this); // TODO - We shouldn't need a fragment shader
8413 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008414 shaderStages[0] = vs.GetStageCreateInfo();
8415 shaderStages[1] = fs.GetStageCreateInfo();
8416
8417 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8418 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8419 vi_ci.pNext = nullptr;
8420 vi_ci.vertexBindingDescriptionCount = 0;
8421 vi_ci.pVertexBindingDescriptions = nullptr;
8422 vi_ci.vertexAttributeDescriptionCount = 0;
8423 vi_ci.pVertexAttributeDescriptions = nullptr;
8424
8425 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8426 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8427 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8428
8429 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8430 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8431 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008432 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008433
Mark Young47107952016-05-02 15:59:55 -06008434 // Check too low (line width of -1.0f).
8435 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008436
8437 VkPipelineColorBlendAttachmentState att = {};
8438 att.blendEnable = VK_FALSE;
8439 att.colorWriteMask = 0xf;
8440
8441 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8442 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8443 cb_ci.pNext = nullptr;
8444 cb_ci.attachmentCount = 1;
8445 cb_ci.pAttachments = &att;
8446
8447 VkGraphicsPipelineCreateInfo gp_ci = {};
8448 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8449 gp_ci.stageCount = 2;
8450 gp_ci.pStages = shaderStages;
8451 gp_ci.pVertexInputState = &vi_ci;
8452 gp_ci.pInputAssemblyState = &ia_ci;
8453 gp_ci.pViewportState = &vp_state_ci;
8454 gp_ci.pRasterizationState = &rs_ci;
8455 gp_ci.pColorBlendState = &cb_ci;
8456 gp_ci.pDynamicState = &dyn_state_ci;
8457 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8458 gp_ci.layout = pipeline_layout;
8459 gp_ci.renderPass = renderPass();
8460
8461 VkPipelineCacheCreateInfo pc_ci = {};
8462 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8463
8464 VkPipeline pipeline;
8465 VkPipelineCache pipelineCache;
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);
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008472 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008475
8476 // Check too high (line width of 65536.0f).
8477 rs_ci.lineWidth = 65536.0f;
8478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008487
8488 dyn_state_ci.dynamicStateCount = 3;
8489
8490 rs_ci.lineWidth = 1.0f;
8491
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008493 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008495 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008497
8498 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008499 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008500 m_errorMonitor->VerifyFound();
8501
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008503
8504 // Check too high with dynamic setting.
8505 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8506 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008507 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008508
8509 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8510 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8511 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8512 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008513 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008514}
8515
Karl Schultz6addd812016-02-02 17:17:23 -07008516TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008517 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008519 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008520
8521 ASSERT_NO_FATAL_FAILURE(InitState());
8522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008523
Tony Barbour552f6c02016-12-21 14:34:07 -07008524 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008525 // Don't care about RenderPass handle b/c error should be flagged before
8526 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008529 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008530}
8531
Karl Schultz6addd812016-02-02 17:17:23 -07008532TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008533 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8535 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008536
8537 ASSERT_NO_FATAL_FAILURE(InitState());
8538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008539
Tony Barbour552f6c02016-12-21 14:34:07 -07008540 m_commandBuffer->BeginCommandBuffer();
8541 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008542 // Just create a dummy Renderpass that's non-NULL so we can get to the
8543 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008544 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008545
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008546 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008547}
8548
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008549TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008550 TEST_DESCRIPTION(
8551 "Begin a renderPass where clearValueCount is less than"
8552 "the number of renderPass attachments that use loadOp"
8553 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008554
8555 ASSERT_NO_FATAL_FAILURE(InitState());
8556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8557
8558 // Create a renderPass with a single attachment that uses loadOp CLEAR
8559 VkAttachmentReference attach = {};
8560 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8561 VkSubpassDescription subpass = {};
8562 subpass.inputAttachmentCount = 1;
8563 subpass.pInputAttachments = &attach;
8564 VkRenderPassCreateInfo rpci = {};
8565 rpci.subpassCount = 1;
8566 rpci.pSubpasses = &subpass;
8567 rpci.attachmentCount = 1;
8568 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008569 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008570 // Set loadOp to CLEAR
8571 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8572 rpci.pAttachments = &attach_desc;
8573 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8574 VkRenderPass rp;
8575 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8576
8577 VkCommandBufferInheritanceInfo hinfo = {};
8578 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8579 hinfo.renderPass = VK_NULL_HANDLE;
8580 hinfo.subpass = 0;
8581 hinfo.framebuffer = VK_NULL_HANDLE;
8582 hinfo.occlusionQueryEnable = VK_FALSE;
8583 hinfo.queryFlags = 0;
8584 hinfo.pipelineStatistics = 0;
8585 VkCommandBufferBeginInfo info = {};
8586 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8587 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8588 info.pInheritanceInfo = &hinfo;
8589
8590 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8591 VkRenderPassBeginInfo rp_begin = {};
8592 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8593 rp_begin.pNext = NULL;
8594 rp_begin.renderPass = renderPass();
8595 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008596 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008597
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008600 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008601
8602 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008603
8604 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008605}
8606
Slawomir Cygan0808f392016-11-28 17:53:23 +01008607TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008608 TEST_DESCRIPTION(
8609 "Begin a renderPass where clearValueCount is greater than"
8610 "the number of renderPass attachments that use loadOp"
8611 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008612
8613 ASSERT_NO_FATAL_FAILURE(InitState());
8614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8615
8616 // Create a renderPass with a single attachment that uses loadOp CLEAR
8617 VkAttachmentReference attach = {};
8618 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8619 VkSubpassDescription subpass = {};
8620 subpass.inputAttachmentCount = 1;
8621 subpass.pInputAttachments = &attach;
8622 VkRenderPassCreateInfo rpci = {};
8623 rpci.subpassCount = 1;
8624 rpci.pSubpasses = &subpass;
8625 rpci.attachmentCount = 1;
8626 VkAttachmentDescription attach_desc = {};
8627 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8628 // Set loadOp to CLEAR
8629 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8630 rpci.pAttachments = &attach_desc;
8631 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8632 VkRenderPass rp;
8633 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8634
8635 VkCommandBufferBeginInfo info = {};
8636 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8637 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8638
8639 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8640 VkRenderPassBeginInfo rp_begin = {};
8641 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8642 rp_begin.pNext = NULL;
8643 rp_begin.renderPass = renderPass();
8644 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008645 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008646
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8648 " has a clearValueCount of"
8649 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008650
8651 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8652
8653 m_errorMonitor->VerifyFound();
8654
8655 vkDestroyRenderPass(m_device->device(), rp, NULL);
8656}
8657
Cody Northrop3bb4d962016-05-09 16:15:57 -06008658TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008659 TEST_DESCRIPTION("End a command buffer with an active render pass");
8660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8662 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008663
8664 ASSERT_NO_FATAL_FAILURE(InitState());
8665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8666
Tony Barbour552f6c02016-12-21 14:34:07 -07008667 m_commandBuffer->BeginCommandBuffer();
8668 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8669 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670
8671 m_errorMonitor->VerifyFound();
8672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008673 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8674 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008675}
8676
Karl Schultz6addd812016-02-02 17:17:23 -07008677TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008678 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8680 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008681
8682 ASSERT_NO_FATAL_FAILURE(InitState());
8683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008684
Tony Barbour552f6c02016-12-21 14:34:07 -07008685 m_commandBuffer->BeginCommandBuffer();
8686 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008687
8688 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008689 vk_testing::Buffer dstBuffer;
8690 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008692 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008694 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008695}
8696
Karl Schultz6addd812016-02-02 17:17:23 -07008697TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008698 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8700 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008701
8702 ASSERT_NO_FATAL_FAILURE(InitState());
8703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008704
Tony Barbour552f6c02016-12-21 14:34:07 -07008705 m_commandBuffer->BeginCommandBuffer();
8706 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008707
8708 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008709 vk_testing::Buffer dstBuffer;
8710 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Karl Schultz6addd812016-02-02 17:17:23 -07008712 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008713 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8714 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8715 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008717 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008718}
8719
Karl Schultz6addd812016-02-02 17:17:23 -07008720TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008721 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8723 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008724
8725 ASSERT_NO_FATAL_FAILURE(InitState());
8726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008727
Tony Barbour552f6c02016-12-21 14:34:07 -07008728 m_commandBuffer->BeginCommandBuffer();
8729 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008730
Michael Lentine0a369f62016-02-03 16:51:46 -06008731 VkClearColorValue clear_color;
8732 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008733 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8734 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8735 const int32_t tex_width = 32;
8736 const int32_t tex_height = 32;
8737 VkImageCreateInfo image_create_info = {};
8738 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8739 image_create_info.pNext = NULL;
8740 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8741 image_create_info.format = tex_format;
8742 image_create_info.extent.width = tex_width;
8743 image_create_info.extent.height = tex_height;
8744 image_create_info.extent.depth = 1;
8745 image_create_info.mipLevels = 1;
8746 image_create_info.arrayLayers = 1;
8747 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8748 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07008749 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008751 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008752 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008754 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008756 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008758 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008759}
8760
Karl Schultz6addd812016-02-02 17:17:23 -07008761TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008762 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8764 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008765
8766 ASSERT_NO_FATAL_FAILURE(InitState());
8767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008768
Tony Barbourf887b162017-03-09 10:06:46 -07008769 auto depth_format = find_depth_stencil_format(m_device);
8770 if (!depth_format) {
8771 printf(" No Depth + Stencil format found. Skipped.\n");
8772 return;
8773 }
8774
Tony Barbour552f6c02016-12-21 14:34:07 -07008775 m_commandBuffer->BeginCommandBuffer();
8776 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008777
8778 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008779 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008780 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8781 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008782 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008783 image_create_info.extent.width = 64;
8784 image_create_info.extent.height = 64;
8785 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8786 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008788 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008793 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8794 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008795
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008796 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797}
8798
Karl Schultz6addd812016-02-02 17:17:23 -07008799TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008800 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008801 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8804 "vkCmdClearAttachments(): This call "
8805 "must be issued inside an active "
8806 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008807
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008808 ASSERT_NO_FATAL_FAILURE(InitState());
8809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008810
8811 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008812 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008813 ASSERT_VK_SUCCESS(err);
8814
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008815 VkClearAttachment color_attachment;
8816 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8817 color_attachment.clearValue.color.float32[0] = 0;
8818 color_attachment.clearValue.color.float32[1] = 0;
8819 color_attachment.clearValue.color.float32[2] = 0;
8820 color_attachment.clearValue.color.float32[3] = 0;
8821 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008822 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008824
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008825 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008826}
8827
Chris Forbes3b97e932016-09-07 11:29:24 +12008828TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008829 TEST_DESCRIPTION(
8830 "Test that an error is produced when CmdNextSubpass is "
8831 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008832
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8834 "vkCmdNextSubpass(): Attempted to advance "
8835 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008836
8837 ASSERT_NO_FATAL_FAILURE(InitState());
8838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8839
Tony Barbour552f6c02016-12-21 14:34:07 -07008840 m_commandBuffer->BeginCommandBuffer();
8841 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008842
8843 // error here.
8844 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8845 m_errorMonitor->VerifyFound();
8846
Tony Barbour552f6c02016-12-21 14:34:07 -07008847 m_commandBuffer->EndRenderPass();
8848 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008849}
8850
Chris Forbes6d624702016-09-07 13:57:05 +12008851TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008852 TEST_DESCRIPTION(
8853 "Test that an error is produced when CmdEndRenderPass is "
8854 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008855
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8857 "vkCmdEndRenderPass(): Called before reaching "
8858 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008859
8860 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008861 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8862 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008864 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008865
8866 VkRenderPass rp;
8867 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8868 ASSERT_VK_SUCCESS(err);
8869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008870 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008871
8872 VkFramebuffer fb;
8873 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8874 ASSERT_VK_SUCCESS(err);
8875
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008876 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008878 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 +12008879
8880 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8881
8882 // Error here.
8883 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8884 m_errorMonitor->VerifyFound();
8885
8886 // Clean up.
8887 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8888 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8889}
8890
Karl Schultz9e66a292016-04-21 15:57:51 -06008891TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8892 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8894 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008895
8896 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008897 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008898
8899 VkBufferMemoryBarrier buf_barrier = {};
8900 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8901 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8902 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8903 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8904 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8905 buf_barrier.buffer = VK_NULL_HANDLE;
8906 buf_barrier.offset = 0;
8907 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008908 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8909 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008910
8911 m_errorMonitor->VerifyFound();
8912}
8913
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008914TEST_F(VkLayerTest, InvalidBarriers) {
8915 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008918
8919 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008920 auto depth_format = find_depth_stencil_format(m_device);
8921 if (!depth_format) {
8922 printf(" No Depth + Stencil format found. Skipped.\n");
8923 return;
8924 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8926
8927 VkMemoryBarrier mem_barrier = {};
8928 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8929 mem_barrier.pNext = NULL;
8930 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8931 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008932 m_commandBuffer->BeginCommandBuffer();
8933 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008934 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008935 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008936 &mem_barrier, 0, nullptr, 0, nullptr);
8937 m_errorMonitor->VerifyFound();
8938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008940 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 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 -06008942 ASSERT_TRUE(image.initialized());
8943 VkImageMemoryBarrier img_barrier = {};
8944 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8945 img_barrier.pNext = NULL;
8946 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8947 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8948 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8949 // New layout can't be UNDEFINED
8950 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8951 img_barrier.image = image.handle();
8952 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8953 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8954 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8955 img_barrier.subresourceRange.baseArrayLayer = 0;
8956 img_barrier.subresourceRange.baseMipLevel = 0;
8957 img_barrier.subresourceRange.layerCount = 1;
8958 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8960 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008961 m_errorMonitor->VerifyFound();
8962 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8963
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8965 "Subresource must have the sum of the "
8966 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008967 // baseArrayLayer + layerCount must be <= image's arrayLayers
8968 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008969 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8970 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008971 m_errorMonitor->VerifyFound();
8972 img_barrier.subresourceRange.baseArrayLayer = 0;
8973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008975 // baseMipLevel + levelCount must be <= image's mipLevels
8976 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008977 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8978 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008979 m_errorMonitor->VerifyFound();
8980 img_barrier.subresourceRange.baseMipLevel = 0;
8981
Mike Weiblen7053aa32017-01-25 15:21:10 -07008982 // levelCount must be non-zero.
8983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8984 img_barrier.subresourceRange.levelCount = 0;
8985 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8986 nullptr, 0, nullptr, 1, &img_barrier);
8987 m_errorMonitor->VerifyFound();
8988 img_barrier.subresourceRange.levelCount = 1;
8989
8990 // layerCount must be non-zero.
8991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8992 img_barrier.subresourceRange.layerCount = 0;
8993 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8994 nullptr, 0, nullptr, 1, &img_barrier);
8995 m_errorMonitor->VerifyFound();
8996 img_barrier.subresourceRange.layerCount = 1;
8997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 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 -06008999 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009000 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9001 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009002 VkBufferMemoryBarrier buf_barrier = {};
9003 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9004 buf_barrier.pNext = NULL;
9005 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9006 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9007 buf_barrier.buffer = buffer.handle();
9008 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9009 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9010 buf_barrier.offset = 0;
9011 buf_barrier.size = VK_WHOLE_SIZE;
9012 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9014 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009015 m_errorMonitor->VerifyFound();
9016 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009019 buf_barrier.offset = 257;
9020 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9022 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009023 m_errorMonitor->VerifyFound();
9024 buf_barrier.offset = 0;
9025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027 buf_barrier.size = 257;
9028 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009029 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9030 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009031 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009032
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009033 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009034 m_errorMonitor->SetDesiredFailureMsg(
9035 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009036 "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 -06009037 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009038 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009039 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009040 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9041 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009042 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009043
9044 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009045 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009046 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9047 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009048 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009049
9050 // Having anything other than DEPTH or STENCIL is an error
9051 m_errorMonitor->SetDesiredFailureMsg(
9052 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9053 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9054 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9055 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9056 nullptr, 0, nullptr, 1, &img_barrier);
9057 m_errorMonitor->VerifyFound();
9058
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009059 // Now test depth-only
9060 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9062 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009063 VkDepthStencilObj d_image(m_device);
9064 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9065 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009066 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009067 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009068 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009069
9070 // DEPTH bit must be set
9071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9072 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009073 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009074 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9075 0, nullptr, 0, nullptr, 1, &img_barrier);
9076 m_errorMonitor->VerifyFound();
9077
9078 // No bits other than DEPTH may be set
9079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9080 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9081 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009082 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9083 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009084 m_errorMonitor->VerifyFound();
9085 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009086
9087 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9089 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 VkDepthStencilObj s_image(m_device);
9091 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9092 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009093 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009094 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009095 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009096 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9098 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009099 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009100 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9101 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009102 m_errorMonitor->VerifyFound();
9103 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009104
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009105 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009106 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009107 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 -06009108 ASSERT_TRUE(c_image.initialized());
9109 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9110 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9111 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009112
9113 // COLOR bit must be set
9114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9115 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009116 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009117 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9118 nullptr, 0, nullptr, 1, &img_barrier);
9119 m_errorMonitor->VerifyFound();
9120
9121 // No bits other than COLOR may be set
9122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9123 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9124 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009125 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9126 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009127 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009128
Mike Weiblene6e01172017-03-07 22:18:40 -07009129 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9130 {
9131 VkImageObj img_color(m_device);
9132 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9133 ASSERT_TRUE(img_color.initialized());
9134
9135 VkImageObj img_ds(m_device);
9136 img_ds.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9137 ASSERT_TRUE(img_ds.initialized());
9138
9139 VkImageObj img_xfer_src(m_device);
9140 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
9141 ASSERT_TRUE(img_xfer_src.initialized());
9142
9143 VkImageObj img_xfer_dst(m_device);
9144 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9145 ASSERT_TRUE(img_xfer_dst.initialized());
9146
9147 VkImageObj img_sampled(m_device);
9148 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
9149 ASSERT_TRUE(img_sampled.initialized());
9150
9151 VkImageObj img_input(m_device);
9152 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9153 ASSERT_TRUE(img_input.initialized());
9154
9155 const struct {
9156 VkImageObj &image_obj;
9157 VkImageLayout bad_layout;
9158 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9159 } bad_buffer_layouts[] = {
9160 // clang-format off
9161 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9162 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9163 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9164 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9165 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9166 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9167 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9168 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9169 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9170 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9171 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9172 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9173 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9174 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9175 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9176 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9177 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9178 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9179 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9180 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9181 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9182 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9183 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9184 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9185 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9186 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9187 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9188 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9189 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9190 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9191 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9192 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9193 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9194 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9195 // clang-format on
9196 };
9197 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9198
9199 for (uint32_t i = 0; i < layout_count; ++i) {
9200 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9201 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9202 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9203 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9204 : VK_IMAGE_ASPECT_COLOR_BIT;
9205
9206 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9207 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9209 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9210 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9211 m_errorMonitor->VerifyFound();
9212
9213 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9214 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9216 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9217 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9218 m_errorMonitor->VerifyFound();
9219 }
9220
9221 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9222 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9223 }
9224
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009225 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9226
9227 // Create command pool with incompatible queueflags
9228 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9229 uint32_t queue_family_index = UINT32_MAX;
9230 for (uint32_t i = 0; i < queue_props.size(); i++) {
9231 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9232 queue_family_index = i;
9233 break;
9234 }
9235 }
9236 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009237 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009238 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009239 }
9240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9241
9242 VkCommandPool command_pool;
9243 VkCommandPoolCreateInfo pool_create_info{};
9244 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9245 pool_create_info.queueFamilyIndex = queue_family_index;
9246 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9247 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9248
9249 // Allocate a command buffer
9250 VkCommandBuffer bad_command_buffer;
9251 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9252 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9253 command_buffer_allocate_info.commandPool = command_pool;
9254 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9255 command_buffer_allocate_info.commandBufferCount = 1;
9256 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9257
9258 VkCommandBufferBeginInfo cbbi = {};
9259 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9260 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9261 buf_barrier.offset = 0;
9262 buf_barrier.size = VK_WHOLE_SIZE;
9263 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9264 &buf_barrier, 0, nullptr);
9265 m_errorMonitor->VerifyFound();
9266
9267 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9268 vkEndCommandBuffer(bad_command_buffer);
9269 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009270 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009271 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009272 }
9273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9274 VkEvent event;
9275 VkEventCreateInfo event_create_info{};
9276 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9277 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9278 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9279 nullptr, 0, nullptr);
9280 m_errorMonitor->VerifyFound();
9281
9282 vkEndCommandBuffer(bad_command_buffer);
9283 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009284}
9285
Tony Barbour18ba25c2016-09-29 13:42:40 -06009286TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9287 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9288
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009290 ASSERT_NO_FATAL_FAILURE(InitState());
9291 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -07009292 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
9293 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009294 ASSERT_TRUE(image.initialized());
9295
9296 VkImageMemoryBarrier barrier = {};
9297 VkImageSubresourceRange range;
9298 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9299 barrier.srcAccessMask = 0;
9300 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9301 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9302 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9303 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9304 barrier.image = image.handle();
9305 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9306 range.baseMipLevel = 0;
9307 range.levelCount = 1;
9308 range.baseArrayLayer = 0;
9309 range.layerCount = 1;
9310 barrier.subresourceRange = range;
9311 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9312 cmdbuf.BeginCommandBuffer();
9313 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9314 &barrier);
9315 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9316 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9317 barrier.srcAccessMask = 0;
9318 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9319 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9320 &barrier);
9321
9322 m_errorMonitor->VerifyFound();
9323}
9324
Karl Schultz6addd812016-02-02 17:17:23 -07009325TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009326 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009327 ASSERT_NO_FATAL_FAILURE(InitState());
9328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009329
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009330 uint32_t const indices[] = {0};
9331 VkBufferCreateInfo buf_info = {};
9332 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9333 buf_info.size = 1024;
9334 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9335 buf_info.queueFamilyIndexCount = 1;
9336 buf_info.pQueueFamilyIndices = indices;
9337
9338 VkBuffer buffer;
9339 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9340 ASSERT_VK_SUCCESS(err);
9341
9342 VkMemoryRequirements requirements;
9343 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9344
9345 VkMemoryAllocateInfo alloc_info{};
9346 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9347 alloc_info.pNext = NULL;
9348 alloc_info.memoryTypeIndex = 0;
9349 alloc_info.allocationSize = requirements.size;
9350 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9351 ASSERT_TRUE(pass);
9352
9353 VkDeviceMemory memory;
9354 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9355 ASSERT_VK_SUCCESS(err);
9356
9357 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009358 ASSERT_VK_SUCCESS(err);
9359
Tony Barbour552f6c02016-12-21 14:34:07 -07009360 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009361 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009362
Karl Schultz6addd812016-02-02 17:17:23 -07009363 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9364 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009365 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9367 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009368 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009369
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009370 vkFreeMemory(m_device->device(), memory, NULL);
9371 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009372}
9373
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009374TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9375 // Create an out-of-range queueFamilyIndex
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009376 ASSERT_NO_FATAL_FAILURE(InitState());
9377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9378 VkBufferCreateInfo buffCI = {};
9379 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9380 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009381 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009382 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009383 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009384 uint32_t qfi[2];
9385 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009386 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009387
9388 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009389 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009390
9391 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9393 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
9394 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009395 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009396 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009397
9398 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009399 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9401
9402 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9403 buffCI.queueFamilyIndexCount = 2;
9404 qfi[0] = 1;
9405 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009406 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009407 VkDeviceMemory mem;
9408 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009409 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009410
9411 VkMemoryAllocateInfo alloc_info = {};
9412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9413 alloc_info.allocationSize = 1024;
9414 bool pass = false;
9415 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9416 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009417 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009418 return;
9419 }
9420 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009421 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009422
9423 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009424 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009425 m_commandBuffer->end();
9426 QueueCommandBuffer(false);
9427 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009428 vkDestroyBuffer(m_device->device(), ib2, NULL);
9429 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009430 }
9431
Tony Barbourdf4c0042016-06-01 15:55:43 -06009432 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009433}
9434
Karl Schultz6addd812016-02-02 17:17:23 -07009435TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009436 TEST_DESCRIPTION(
9437 "Attempt vkCmdExecuteCommands with a primary command buffer"
9438 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009439
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009440 ASSERT_NO_FATAL_FAILURE(InitState());
9441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009442
Chris Forbesf29a84f2016-10-06 18:39:28 +13009443 // An empty primary command buffer
9444 VkCommandBufferObj cb(m_device, m_commandPool);
9445 cb.BeginCommandBuffer();
9446 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009447
Chris Forbesf29a84f2016-10-06 18:39:28 +13009448 m_commandBuffer->BeginCommandBuffer();
9449 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9450 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009451
Chris Forbesf29a84f2016-10-06 18:39:28 +13009452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9453 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009454 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009455
9456 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009457}
9458
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009459TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009460 TEST_DESCRIPTION(
9461 "Attempt to update descriptor sets for images and buffers "
9462 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009463 VkResult err;
9464
9465 ASSERT_NO_FATAL_FAILURE(InitState());
9466 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9467 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9468 ds_type_count[i].type = VkDescriptorType(i);
9469 ds_type_count[i].descriptorCount = 1;
9470 }
9471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9473 ds_pool_ci.pNext = NULL;
9474 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9475 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9476 ds_pool_ci.pPoolSizes = ds_type_count;
9477
9478 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009479 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009480 ASSERT_VK_SUCCESS(err);
9481
9482 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009483 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009484 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9485 dsl_binding[i].binding = 0;
9486 dsl_binding[i].descriptorType = VkDescriptorType(i);
9487 dsl_binding[i].descriptorCount = 1;
9488 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9489 dsl_binding[i].pImmutableSamplers = NULL;
9490 }
9491
9492 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9493 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9494 ds_layout_ci.pNext = NULL;
9495 ds_layout_ci.bindingCount = 1;
9496 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9497 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9498 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009500 ASSERT_VK_SUCCESS(err);
9501 }
9502 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9503 VkDescriptorSetAllocateInfo alloc_info = {};
9504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9505 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9506 alloc_info.descriptorPool = ds_pool;
9507 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009509 ASSERT_VK_SUCCESS(err);
9510
9511 // Create a buffer & bufferView to be used for invalid updates
9512 VkBufferCreateInfo buff_ci = {};
9513 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009514 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009515 buff_ci.size = 256;
9516 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009517 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009518 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9519 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009520
9521 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9522 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9523 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9524 ASSERT_VK_SUCCESS(err);
9525
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009526 VkMemoryRequirements mem_reqs;
9527 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9528 VkMemoryAllocateInfo mem_alloc_info = {};
9529 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9530 mem_alloc_info.pNext = NULL;
9531 mem_alloc_info.memoryTypeIndex = 0;
9532 mem_alloc_info.allocationSize = mem_reqs.size;
9533 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9534 if (!pass) {
9535 vkDestroyBuffer(m_device->device(), buffer, NULL);
9536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9537 return;
9538 }
9539 VkDeviceMemory mem;
9540 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9541 ASSERT_VK_SUCCESS(err);
9542 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9543 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009544
9545 VkBufferViewCreateInfo buff_view_ci = {};
9546 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9547 buff_view_ci.buffer = buffer;
9548 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9549 buff_view_ci.range = VK_WHOLE_SIZE;
9550 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009551 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009552 ASSERT_VK_SUCCESS(err);
9553
Tony Barbour415497c2017-01-24 10:06:09 -07009554 // Now get resources / view for storage_texel_buffer
9555 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9556 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9557 if (!pass) {
9558 vkDestroyBuffer(m_device->device(), buffer, NULL);
9559 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9560 vkFreeMemory(m_device->device(), mem, NULL);
9561 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9562 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9563 return;
9564 }
9565 VkDeviceMemory storage_texel_buffer_mem;
9566 VkBufferView storage_texel_buffer_view;
9567 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9568 ASSERT_VK_SUCCESS(err);
9569 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9570 ASSERT_VK_SUCCESS(err);
9571 buff_view_ci.buffer = storage_texel_buffer;
9572 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9573 ASSERT_VK_SUCCESS(err);
9574
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009575 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009576 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009577 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009578 image_ci.format = VK_FORMAT_UNDEFINED;
9579 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9580 VkFormat format = static_cast<VkFormat>(f);
9581 VkFormatProperties fProps = m_device->format_properties(format);
9582 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9583 image_ci.format = format;
9584 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9585 break;
9586 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9587 image_ci.format = format;
9588 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9589 break;
9590 }
9591 }
9592 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9593 return;
9594 }
9595
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009596 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9597 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009598 image_ci.extent.width = 64;
9599 image_ci.extent.height = 64;
9600 image_ci.extent.depth = 1;
9601 image_ci.mipLevels = 1;
9602 image_ci.arrayLayers = 1;
9603 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009604 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009605 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009606 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9607 VkImage image;
9608 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9609 ASSERT_VK_SUCCESS(err);
9610 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009611 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009612
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009613 VkMemoryAllocateInfo mem_alloc = {};
9614 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9615 mem_alloc.pNext = NULL;
9616 mem_alloc.allocationSize = 0;
9617 mem_alloc.memoryTypeIndex = 0;
9618 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9619 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009620 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009621 ASSERT_TRUE(pass);
9622 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9623 ASSERT_VK_SUCCESS(err);
9624 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9625 ASSERT_VK_SUCCESS(err);
9626 // Now create view for image
9627 VkImageViewCreateInfo image_view_ci = {};
9628 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9629 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009630 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009631 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9632 image_view_ci.subresourceRange.layerCount = 1;
9633 image_view_ci.subresourceRange.baseArrayLayer = 0;
9634 image_view_ci.subresourceRange.levelCount = 1;
9635 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9636 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009637 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009638 ASSERT_VK_SUCCESS(err);
9639
9640 VkDescriptorBufferInfo buff_info = {};
9641 buff_info.buffer = buffer;
9642 VkDescriptorImageInfo img_info = {};
9643 img_info.imageView = image_view;
9644 VkWriteDescriptorSet descriptor_write = {};
9645 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9646 descriptor_write.dstBinding = 0;
9647 descriptor_write.descriptorCount = 1;
9648 descriptor_write.pTexelBufferView = &buff_view;
9649 descriptor_write.pBufferInfo = &buff_info;
9650 descriptor_write.pImageInfo = &img_info;
9651
9652 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009653 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009654 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9655 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9656 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9657 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9658 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9659 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9660 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9661 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9662 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9663 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9664 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009665 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009666 // Start loop at 1 as SAMPLER desc type has no usage bit error
9667 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009668 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9669 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9670 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9671 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009672 descriptor_write.descriptorType = VkDescriptorType(i);
9673 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009677
9678 m_errorMonitor->VerifyFound();
9679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009680 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9681 descriptor_write.pTexelBufferView = &buff_view;
9682 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009683 }
Tony Barbour415497c2017-01-24 10:06:09 -07009684
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9686 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009687 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009688 vkDestroyImageView(m_device->device(), image_view, NULL);
9689 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009690 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009691 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009692 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009693 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009694 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009695 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9696}
9697
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009698TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009699 TEST_DESCRIPTION(
9700 "Attempt to update buffer descriptor set that has incorrect "
9701 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009702 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009703 "2. range value of 0\n"
9704 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009705 VkResult err;
9706
9707 ASSERT_NO_FATAL_FAILURE(InitState());
9708 VkDescriptorPoolSize ds_type_count = {};
9709 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9710 ds_type_count.descriptorCount = 1;
9711
9712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9714 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009715 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009716 ds_pool_ci.maxSets = 1;
9717 ds_pool_ci.poolSizeCount = 1;
9718 ds_pool_ci.pPoolSizes = &ds_type_count;
9719
9720 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009721 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009722 ASSERT_VK_SUCCESS(err);
9723
9724 // Create layout with single uniform buffer descriptor
9725 VkDescriptorSetLayoutBinding dsl_binding = {};
9726 dsl_binding.binding = 0;
9727 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9728 dsl_binding.descriptorCount = 1;
9729 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9730 dsl_binding.pImmutableSamplers = NULL;
9731
9732 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9733 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9734 ds_layout_ci.pNext = NULL;
9735 ds_layout_ci.bindingCount = 1;
9736 ds_layout_ci.pBindings = &dsl_binding;
9737 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009739 ASSERT_VK_SUCCESS(err);
9740
9741 VkDescriptorSet descriptor_set = {};
9742 VkDescriptorSetAllocateInfo alloc_info = {};
9743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9744 alloc_info.descriptorSetCount = 1;
9745 alloc_info.descriptorPool = ds_pool;
9746 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009748 ASSERT_VK_SUCCESS(err);
9749
9750 // Create a buffer to be used for invalid updates
9751 VkBufferCreateInfo buff_ci = {};
9752 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9753 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009754 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009755 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9756 VkBuffer buffer;
9757 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9758 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009759
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009760 // Have to bind memory to buffer before descriptor update
9761 VkMemoryAllocateInfo mem_alloc = {};
9762 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9763 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009764 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009765 mem_alloc.memoryTypeIndex = 0;
9766
9767 VkMemoryRequirements mem_reqs;
9768 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009769 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009770 if (!pass) {
9771 vkDestroyBuffer(m_device->device(), buffer, NULL);
9772 return;
9773 }
9774
9775 VkDeviceMemory mem;
9776 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9777 ASSERT_VK_SUCCESS(err);
9778 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9779 ASSERT_VK_SUCCESS(err);
9780
9781 VkDescriptorBufferInfo buff_info = {};
9782 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009783 // Cause error due to offset out of range
9784 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009785 buff_info.range = VK_WHOLE_SIZE;
9786 VkWriteDescriptorSet descriptor_write = {};
9787 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9788 descriptor_write.dstBinding = 0;
9789 descriptor_write.descriptorCount = 1;
9790 descriptor_write.pTexelBufferView = nullptr;
9791 descriptor_write.pBufferInfo = &buff_info;
9792 descriptor_write.pImageInfo = nullptr;
9793
9794 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9795 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009797
9798 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9799
9800 m_errorMonitor->VerifyFound();
9801 // Now cause error due to range of 0
9802 buff_info.offset = 0;
9803 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009805
9806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9807
9808 m_errorMonitor->VerifyFound();
9809 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009810 buff_info.offset = 0;
9811 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009813
9814 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9815
9816 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009817 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9819 vkDestroyBuffer(m_device->device(), buffer, NULL);
9820 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9821 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9822}
9823
Tobin Ehlis845887e2017-02-02 19:01:44 -07009824TEST_F(VkLayerTest, DSBufferLimitErrors) {
9825 TEST_DESCRIPTION(
9826 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9827 "Test cases include:\n"
9828 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9829 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9830 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9831 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9832 VkResult err;
9833
9834 ASSERT_NO_FATAL_FAILURE(InitState());
9835 VkDescriptorPoolSize ds_type_count[2] = {};
9836 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9837 ds_type_count[0].descriptorCount = 1;
9838 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9839 ds_type_count[1].descriptorCount = 1;
9840
9841 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9842 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9843 ds_pool_ci.pNext = NULL;
9844 ds_pool_ci.maxSets = 1;
9845 ds_pool_ci.poolSizeCount = 2;
9846 ds_pool_ci.pPoolSizes = ds_type_count;
9847
9848 VkDescriptorPool ds_pool;
9849 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9850 ASSERT_VK_SUCCESS(err);
9851
9852 // Create layout with single uniform buffer & single storage buffer descriptor
9853 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9854 dsl_binding[0].binding = 0;
9855 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9856 dsl_binding[0].descriptorCount = 1;
9857 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9858 dsl_binding[0].pImmutableSamplers = NULL;
9859 dsl_binding[1].binding = 1;
9860 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9861 dsl_binding[1].descriptorCount = 1;
9862 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9863 dsl_binding[1].pImmutableSamplers = NULL;
9864
9865 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9866 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9867 ds_layout_ci.pNext = NULL;
9868 ds_layout_ci.bindingCount = 2;
9869 ds_layout_ci.pBindings = dsl_binding;
9870 VkDescriptorSetLayout ds_layout;
9871 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9872 ASSERT_VK_SUCCESS(err);
9873
9874 VkDescriptorSet descriptor_set = {};
9875 VkDescriptorSetAllocateInfo alloc_info = {};
9876 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9877 alloc_info.descriptorSetCount = 1;
9878 alloc_info.descriptorPool = ds_pool;
9879 alloc_info.pSetLayouts = &ds_layout;
9880 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9881 ASSERT_VK_SUCCESS(err);
9882
9883 // Create a buffer to be used for invalid updates
9884 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9885 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9886 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9887 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9888 VkBufferCreateInfo ub_ci = {};
9889 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9890 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9891 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9892 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9893 VkBuffer uniform_buffer;
9894 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9895 ASSERT_VK_SUCCESS(err);
9896 VkBufferCreateInfo sb_ci = {};
9897 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9898 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9899 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9900 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9901 VkBuffer storage_buffer;
9902 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9903 ASSERT_VK_SUCCESS(err);
9904 // Have to bind memory to buffer before descriptor update
9905 VkMemoryAllocateInfo mem_alloc = {};
9906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9907 mem_alloc.pNext = NULL;
9908 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9909 mem_alloc.memoryTypeIndex = 0;
9910
Cort Stratton77a0d592017-02-17 13:14:13 -08009911 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9912 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9913 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9914 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9915 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009916 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009918 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009919 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9920 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009921 return;
9922 }
9923
9924 VkDeviceMemory mem;
9925 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009926 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009927 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009928 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9929 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9930 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9931 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9932 return;
9933 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009934 ASSERT_VK_SUCCESS(err);
9935 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9936 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009937 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009938 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9939 ASSERT_VK_SUCCESS(err);
9940
9941 VkDescriptorBufferInfo buff_info = {};
9942 buff_info.buffer = uniform_buffer;
9943 buff_info.range = ub_ci.size; // This will exceed limit
9944 VkWriteDescriptorSet descriptor_write = {};
9945 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9946 descriptor_write.dstBinding = 0;
9947 descriptor_write.descriptorCount = 1;
9948 descriptor_write.pTexelBufferView = nullptr;
9949 descriptor_write.pBufferInfo = &buff_info;
9950 descriptor_write.pImageInfo = nullptr;
9951
9952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9953 descriptor_write.dstSet = descriptor_set;
9954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9955 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9956 m_errorMonitor->VerifyFound();
9957
9958 // Reduce size of range to acceptable limit & cause offset error
9959 buff_info.range = max_ub_range;
9960 buff_info.offset = min_ub_align - 1;
9961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9962 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9963 m_errorMonitor->VerifyFound();
9964
9965 // Now break storage updates
9966 buff_info.buffer = storage_buffer;
9967 buff_info.range = sb_ci.size; // This will exceed limit
9968 buff_info.offset = 0; // Reset offset for this update
9969
9970 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9971 descriptor_write.dstBinding = 1;
9972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9974 m_errorMonitor->VerifyFound();
9975
9976 // Reduce size of range to acceptable limit & cause offset error
9977 buff_info.range = max_sb_range;
9978 buff_info.offset = min_sb_align - 1;
9979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9980 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9981 m_errorMonitor->VerifyFound();
9982
9983 vkFreeMemory(m_device->device(), mem, NULL);
9984 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9985 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9986 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9987 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9988}
9989
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009990TEST_F(VkLayerTest, DSAspectBitsErrors) {
9991 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9992 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009993 TEST_DESCRIPTION(
9994 "Attempt to update descriptor sets for images "
9995 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009996 VkResult err;
9997
9998 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009999 auto depth_format = find_depth_stencil_format(m_device);
10000 if (!depth_format) {
10001 printf(" No Depth + Stencil format found. Skipped.\n");
10002 return;
10003 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010004 VkDescriptorPoolSize ds_type_count = {};
10005 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10006 ds_type_count.descriptorCount = 1;
10007
10008 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10009 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10010 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010011 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010012 ds_pool_ci.maxSets = 5;
10013 ds_pool_ci.poolSizeCount = 1;
10014 ds_pool_ci.pPoolSizes = &ds_type_count;
10015
10016 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010018 ASSERT_VK_SUCCESS(err);
10019
10020 VkDescriptorSetLayoutBinding dsl_binding = {};
10021 dsl_binding.binding = 0;
10022 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10023 dsl_binding.descriptorCount = 1;
10024 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10025 dsl_binding.pImmutableSamplers = NULL;
10026
10027 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10028 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10029 ds_layout_ci.pNext = NULL;
10030 ds_layout_ci.bindingCount = 1;
10031 ds_layout_ci.pBindings = &dsl_binding;
10032 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010034 ASSERT_VK_SUCCESS(err);
10035
10036 VkDescriptorSet descriptor_set = {};
10037 VkDescriptorSetAllocateInfo alloc_info = {};
10038 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10039 alloc_info.descriptorSetCount = 1;
10040 alloc_info.descriptorPool = ds_pool;
10041 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010042 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010043 ASSERT_VK_SUCCESS(err);
10044
10045 // Create an image to be used for invalid updates
10046 VkImageCreateInfo image_ci = {};
10047 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10048 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010049 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010050 image_ci.extent.width = 64;
10051 image_ci.extent.height = 64;
10052 image_ci.extent.depth = 1;
10053 image_ci.mipLevels = 1;
10054 image_ci.arrayLayers = 1;
10055 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010056 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010057 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10058 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10059 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10060 VkImage image;
10061 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10062 ASSERT_VK_SUCCESS(err);
10063 // Bind memory to image
10064 VkMemoryRequirements mem_reqs;
10065 VkDeviceMemory image_mem;
10066 bool pass;
10067 VkMemoryAllocateInfo mem_alloc = {};
10068 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10069 mem_alloc.pNext = NULL;
10070 mem_alloc.allocationSize = 0;
10071 mem_alloc.memoryTypeIndex = 0;
10072 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10073 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010075 ASSERT_TRUE(pass);
10076 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10077 ASSERT_VK_SUCCESS(err);
10078 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10079 ASSERT_VK_SUCCESS(err);
10080 // Now create view for image
10081 VkImageViewCreateInfo image_view_ci = {};
10082 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10083 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010084 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010085 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10086 image_view_ci.subresourceRange.layerCount = 1;
10087 image_view_ci.subresourceRange.baseArrayLayer = 0;
10088 image_view_ci.subresourceRange.levelCount = 1;
10089 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010091
10092 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010093 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010094 ASSERT_VK_SUCCESS(err);
10095
10096 VkDescriptorImageInfo img_info = {};
10097 img_info.imageView = image_view;
10098 VkWriteDescriptorSet descriptor_write = {};
10099 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10100 descriptor_write.dstBinding = 0;
10101 descriptor_write.descriptorCount = 1;
10102 descriptor_write.pTexelBufferView = NULL;
10103 descriptor_write.pBufferInfo = NULL;
10104 descriptor_write.pImageInfo = &img_info;
10105 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10106 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010107 const char *error_msg =
10108 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10109 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010111
10112 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10113
10114 m_errorMonitor->VerifyFound();
10115 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10116 vkDestroyImage(m_device->device(), image, NULL);
10117 vkFreeMemory(m_device->device(), image_mem, NULL);
10118 vkDestroyImageView(m_device->device(), image_view, NULL);
10119 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10120 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10121}
10122
Karl Schultz6addd812016-02-02 17:17:23 -070010123TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010124 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010125 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10128 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10129 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010130
Tobin Ehlis3b780662015-05-28 12:11:26 -060010131 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010132 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010133 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010134 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10135 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010136
10137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10139 ds_pool_ci.pNext = NULL;
10140 ds_pool_ci.maxSets = 1;
10141 ds_pool_ci.poolSizeCount = 1;
10142 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010143
Tobin Ehlis3b780662015-05-28 12:11:26 -060010144 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010145 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010146 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010147 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010148 dsl_binding.binding = 0;
10149 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10150 dsl_binding.descriptorCount = 1;
10151 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10152 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010153
Tony Barboureb254902015-07-15 12:50:33 -060010154 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010155 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10156 ds_layout_ci.pNext = NULL;
10157 ds_layout_ci.bindingCount = 1;
10158 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010159
Tobin Ehlis3b780662015-05-28 12:11:26 -060010160 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010162 ASSERT_VK_SUCCESS(err);
10163
10164 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010165 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010167 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010168 alloc_info.descriptorPool = ds_pool;
10169 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010171 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010172
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010173 VkSamplerCreateInfo sampler_ci = {};
10174 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10175 sampler_ci.pNext = NULL;
10176 sampler_ci.magFilter = VK_FILTER_NEAREST;
10177 sampler_ci.minFilter = VK_FILTER_NEAREST;
10178 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10179 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10180 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10181 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10182 sampler_ci.mipLodBias = 1.0;
10183 sampler_ci.anisotropyEnable = VK_FALSE;
10184 sampler_ci.maxAnisotropy = 1;
10185 sampler_ci.compareEnable = VK_FALSE;
10186 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10187 sampler_ci.minLod = 1.0;
10188 sampler_ci.maxLod = 1.0;
10189 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10190 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10191 VkSampler sampler;
10192 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10193 ASSERT_VK_SUCCESS(err);
10194
10195 VkDescriptorImageInfo info = {};
10196 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010197
10198 VkWriteDescriptorSet descriptor_write;
10199 memset(&descriptor_write, 0, sizeof(descriptor_write));
10200 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010201 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010202 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010203 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010205 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010206
10207 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10208
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010209 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010210
Chia-I Wuf7458c52015-10-26 21:10:41 +080010211 vkDestroySampler(m_device->device(), sampler, NULL);
10212 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10213 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010214}
10215
Karl Schultz6addd812016-02-02 17:17:23 -070010216TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010217 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010218 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010219
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010221
Tobin Ehlis3b780662015-05-28 12:11:26 -060010222 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010223 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010224 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010225 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10226 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010227
10228 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010229 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10230 ds_pool_ci.pNext = NULL;
10231 ds_pool_ci.maxSets = 1;
10232 ds_pool_ci.poolSizeCount = 1;
10233 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010234
Tobin Ehlis3b780662015-05-28 12:11:26 -060010235 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010237 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010238
Tony Barboureb254902015-07-15 12:50:33 -060010239 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010240 dsl_binding.binding = 0;
10241 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10242 dsl_binding.descriptorCount = 1;
10243 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10244 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010245
10246 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010247 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10248 ds_layout_ci.pNext = NULL;
10249 ds_layout_ci.bindingCount = 1;
10250 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010251
Tobin Ehlis3b780662015-05-28 12:11:26 -060010252 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010253 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010254 ASSERT_VK_SUCCESS(err);
10255
10256 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010257 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010258 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010259 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010260 alloc_info.descriptorPool = ds_pool;
10261 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010262 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010263 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010264
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010265 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10266
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010267 // Correctly update descriptor to avoid "NOT_UPDATED" error
10268 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010269 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010270 buff_info.offset = 0;
10271 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010272
10273 VkWriteDescriptorSet descriptor_write;
10274 memset(&descriptor_write, 0, sizeof(descriptor_write));
10275 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010276 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010277 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010278 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10280 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010281
10282 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10283
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010284 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010285
Chia-I Wuf7458c52015-10-26 21:10:41 +080010286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010288}
10289
Karl Schultz6addd812016-02-02 17:17:23 -070010290TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010291 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010292 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010293
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010295
Tobin Ehlis3b780662015-05-28 12:11:26 -060010296 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010297 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10300 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010301
10302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10304 ds_pool_ci.pNext = NULL;
10305 ds_pool_ci.maxSets = 1;
10306 ds_pool_ci.poolSizeCount = 1;
10307 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010308
Tobin Ehlis3b780662015-05-28 12:11:26 -060010309 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010311 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010312
Tony Barboureb254902015-07-15 12:50:33 -060010313 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010314 dsl_binding.binding = 0;
10315 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10316 dsl_binding.descriptorCount = 1;
10317 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10318 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010319
10320 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010321 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10322 ds_layout_ci.pNext = NULL;
10323 ds_layout_ci.bindingCount = 1;
10324 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010325 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010326 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010327 ASSERT_VK_SUCCESS(err);
10328
10329 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010330 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010332 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010333 alloc_info.descriptorPool = ds_pool;
10334 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010335 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010336 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010337
Tony Barboureb254902015-07-15 12:50:33 -060010338 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010339 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10340 sampler_ci.pNext = NULL;
10341 sampler_ci.magFilter = VK_FILTER_NEAREST;
10342 sampler_ci.minFilter = VK_FILTER_NEAREST;
10343 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10344 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10345 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10346 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10347 sampler_ci.mipLodBias = 1.0;
10348 sampler_ci.anisotropyEnable = VK_FALSE;
10349 sampler_ci.maxAnisotropy = 1;
10350 sampler_ci.compareEnable = VK_FALSE;
10351 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10352 sampler_ci.minLod = 1.0;
10353 sampler_ci.maxLod = 1.0;
10354 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10355 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010356
Tobin Ehlis3b780662015-05-28 12:11:26 -060010357 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010358 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010359 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010360
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010361 VkDescriptorImageInfo info = {};
10362 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010363
10364 VkWriteDescriptorSet descriptor_write;
10365 memset(&descriptor_write, 0, sizeof(descriptor_write));
10366 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010367 descriptor_write.dstSet = descriptorSet;
10368 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010369 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010370 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010371 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010372 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010373
10374 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10375
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010376 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010377
Chia-I Wuf7458c52015-10-26 21:10:41 +080010378 vkDestroySampler(m_device->device(), sampler, NULL);
10379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010381}
10382
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010383TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10384 // Create layout w/ empty binding and attempt to update it
10385 VkResult err;
10386
10387 ASSERT_NO_FATAL_FAILURE(InitState());
10388
10389 VkDescriptorPoolSize ds_type_count = {};
10390 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10391 ds_type_count.descriptorCount = 1;
10392
10393 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10394 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10395 ds_pool_ci.pNext = NULL;
10396 ds_pool_ci.maxSets = 1;
10397 ds_pool_ci.poolSizeCount = 1;
10398 ds_pool_ci.pPoolSizes = &ds_type_count;
10399
10400 VkDescriptorPool ds_pool;
10401 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10402 ASSERT_VK_SUCCESS(err);
10403
10404 VkDescriptorSetLayoutBinding dsl_binding = {};
10405 dsl_binding.binding = 0;
10406 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10407 dsl_binding.descriptorCount = 0;
10408 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10409 dsl_binding.pImmutableSamplers = NULL;
10410
10411 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10412 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10413 ds_layout_ci.pNext = NULL;
10414 ds_layout_ci.bindingCount = 1;
10415 ds_layout_ci.pBindings = &dsl_binding;
10416 VkDescriptorSetLayout ds_layout;
10417 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10418 ASSERT_VK_SUCCESS(err);
10419
10420 VkDescriptorSet descriptor_set;
10421 VkDescriptorSetAllocateInfo alloc_info = {};
10422 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10423 alloc_info.descriptorSetCount = 1;
10424 alloc_info.descriptorPool = ds_pool;
10425 alloc_info.pSetLayouts = &ds_layout;
10426 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10427 ASSERT_VK_SUCCESS(err);
10428
10429 VkSamplerCreateInfo sampler_ci = {};
10430 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10431 sampler_ci.magFilter = VK_FILTER_NEAREST;
10432 sampler_ci.minFilter = VK_FILTER_NEAREST;
10433 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10434 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10435 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10436 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10437 sampler_ci.mipLodBias = 1.0;
10438 sampler_ci.maxAnisotropy = 1;
10439 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10440 sampler_ci.minLod = 1.0;
10441 sampler_ci.maxLod = 1.0;
10442 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10443
10444 VkSampler sampler;
10445 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10446 ASSERT_VK_SUCCESS(err);
10447
10448 VkDescriptorImageInfo info = {};
10449 info.sampler = sampler;
10450
10451 VkWriteDescriptorSet descriptor_write;
10452 memset(&descriptor_write, 0, sizeof(descriptor_write));
10453 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10454 descriptor_write.dstSet = descriptor_set;
10455 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010456 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010457 // This is the wrong type, but empty binding error will be flagged first
10458 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10459 descriptor_write.pImageInfo = &info;
10460
10461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10463 m_errorMonitor->VerifyFound();
10464
10465 vkDestroySampler(m_device->device(), sampler, NULL);
10466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10467 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10468}
10469
Karl Schultz6addd812016-02-02 17:17:23 -070010470TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10471 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10472 // types
10473 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010474
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010475 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 -060010476
Tobin Ehlis3b780662015-05-28 12:11:26 -060010477 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010478
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010479 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010480 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10481 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010482
10483 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010484 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10485 ds_pool_ci.pNext = NULL;
10486 ds_pool_ci.maxSets = 1;
10487 ds_pool_ci.poolSizeCount = 1;
10488 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010489
Tobin Ehlis3b780662015-05-28 12:11:26 -060010490 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010491 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010492 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010493 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010494 dsl_binding.binding = 0;
10495 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10496 dsl_binding.descriptorCount = 1;
10497 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10498 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010499
Tony Barboureb254902015-07-15 12:50:33 -060010500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10502 ds_layout_ci.pNext = NULL;
10503 ds_layout_ci.bindingCount = 1;
10504 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010505
Tobin Ehlis3b780662015-05-28 12:11:26 -060010506 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010508 ASSERT_VK_SUCCESS(err);
10509
10510 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010511 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010512 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010513 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010514 alloc_info.descriptorPool = ds_pool;
10515 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010517 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010518
Tony Barboureb254902015-07-15 12:50:33 -060010519 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010520 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10521 sampler_ci.pNext = NULL;
10522 sampler_ci.magFilter = VK_FILTER_NEAREST;
10523 sampler_ci.minFilter = VK_FILTER_NEAREST;
10524 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10525 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10526 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10527 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10528 sampler_ci.mipLodBias = 1.0;
10529 sampler_ci.anisotropyEnable = VK_FALSE;
10530 sampler_ci.maxAnisotropy = 1;
10531 sampler_ci.compareEnable = VK_FALSE;
10532 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10533 sampler_ci.minLod = 1.0;
10534 sampler_ci.maxLod = 1.0;
10535 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10536 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010537 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010538 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010539 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010540
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010541 VkDescriptorImageInfo info = {};
10542 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010543
10544 VkWriteDescriptorSet descriptor_write;
10545 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010547 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010548 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010549 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010550 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010551 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010552
10553 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10554
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010555 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010556
Chia-I Wuf7458c52015-10-26 21:10:41 +080010557 vkDestroySampler(m_device->device(), sampler, NULL);
10558 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10559 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010560}
10561
Karl Schultz6addd812016-02-02 17:17:23 -070010562TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010563 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010564 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010565
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010567
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010568 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010569 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10570 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010571 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010572 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10573 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010574
10575 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010576 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10577 ds_pool_ci.pNext = NULL;
10578 ds_pool_ci.maxSets = 1;
10579 ds_pool_ci.poolSizeCount = 1;
10580 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010581
10582 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010584 ASSERT_VK_SUCCESS(err);
10585
10586 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010587 dsl_binding.binding = 0;
10588 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10589 dsl_binding.descriptorCount = 1;
10590 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10591 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010592
10593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10595 ds_layout_ci.pNext = NULL;
10596 ds_layout_ci.bindingCount = 1;
10597 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010598 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010600 ASSERT_VK_SUCCESS(err);
10601
10602 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010603 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010605 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010606 alloc_info.descriptorPool = ds_pool;
10607 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010609 ASSERT_VK_SUCCESS(err);
10610
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010611 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010612
10613 VkDescriptorImageInfo descriptor_info;
10614 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10615 descriptor_info.sampler = sampler;
10616
10617 VkWriteDescriptorSet descriptor_write;
10618 memset(&descriptor_write, 0, sizeof(descriptor_write));
10619 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010620 descriptor_write.dstSet = descriptorSet;
10621 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010622 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010623 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10624 descriptor_write.pImageInfo = &descriptor_info;
10625
10626 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10627
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010628 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010629
Chia-I Wuf7458c52015-10-26 21:10:41 +080010630 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10631 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010632}
10633
Karl Schultz6addd812016-02-02 17:17:23 -070010634TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10635 // Create a single combined Image/Sampler descriptor and send it an invalid
10636 // imageView
10637 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010638
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010640
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010641 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010643 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10644 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010645
10646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10648 ds_pool_ci.pNext = NULL;
10649 ds_pool_ci.maxSets = 1;
10650 ds_pool_ci.poolSizeCount = 1;
10651 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010652
10653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010655 ASSERT_VK_SUCCESS(err);
10656
10657 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010658 dsl_binding.binding = 0;
10659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10660 dsl_binding.descriptorCount = 1;
10661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10662 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010663
10664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10666 ds_layout_ci.pNext = NULL;
10667 ds_layout_ci.bindingCount = 1;
10668 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010671 ASSERT_VK_SUCCESS(err);
10672
10673 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010674 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010676 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010677 alloc_info.descriptorPool = ds_pool;
10678 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010680 ASSERT_VK_SUCCESS(err);
10681
10682 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010683 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10684 sampler_ci.pNext = NULL;
10685 sampler_ci.magFilter = VK_FILTER_NEAREST;
10686 sampler_ci.minFilter = VK_FILTER_NEAREST;
10687 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10688 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10689 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10690 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10691 sampler_ci.mipLodBias = 1.0;
10692 sampler_ci.anisotropyEnable = VK_FALSE;
10693 sampler_ci.maxAnisotropy = 1;
10694 sampler_ci.compareEnable = VK_FALSE;
10695 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10696 sampler_ci.minLod = 1.0;
10697 sampler_ci.maxLod = 1.0;
10698 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10699 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010700
10701 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010702 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010703 ASSERT_VK_SUCCESS(err);
10704
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010705 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010706
10707 VkDescriptorImageInfo descriptor_info;
10708 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10709 descriptor_info.sampler = sampler;
10710 descriptor_info.imageView = view;
10711
10712 VkWriteDescriptorSet descriptor_write;
10713 memset(&descriptor_write, 0, sizeof(descriptor_write));
10714 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010715 descriptor_write.dstSet = descriptorSet;
10716 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010717 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010718 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10719 descriptor_write.pImageInfo = &descriptor_info;
10720
10721 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10722
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010723 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010724
Chia-I Wuf7458c52015-10-26 21:10:41 +080010725 vkDestroySampler(m_device->device(), sampler, NULL);
10726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10727 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010728}
10729
Karl Schultz6addd812016-02-02 17:17:23 -070010730TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10731 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10732 // into the other
10733 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010734
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10736 " binding #1 with type "
10737 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10738 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010739
Tobin Ehlis04356f92015-10-27 16:35:27 -060010740 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010741 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010742 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010743 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10744 ds_type_count[0].descriptorCount = 1;
10745 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10746 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010747
10748 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010749 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10750 ds_pool_ci.pNext = NULL;
10751 ds_pool_ci.maxSets = 1;
10752 ds_pool_ci.poolSizeCount = 2;
10753 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010754
10755 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010757 ASSERT_VK_SUCCESS(err);
10758 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010759 dsl_binding[0].binding = 0;
10760 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10761 dsl_binding[0].descriptorCount = 1;
10762 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10763 dsl_binding[0].pImmutableSamplers = NULL;
10764 dsl_binding[1].binding = 1;
10765 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10766 dsl_binding[1].descriptorCount = 1;
10767 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10768 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010769
10770 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010771 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10772 ds_layout_ci.pNext = NULL;
10773 ds_layout_ci.bindingCount = 2;
10774 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010775
10776 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010777 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010778 ASSERT_VK_SUCCESS(err);
10779
10780 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010781 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010782 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010783 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010784 alloc_info.descriptorPool = ds_pool;
10785 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010786 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010787 ASSERT_VK_SUCCESS(err);
10788
10789 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010790 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10791 sampler_ci.pNext = NULL;
10792 sampler_ci.magFilter = VK_FILTER_NEAREST;
10793 sampler_ci.minFilter = VK_FILTER_NEAREST;
10794 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10795 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10796 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10797 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10798 sampler_ci.mipLodBias = 1.0;
10799 sampler_ci.anisotropyEnable = VK_FALSE;
10800 sampler_ci.maxAnisotropy = 1;
10801 sampler_ci.compareEnable = VK_FALSE;
10802 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10803 sampler_ci.minLod = 1.0;
10804 sampler_ci.maxLod = 1.0;
10805 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10806 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010807
10808 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010809 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010810 ASSERT_VK_SUCCESS(err);
10811
10812 VkDescriptorImageInfo info = {};
10813 info.sampler = sampler;
10814
10815 VkWriteDescriptorSet descriptor_write;
10816 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010818 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010819 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010820 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010821 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10822 descriptor_write.pImageInfo = &info;
10823 // This write update should succeed
10824 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10825 // Now perform a copy update that fails due to type mismatch
10826 VkCopyDescriptorSet copy_ds_update;
10827 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10828 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10829 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010830 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010831 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010832 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10833 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010834 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10835
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010836 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010837 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010838 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 -060010839 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10840 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10841 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010842 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010843 copy_ds_update.dstSet = descriptorSet;
10844 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010845 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010846 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10847
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010848 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010849
Tobin Ehlis04356f92015-10-27 16:35:27 -060010850 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10852 " binding#1 with offset index of 1 plus "
10853 "update array offset of 0 and update of "
10854 "5 descriptors oversteps total number "
10855 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010856
Tobin Ehlis04356f92015-10-27 16:35:27 -060010857 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10858 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10859 copy_ds_update.srcSet = descriptorSet;
10860 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010861 copy_ds_update.dstSet = descriptorSet;
10862 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010863 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010864 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10865
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010866 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010867
Chia-I Wuf7458c52015-10-26 21:10:41 +080010868 vkDestroySampler(m_device->device(), sampler, NULL);
10869 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10870 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010871}
10872
Karl Schultz6addd812016-02-02 17:17:23 -070010873TEST_F(VkLayerTest, NumSamplesMismatch) {
10874 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10875 // sampleCount
10876 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010879
Tobin Ehlis3b780662015-05-28 12:11:26 -060010880 ASSERT_NO_FATAL_FAILURE(InitState());
10881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010882 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010883 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010884 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010885
10886 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010887 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10888 ds_pool_ci.pNext = NULL;
10889 ds_pool_ci.maxSets = 1;
10890 ds_pool_ci.poolSizeCount = 1;
10891 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010892
Tobin Ehlis3b780662015-05-28 12:11:26 -060010893 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010894 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010895 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010896
Tony Barboureb254902015-07-15 12:50:33 -060010897 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010898 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010899 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010900 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010901 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10902 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010903
Tony Barboureb254902015-07-15 12:50:33 -060010904 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10905 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10906 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010907 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010908 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010909
Tobin Ehlis3b780662015-05-28 12:11:26 -060010910 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010912 ASSERT_VK_SUCCESS(err);
10913
10914 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010915 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010916 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010917 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010918 alloc_info.descriptorPool = ds_pool;
10919 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010920 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010921 ASSERT_VK_SUCCESS(err);
10922
Tony Barboureb254902015-07-15 12:50:33 -060010923 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010924 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010925 pipe_ms_state_ci.pNext = NULL;
10926 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10927 pipe_ms_state_ci.sampleShadingEnable = 0;
10928 pipe_ms_state_ci.minSampleShading = 1.0;
10929 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010930
Tony Barboureb254902015-07-15 12:50:33 -060010931 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010932 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10933 pipeline_layout_ci.pNext = NULL;
10934 pipeline_layout_ci.setLayoutCount = 1;
10935 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010936
10937 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010938 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010939 ASSERT_VK_SUCCESS(err);
10940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010942 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 -060010943 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010944 VkPipelineObj pipe(m_device);
10945 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010946 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010947 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010948 pipe.SetMSAA(&pipe_ms_state_ci);
10949 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010950
Tony Barbour552f6c02016-12-21 14:34:07 -070010951 m_commandBuffer->BeginCommandBuffer();
10952 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010953 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010954
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010955 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10956 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10957 VkRect2D scissor = {{0, 0}, {16, 16}};
10958 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10959
Mark Young29927482016-05-04 14:38:51 -060010960 // Render triangle (the error should trigger on the attempt to draw).
10961 Draw(3, 1, 0, 0);
10962
10963 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010964 m_commandBuffer->EndRenderPass();
10965 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010966
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010967 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010968
Chia-I Wuf7458c52015-10-26 21:10:41 +080010969 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10970 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10971 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010972}
Mark Young29927482016-05-04 14:38:51 -060010973
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010974TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010975 TEST_DESCRIPTION(
10976 "Hit RenderPass incompatible cases. "
10977 "Initial case is drawing with an active renderpass that's "
10978 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010979 VkResult err;
10980
10981 ASSERT_NO_FATAL_FAILURE(InitState());
10982 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10983
10984 VkDescriptorSetLayoutBinding dsl_binding = {};
10985 dsl_binding.binding = 0;
10986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10987 dsl_binding.descriptorCount = 1;
10988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10989 dsl_binding.pImmutableSamplers = NULL;
10990
10991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10993 ds_layout_ci.pNext = NULL;
10994 ds_layout_ci.bindingCount = 1;
10995 ds_layout_ci.pBindings = &dsl_binding;
10996
10997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010999 ASSERT_VK_SUCCESS(err);
11000
11001 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11002 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11003 pipeline_layout_ci.pNext = NULL;
11004 pipeline_layout_ci.setLayoutCount = 1;
11005 pipeline_layout_ci.pSetLayouts = &ds_layout;
11006
11007 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011009 ASSERT_VK_SUCCESS(err);
11010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011011 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011012 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 -060011013 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011014 // Create a renderpass that will be incompatible with default renderpass
11015 VkAttachmentReference attach = {};
11016 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11017 VkAttachmentReference color_att = {};
11018 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11019 VkSubpassDescription subpass = {};
11020 subpass.inputAttachmentCount = 1;
11021 subpass.pInputAttachments = &attach;
11022 subpass.colorAttachmentCount = 1;
11023 subpass.pColorAttachments = &color_att;
11024 VkRenderPassCreateInfo rpci = {};
11025 rpci.subpassCount = 1;
11026 rpci.pSubpasses = &subpass;
11027 rpci.attachmentCount = 1;
11028 VkAttachmentDescription attach_desc = {};
11029 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011030 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11031 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011032 rpci.pAttachments = &attach_desc;
11033 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11034 VkRenderPass rp;
11035 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11036 VkPipelineObj pipe(m_device);
11037 pipe.AddShader(&vs);
11038 pipe.AddShader(&fs);
11039 pipe.AddColorAttachment();
11040 VkViewport view_port = {};
11041 m_viewports.push_back(view_port);
11042 pipe.SetViewport(m_viewports);
11043 VkRect2D rect = {};
11044 m_scissors.push_back(rect);
11045 pipe.SetScissor(m_scissors);
11046 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11047
11048 VkCommandBufferInheritanceInfo cbii = {};
11049 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11050 cbii.renderPass = rp;
11051 cbii.subpass = 0;
11052 VkCommandBufferBeginInfo cbbi = {};
11053 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11054 cbbi.pInheritanceInfo = &cbii;
11055 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11056 VkRenderPassBeginInfo rpbi = {};
11057 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11058 rpbi.framebuffer = m_framebuffer;
11059 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11061 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011064 // Render triangle (the error should trigger on the attempt to draw).
11065 Draw(3, 1, 0, 0);
11066
11067 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011068 m_commandBuffer->EndRenderPass();
11069 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011070
11071 m_errorMonitor->VerifyFound();
11072
11073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11075 vkDestroyRenderPass(m_device->device(), rp, NULL);
11076}
11077
Mark Youngc89c6312016-03-31 16:03:20 -060011078TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11079 // Create Pipeline where the number of blend attachments doesn't match the
11080 // number of color attachments. In this case, we don't add any color
11081 // blend attachments even though we have a color attachment.
11082 VkResult err;
11083
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011085
11086 ASSERT_NO_FATAL_FAILURE(InitState());
11087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11088 VkDescriptorPoolSize ds_type_count = {};
11089 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11090 ds_type_count.descriptorCount = 1;
11091
11092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11094 ds_pool_ci.pNext = NULL;
11095 ds_pool_ci.maxSets = 1;
11096 ds_pool_ci.poolSizeCount = 1;
11097 ds_pool_ci.pPoolSizes = &ds_type_count;
11098
11099 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011101 ASSERT_VK_SUCCESS(err);
11102
11103 VkDescriptorSetLayoutBinding dsl_binding = {};
11104 dsl_binding.binding = 0;
11105 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11106 dsl_binding.descriptorCount = 1;
11107 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11108 dsl_binding.pImmutableSamplers = NULL;
11109
11110 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11111 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11112 ds_layout_ci.pNext = NULL;
11113 ds_layout_ci.bindingCount = 1;
11114 ds_layout_ci.pBindings = &dsl_binding;
11115
11116 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011117 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011118 ASSERT_VK_SUCCESS(err);
11119
11120 VkDescriptorSet descriptorSet;
11121 VkDescriptorSetAllocateInfo alloc_info = {};
11122 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11123 alloc_info.descriptorSetCount = 1;
11124 alloc_info.descriptorPool = ds_pool;
11125 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011127 ASSERT_VK_SUCCESS(err);
11128
11129 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011130 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011131 pipe_ms_state_ci.pNext = NULL;
11132 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11133 pipe_ms_state_ci.sampleShadingEnable = 0;
11134 pipe_ms_state_ci.minSampleShading = 1.0;
11135 pipe_ms_state_ci.pSampleMask = NULL;
11136
11137 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11138 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11139 pipeline_layout_ci.pNext = NULL;
11140 pipeline_layout_ci.setLayoutCount = 1;
11141 pipeline_layout_ci.pSetLayouts = &ds_layout;
11142
11143 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011145 ASSERT_VK_SUCCESS(err);
11146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011147 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011148 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 -060011149 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011150 VkPipelineObj pipe(m_device);
11151 pipe.AddShader(&vs);
11152 pipe.AddShader(&fs);
11153 pipe.SetMSAA(&pipe_ms_state_ci);
11154 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011155 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011156
11157 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11158 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11159 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11160}
Mark Young29927482016-05-04 14:38:51 -060011161
Mark Muellerd4914412016-06-13 17:52:06 -060011162TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011163 TEST_DESCRIPTION(
11164 "Points to a wrong colorAttachment index in a VkClearAttachment "
11165 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011168
11169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11170 m_errorMonitor->VerifyFound();
11171}
11172
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011173TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011174 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11175 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011176
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011177 ASSERT_NO_FATAL_FAILURE(InitState());
11178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011179
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11182 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011183
11184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11186 ds_pool_ci.pNext = NULL;
11187 ds_pool_ci.maxSets = 1;
11188 ds_pool_ci.poolSizeCount = 1;
11189 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011190
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011193 ASSERT_VK_SUCCESS(err);
11194
Tony Barboureb254902015-07-15 12:50:33 -060011195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011196 dsl_binding.binding = 0;
11197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11198 dsl_binding.descriptorCount = 1;
11199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011201
Tony Barboureb254902015-07-15 12:50:33 -060011202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11204 ds_layout_ci.pNext = NULL;
11205 ds_layout_ci.bindingCount = 1;
11206 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011207
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011210 ASSERT_VK_SUCCESS(err);
11211
11212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011215 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011216 alloc_info.descriptorPool = ds_pool;
11217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011219 ASSERT_VK_SUCCESS(err);
11220
Tony Barboureb254902015-07-15 12:50:33 -060011221 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011222 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011223 pipe_ms_state_ci.pNext = NULL;
11224 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11225 pipe_ms_state_ci.sampleShadingEnable = 0;
11226 pipe_ms_state_ci.minSampleShading = 1.0;
11227 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011228
Tony Barboureb254902015-07-15 12:50:33 -060011229 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011230 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11231 pipeline_layout_ci.pNext = NULL;
11232 pipeline_layout_ci.setLayoutCount = 1;
11233 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011234
11235 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011237 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011240 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011241 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011243
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011244 VkPipelineObj pipe(m_device);
11245 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011246 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011247 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011248 pipe.SetMSAA(&pipe_ms_state_ci);
11249 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011250
Tony Barbour552f6c02016-12-21 14:34:07 -070011251 m_commandBuffer->BeginCommandBuffer();
11252 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011253
Karl Schultz6addd812016-02-02 17:17:23 -070011254 // Main thing we care about for this test is that the VkImage obj we're
11255 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011256 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011257 VkClearAttachment color_attachment;
11258 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11259 color_attachment.clearValue.color.float32[0] = 1.0;
11260 color_attachment.clearValue.color.float32[1] = 1.0;
11261 color_attachment.clearValue.color.float32[2] = 1.0;
11262 color_attachment.clearValue.color.float32[3] = 1.0;
11263 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011265
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011266 // Call for full-sized FB Color attachment prior to issuing a Draw
11267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011268 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011269 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011270 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011271
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011272 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11273 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11275 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11276 m_errorMonitor->VerifyFound();
11277
11278 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11279 clear_rect.layerCount = 2;
11280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11281 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011282 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011283
Chia-I Wuf7458c52015-10-26 21:10:41 +080011284 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11285 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11286 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011287}
11288
Karl Schultz6addd812016-02-02 17:17:23 -070011289TEST_F(VkLayerTest, VtxBufferBadIndex) {
11290 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11293 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011294
Tobin Ehlis502480b2015-06-24 15:53:07 -060011295 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011296 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011298
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011299 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011300 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11301 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011302
11303 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011304 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11305 ds_pool_ci.pNext = NULL;
11306 ds_pool_ci.maxSets = 1;
11307 ds_pool_ci.poolSizeCount = 1;
11308 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011309
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011310 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011311 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011312 ASSERT_VK_SUCCESS(err);
11313
Tony Barboureb254902015-07-15 12:50:33 -060011314 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011315 dsl_binding.binding = 0;
11316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11317 dsl_binding.descriptorCount = 1;
11318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11319 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011320
Tony Barboureb254902015-07-15 12:50:33 -060011321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11323 ds_layout_ci.pNext = NULL;
11324 ds_layout_ci.bindingCount = 1;
11325 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011326
Tobin Ehlis502480b2015-06-24 15:53:07 -060011327 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011329 ASSERT_VK_SUCCESS(err);
11330
11331 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011332 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011334 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011335 alloc_info.descriptorPool = ds_pool;
11336 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011338 ASSERT_VK_SUCCESS(err);
11339
Tony Barboureb254902015-07-15 12:50:33 -060011340 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011341 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011342 pipe_ms_state_ci.pNext = NULL;
11343 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11344 pipe_ms_state_ci.sampleShadingEnable = 0;
11345 pipe_ms_state_ci.minSampleShading = 1.0;
11346 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011347
Tony Barboureb254902015-07-15 12:50:33 -060011348 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011349 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11350 pipeline_layout_ci.pNext = NULL;
11351 pipeline_layout_ci.setLayoutCount = 1;
11352 pipeline_layout_ci.pSetLayouts = &ds_layout;
11353 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011355 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011356 ASSERT_VK_SUCCESS(err);
11357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011358 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011359 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 -060011360 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011361 VkPipelineObj pipe(m_device);
11362 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011363 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011364 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011365 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011366 pipe.SetViewport(m_viewports);
11367 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011368 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011369
Tony Barbour552f6c02016-12-21 14:34:07 -070011370 m_commandBuffer->BeginCommandBuffer();
11371 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011372 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011373 // Don't care about actual data, just need to get to draw to flag error
11374 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011376 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011377 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011378
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011379 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011380
Chia-I Wuf7458c52015-10-26 21:10:41 +080011381 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11382 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11383 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011384}
Mark Muellerdfe37552016-07-07 14:47:42 -060011385
Mark Mueller2ee294f2016-08-04 12:59:48 -060011386TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011387 TEST_DESCRIPTION(
11388 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11389 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011390 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011391
Mark Mueller880fce52016-08-17 15:23:23 -060011392 // The following test fails with recent NVidia drivers.
11393 // By the time core_validation is reached, the NVidia
11394 // driver has sanitized the invalid condition and core_validation
11395 // is not introduced to the failure condition. This is not the case
11396 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011397 // uint32_t count = static_cast<uint32_t>(~0);
11398 // VkPhysicalDevice physical_device;
11399 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11400 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011401
Mark Mueller2ee294f2016-08-04 12:59:48 -060011402 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011403 VkDeviceQueueCreateInfo queue_create_info = {};
11404 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11405 queue_create_info.queueCount = 1;
11406 queue_create_info.pQueuePriorities = &queue_priority;
11407 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11408
11409 VkPhysicalDeviceFeatures features = m_device->phy().features();
11410 VkDevice testDevice;
11411 VkDeviceCreateInfo device_create_info = {};
11412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11413 device_create_info.queueCreateInfoCount = 1;
11414 device_create_info.pQueueCreateInfos = &queue_create_info;
11415 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070011416
11417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11418 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex ");
11419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011420 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11421 m_errorMonitor->VerifyFound();
11422
11423 queue_create_info.queueFamilyIndex = 1;
11424
11425 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11426 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11427 for (unsigned i = 0; i < feature_count; i++) {
11428 if (VK_FALSE == feature_array[i]) {
11429 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011430 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070011431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11432 "While calling vkCreateDevice(), requesting feature #");
11433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Failed to create device chain.");
11434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11435 "You requested features that are unavailable on this device. You should first "
11436 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011437 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11438 m_errorMonitor->VerifyFound();
11439 break;
11440 }
11441 }
11442}
11443
Tobin Ehlis16edf082016-11-21 12:33:49 -070011444TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11445 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11446
11447 ASSERT_NO_FATAL_FAILURE(InitState());
11448
11449 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11450 std::vector<VkDeviceQueueCreateInfo> queue_info;
11451 queue_info.reserve(queue_props.size());
11452 std::vector<std::vector<float>> queue_priorities;
11453 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11454 VkDeviceQueueCreateInfo qi{};
11455 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11456 qi.queueFamilyIndex = i;
11457 qi.queueCount = queue_props[i].queueCount;
11458 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11459 qi.pQueuePriorities = queue_priorities[i].data();
11460 queue_info.push_back(qi);
11461 }
11462
11463 std::vector<const char *> device_extension_names;
11464
11465 VkDevice local_device;
11466 VkDeviceCreateInfo device_create_info = {};
11467 auto features = m_device->phy().features();
11468 // Intentionally disable pipeline stats
11469 features.pipelineStatisticsQuery = VK_FALSE;
11470 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11471 device_create_info.pNext = NULL;
11472 device_create_info.queueCreateInfoCount = queue_info.size();
11473 device_create_info.pQueueCreateInfos = queue_info.data();
11474 device_create_info.enabledLayerCount = 0;
11475 device_create_info.ppEnabledLayerNames = NULL;
11476 device_create_info.pEnabledFeatures = &features;
11477 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11478 ASSERT_VK_SUCCESS(err);
11479
11480 VkQueryPoolCreateInfo qpci{};
11481 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11482 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11483 qpci.queryCount = 1;
11484 VkQueryPool query_pool;
11485
11486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11487 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11488 m_errorMonitor->VerifyFound();
11489
11490 vkDestroyDevice(local_device, nullptr);
11491}
11492
Mark Mueller2ee294f2016-08-04 12:59:48 -060011493TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011494 TEST_DESCRIPTION(
11495 "Use an invalid queue index in a vkCmdWaitEvents call."
11496 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011497
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011498 const char *invalid_queue_index =
11499 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11500 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11501 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011506
11507 ASSERT_NO_FATAL_FAILURE(InitState());
11508
11509 VkEvent event;
11510 VkEventCreateInfo event_create_info{};
11511 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11512 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11513
Mark Mueller2ee294f2016-08-04 12:59:48 -060011514 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011515 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011516
Tony Barbour552f6c02016-12-21 14:34:07 -070011517 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011518
11519 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011520 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 -060011521 ASSERT_TRUE(image.initialized());
11522 VkImageMemoryBarrier img_barrier = {};
11523 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11524 img_barrier.pNext = NULL;
11525 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11526 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11527 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11528 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11529 img_barrier.image = image.handle();
11530 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011531
11532 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11533 // that layer validation catches the case when it is not.
11534 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011535 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11536 img_barrier.subresourceRange.baseArrayLayer = 0;
11537 img_barrier.subresourceRange.baseMipLevel = 0;
11538 img_barrier.subresourceRange.layerCount = 1;
11539 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11541 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011542 m_errorMonitor->VerifyFound();
11543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011545
11546 VkQueryPool query_pool;
11547 VkQueryPoolCreateInfo query_pool_create_info = {};
11548 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11549 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11550 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011551 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011553 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011554 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11555
11556 vkEndCommandBuffer(m_commandBuffer->handle());
11557 m_errorMonitor->VerifyFound();
11558
11559 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11560 vkDestroyEvent(m_device->device(), event, nullptr);
11561}
11562
Mark Muellerdfe37552016-07-07 14:47:42 -060011563TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011564 TEST_DESCRIPTION(
11565 "Submit a command buffer using deleted vertex buffer, "
11566 "delete a buffer twice, use an invalid offset for each "
11567 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011569 const char *deleted_buffer_in_command_buffer =
11570 "Cannot submit cmd buffer "
11571 "using deleted buffer ";
11572 const char *invalid_offset_message =
11573 "vkBindBufferMemory(): "
11574 "memoryOffset is 0x";
11575 const char *invalid_storage_buffer_offset_message =
11576 "vkBindBufferMemory(): "
11577 "storage memoryOffset "
11578 "is 0x";
11579 const char *invalid_texel_buffer_offset_message =
11580 "vkBindBufferMemory(): "
11581 "texel memoryOffset "
11582 "is 0x";
11583 const char *invalid_uniform_buffer_offset_message =
11584 "vkBindBufferMemory(): "
11585 "uniform memoryOffset "
11586 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011587
11588 ASSERT_NO_FATAL_FAILURE(InitState());
11589 ASSERT_NO_FATAL_FAILURE(InitViewport());
11590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11591
11592 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011593 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011594 pipe_ms_state_ci.pNext = NULL;
11595 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11596 pipe_ms_state_ci.sampleShadingEnable = 0;
11597 pipe_ms_state_ci.minSampleShading = 1.0;
11598 pipe_ms_state_ci.pSampleMask = nullptr;
11599
11600 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11601 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11602 VkPipelineLayout pipeline_layout;
11603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011604 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011605 ASSERT_VK_SUCCESS(err);
11606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011607 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11608 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011609 VkPipelineObj pipe(m_device);
11610 pipe.AddShader(&vs);
11611 pipe.AddShader(&fs);
11612 pipe.AddColorAttachment();
11613 pipe.SetMSAA(&pipe_ms_state_ci);
11614 pipe.SetViewport(m_viewports);
11615 pipe.SetScissor(m_scissors);
11616 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11617
Tony Barbour552f6c02016-12-21 14:34:07 -070011618 m_commandBuffer->BeginCommandBuffer();
11619 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011620 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011621
11622 {
11623 // Create and bind a vertex buffer in a reduced scope, which will cause
11624 // it to be deleted upon leaving this scope
11625 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011626 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011627 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11628 draw_verticies.AddVertexInputToPipe(pipe);
11629 }
11630
11631 Draw(1, 0, 0, 0);
11632
Tony Barbour552f6c02016-12-21 14:34:07 -070011633 m_commandBuffer->EndRenderPass();
11634 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011637 QueueCommandBuffer(false);
11638 m_errorMonitor->VerifyFound();
11639
11640 {
11641 // Create and bind a vertex buffer in a reduced scope, and delete it
11642 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011643 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011645 buffer_test.TestDoubleDestroy();
11646 }
11647 m_errorMonitor->VerifyFound();
11648
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011649 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011650 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011651 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011653 m_errorMonitor->SetUnexpectedError(
11654 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11655 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011656 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11657 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011658 m_errorMonitor->VerifyFound();
11659 }
11660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011661 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11662 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011663 // Create and bind a memory buffer with an invalid offset again,
11664 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011666 m_errorMonitor->SetUnexpectedError(
11667 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11668 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011669 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11670 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011671 m_errorMonitor->VerifyFound();
11672 }
11673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011674 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011675 // Create and bind a memory buffer with an invalid offset again, but
11676 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011678 m_errorMonitor->SetUnexpectedError(
11679 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11680 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011681 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11682 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011683 m_errorMonitor->VerifyFound();
11684 }
11685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011686 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011687 // Create and bind a memory buffer with an invalid offset again, but
11688 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011690 m_errorMonitor->SetUnexpectedError(
11691 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11692 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011693 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11694 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011695 m_errorMonitor->VerifyFound();
11696 }
11697
11698 {
11699 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011701 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11702 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011703 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11704 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011705 m_errorMonitor->VerifyFound();
11706 }
11707
11708 {
11709 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011711 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11712 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011713 }
11714 m_errorMonitor->VerifyFound();
11715
11716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11717}
11718
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011719// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11720TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011721 TEST_DESCRIPTION(
11722 "Hit all possible validation checks associated with the "
11723 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11724 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011725 // 3 in ValidateCmdBufImageLayouts
11726 // * -1 Attempt to submit cmd buf w/ deleted image
11727 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11728 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011729
11730 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011731 auto depth_format = find_depth_stencil_format(m_device);
11732 if (!depth_format) {
11733 printf(" No Depth + Stencil format found. Skipped.\n");
11734 return;
11735 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011736 // Create src & dst images to use for copy operations
11737 VkImage src_image;
11738 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011739 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011740
11741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11742 const int32_t tex_width = 32;
11743 const int32_t tex_height = 32;
11744
11745 VkImageCreateInfo image_create_info = {};
11746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11747 image_create_info.pNext = NULL;
11748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11749 image_create_info.format = tex_format;
11750 image_create_info.extent.width = tex_width;
11751 image_create_info.extent.height = tex_height;
11752 image_create_info.extent.depth = 1;
11753 image_create_info.mipLevels = 1;
11754 image_create_info.arrayLayers = 4;
11755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11757 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011758 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011759 image_create_info.flags = 0;
11760
11761 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11762 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011763 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011764 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11765 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011766 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11767 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11768 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11769 ASSERT_VK_SUCCESS(err);
11770
11771 // Allocate memory
11772 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011773 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011774 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011775 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11776 mem_alloc.pNext = NULL;
11777 mem_alloc.allocationSize = 0;
11778 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011779
11780 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011781 mem_alloc.allocationSize = img_mem_reqs.size;
11782 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011783 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011784 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011785 ASSERT_VK_SUCCESS(err);
11786
11787 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011788 mem_alloc.allocationSize = img_mem_reqs.size;
11789 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011790 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011791 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011792 ASSERT_VK_SUCCESS(err);
11793
11794 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011795 mem_alloc.allocationSize = img_mem_reqs.size;
11796 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011797 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011798 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011799 ASSERT_VK_SUCCESS(err);
11800
11801 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11802 ASSERT_VK_SUCCESS(err);
11803 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11804 ASSERT_VK_SUCCESS(err);
11805 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11806 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011807
Tony Barbour552f6c02016-12-21 14:34:07 -070011808 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011809 VkImageCopy copy_region;
11810 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11811 copy_region.srcSubresource.mipLevel = 0;
11812 copy_region.srcSubresource.baseArrayLayer = 0;
11813 copy_region.srcSubresource.layerCount = 1;
11814 copy_region.srcOffset.x = 0;
11815 copy_region.srcOffset.y = 0;
11816 copy_region.srcOffset.z = 0;
11817 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11818 copy_region.dstSubresource.mipLevel = 0;
11819 copy_region.dstSubresource.baseArrayLayer = 0;
11820 copy_region.dstSubresource.layerCount = 1;
11821 copy_region.dstOffset.x = 0;
11822 copy_region.dstOffset.y = 0;
11823 copy_region.dstOffset.z = 0;
11824 copy_region.extent.width = 1;
11825 copy_region.extent.height = 1;
11826 copy_region.extent.depth = 1;
11827
11828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11829 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011830 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011831 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 -060011832 m_errorMonitor->VerifyFound();
11833 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11835 "Cannot copy from an image whose source layout is "
11836 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11837 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011838 m_errorMonitor->SetUnexpectedError(
11839 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011840 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 -060011841 m_errorMonitor->VerifyFound();
11842 // Final src error is due to bad layout type
11843 m_errorMonitor->SetDesiredFailureMsg(
11844 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11845 "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 -070011846 m_errorMonitor->SetUnexpectedError(
11847 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11848 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011849 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 -060011850 m_errorMonitor->VerifyFound();
11851 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11853 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011854 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011855 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 -060011856 m_errorMonitor->VerifyFound();
11857 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11859 "Cannot copy from an image whose dest layout is "
11860 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11861 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011862 m_errorMonitor->SetUnexpectedError(
11863 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011864 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 -060011865 m_errorMonitor->VerifyFound();
11866 m_errorMonitor->SetDesiredFailureMsg(
11867 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11868 "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 -070011869 m_errorMonitor->SetUnexpectedError(
11870 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11871 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011872 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 -060011873 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011874
Cort3b021012016-12-07 12:00:57 -080011875 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11876 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11877 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11878 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11879 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11880 transfer_dst_image_barrier[0].srcAccessMask = 0;
11881 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11882 transfer_dst_image_barrier[0].image = dst_image;
11883 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11884 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11885 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11886 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11887 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11888 transfer_dst_image_barrier[0].image = depth_image;
11889 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11890 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11891 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11892
11893 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011894 VkClearColorValue color_clear_value = {};
11895 VkImageSubresourceRange clear_range;
11896 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11897 clear_range.baseMipLevel = 0;
11898 clear_range.baseArrayLayer = 0;
11899 clear_range.layerCount = 1;
11900 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011901
Cort3b021012016-12-07 12:00:57 -080011902 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11903 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011906 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011907 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011908 // Fail due to provided layout not matching actual current layout for color clear.
11909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011910 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011911 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011912
Cort530cf382016-12-08 09:59:47 -080011913 VkClearDepthStencilValue depth_clear_value = {};
11914 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011915
11916 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11917 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011920 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011921 m_errorMonitor->VerifyFound();
11922 // Fail due to provided layout not matching actual current layout for depth clear.
11923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011924 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011925 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011926
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011927 // Now cause error due to bad image layout transition in PipelineBarrier
11928 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011929 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011930 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011931 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011932 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011933 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11934 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011935 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11937 "You cannot transition the layout of aspect 1 from "
11938 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11939 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070011940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011941 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11942 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011943 m_errorMonitor->VerifyFound();
11944
11945 // Finally some layout errors at RenderPass create time
11946 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11947 VkAttachmentReference attach = {};
11948 // perf warning for GENERAL layout w/ non-DS input attachment
11949 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11950 VkSubpassDescription subpass = {};
11951 subpass.inputAttachmentCount = 1;
11952 subpass.pInputAttachments = &attach;
11953 VkRenderPassCreateInfo rpci = {};
11954 rpci.subpassCount = 1;
11955 rpci.pSubpasses = &subpass;
11956 rpci.attachmentCount = 1;
11957 VkAttachmentDescription attach_desc = {};
11958 attach_desc.format = VK_FORMAT_UNDEFINED;
11959 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011960 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011961 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11963 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011964 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11965 m_errorMonitor->VerifyFound();
11966 // error w/ non-general layout
11967 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11968
11969 m_errorMonitor->SetDesiredFailureMsg(
11970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11971 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11972 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11973 m_errorMonitor->VerifyFound();
11974 subpass.inputAttachmentCount = 0;
11975 subpass.colorAttachmentCount = 1;
11976 subpass.pColorAttachments = &attach;
11977 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11978 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11980 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011981 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11982 m_errorMonitor->VerifyFound();
11983 // error w/ non-color opt or GENERAL layout for color attachment
11984 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11985 m_errorMonitor->SetDesiredFailureMsg(
11986 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11987 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11988 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11989 m_errorMonitor->VerifyFound();
11990 subpass.colorAttachmentCount = 0;
11991 subpass.pDepthStencilAttachment = &attach;
11992 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11993 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11995 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011996 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11997 m_errorMonitor->VerifyFound();
11998 // error w/ non-ds opt or GENERAL layout for color attachment
11999 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12001 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12002 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012003 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12004 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012005 // For this error we need a valid renderpass so create default one
12006 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12007 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012008 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012009 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12010 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12011 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12012 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12013 // Can't do a CLEAR load on READ_ONLY initialLayout
12014 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12015 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12016 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12018 " with invalid first layout "
12019 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12020 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012021 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12022 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012023
Cort3b021012016-12-07 12:00:57 -080012024 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12025 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12026 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012027 vkDestroyImage(m_device->device(), src_image, NULL);
12028 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012029 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012030}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012031
Tobin Ehlise0936662016-10-11 08:10:51 -060012032TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12033 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12034 VkResult err;
12035
12036 ASSERT_NO_FATAL_FAILURE(InitState());
12037
12038 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12039 VkImageTiling tiling;
12040 VkFormatProperties format_properties;
12041 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12042 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12043 tiling = VK_IMAGE_TILING_LINEAR;
12044 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12045 tiling = VK_IMAGE_TILING_OPTIMAL;
12046 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012047 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012048 return;
12049 }
12050
12051 VkDescriptorPoolSize ds_type = {};
12052 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12053 ds_type.descriptorCount = 1;
12054
12055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12057 ds_pool_ci.maxSets = 1;
12058 ds_pool_ci.poolSizeCount = 1;
12059 ds_pool_ci.pPoolSizes = &ds_type;
12060 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12061
12062 VkDescriptorPool ds_pool;
12063 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12064 ASSERT_VK_SUCCESS(err);
12065
12066 VkDescriptorSetLayoutBinding dsl_binding = {};
12067 dsl_binding.binding = 0;
12068 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12069 dsl_binding.descriptorCount = 1;
12070 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12071 dsl_binding.pImmutableSamplers = NULL;
12072
12073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12075 ds_layout_ci.pNext = NULL;
12076 ds_layout_ci.bindingCount = 1;
12077 ds_layout_ci.pBindings = &dsl_binding;
12078
12079 VkDescriptorSetLayout ds_layout;
12080 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12081 ASSERT_VK_SUCCESS(err);
12082
12083 VkDescriptorSetAllocateInfo alloc_info = {};
12084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12085 alloc_info.descriptorSetCount = 1;
12086 alloc_info.descriptorPool = ds_pool;
12087 alloc_info.pSetLayouts = &ds_layout;
12088 VkDescriptorSet descriptor_set;
12089 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12090 ASSERT_VK_SUCCESS(err);
12091
12092 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12093 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12094 pipeline_layout_ci.pNext = NULL;
12095 pipeline_layout_ci.setLayoutCount = 1;
12096 pipeline_layout_ci.pSetLayouts = &ds_layout;
12097 VkPipelineLayout pipeline_layout;
12098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12099 ASSERT_VK_SUCCESS(err);
12100
12101 VkImageObj image(m_device);
12102 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12103 ASSERT_TRUE(image.initialized());
12104 VkImageView view = image.targetView(tex_format);
12105
12106 VkDescriptorImageInfo image_info = {};
12107 image_info.imageView = view;
12108 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12109
12110 VkWriteDescriptorSet descriptor_write = {};
12111 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12112 descriptor_write.dstSet = descriptor_set;
12113 descriptor_write.dstBinding = 0;
12114 descriptor_write.descriptorCount = 1;
12115 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12116 descriptor_write.pImageInfo = &image_info;
12117
12118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12119 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12120 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12121 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12122 m_errorMonitor->VerifyFound();
12123
12124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12126 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12128}
12129
Mark Mueller93b938f2016-08-18 10:27:40 -060012130TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012131 TEST_DESCRIPTION(
12132 "Use vkCmdExecuteCommands with invalid state "
12133 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012134
12135 ASSERT_NO_FATAL_FAILURE(InitState());
12136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12137
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012138 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012139 const char *simultaneous_use_message2 =
12140 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12141 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012142
12143 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012144 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012145 command_buffer_allocate_info.commandPool = m_commandPool;
12146 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12147 command_buffer_allocate_info.commandBufferCount = 1;
12148
12149 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012150 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012151 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12152 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012153 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012154 command_buffer_inheritance_info.renderPass = m_renderPass;
12155 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012156
Mark Mueller93b938f2016-08-18 10:27:40 -060012157 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012158 command_buffer_begin_info.flags =
12159 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012160 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12161
12162 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12163 vkEndCommandBuffer(secondary_command_buffer);
12164
Mark Mueller93b938f2016-08-18 10:27:40 -060012165 VkSubmitInfo submit_info = {};
12166 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12167 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012168 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012169
Mark Mueller4042b652016-09-05 22:52:21 -060012170 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012171 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12173 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012174 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012175 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012176 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12177 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012178
Dave Houltonfbf52152017-01-06 12:55:29 -070012179 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012180 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012181 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012182
Mark Mueller4042b652016-09-05 22:52:21 -060012183 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012184 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12185 m_errorMonitor->SetUnexpectedError(
12186 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12187 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012188 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012189 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12192 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012193 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012194 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12195 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012196
12197 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012198
12199 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012200}
12201
Tony Barbour626994c2017-02-08 15:29:37 -070012202TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12203 TEST_DESCRIPTION(
12204 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12205 "errors");
12206 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12207 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12208 ASSERT_NO_FATAL_FAILURE(InitState());
12209
12210 VkCommandBuffer cmd_bufs[2];
12211 VkCommandBufferAllocateInfo alloc_info;
12212 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12213 alloc_info.pNext = NULL;
12214 alloc_info.commandBufferCount = 2;
12215 alloc_info.commandPool = m_commandPool;
12216 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12217 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12218
12219 VkCommandBufferBeginInfo cb_binfo;
12220 cb_binfo.pNext = NULL;
12221 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12222 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12223 cb_binfo.flags = 0;
12224 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12225 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12226 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12227 vkEndCommandBuffer(cmd_bufs[0]);
12228 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12229
12230 VkSubmitInfo submit_info = {};
12231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12232 submit_info.commandBufferCount = 2;
12233 submit_info.pCommandBuffers = duplicates;
12234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12235 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12236 m_errorMonitor->VerifyFound();
12237 vkQueueWaitIdle(m_device->m_queue);
12238
12239 // Set one time use and now look for one time submit
12240 duplicates[0] = duplicates[1] = cmd_bufs[1];
12241 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12242 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12243 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12244 vkEndCommandBuffer(cmd_bufs[1]);
12245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12246 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12247 m_errorMonitor->VerifyFound();
12248 vkQueueWaitIdle(m_device->m_queue);
12249}
12250
Tobin Ehlisb093da82017-01-19 12:05:27 -070012251TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012252 TEST_DESCRIPTION(
12253 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12254 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012255
12256 ASSERT_NO_FATAL_FAILURE(InitState());
12257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12258
12259 std::vector<const char *> device_extension_names;
12260 auto features = m_device->phy().features();
12261 // Make sure gs & ts are disabled
12262 features.geometryShader = false;
12263 features.tessellationShader = false;
12264 // The sacrificial device object
12265 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12266
12267 VkCommandPoolCreateInfo pool_create_info{};
12268 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12269 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12270
12271 VkCommandPool command_pool;
12272 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12273
12274 VkCommandBufferAllocateInfo cmd = {};
12275 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12276 cmd.pNext = NULL;
12277 cmd.commandPool = command_pool;
12278 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12279 cmd.commandBufferCount = 1;
12280
12281 VkCommandBuffer cmd_buffer;
12282 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12283 ASSERT_VK_SUCCESS(err);
12284
12285 VkEvent event;
12286 VkEventCreateInfo evci = {};
12287 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12288 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12289 ASSERT_VK_SUCCESS(result);
12290
12291 VkCommandBufferBeginInfo cbbi = {};
12292 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12293 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12295 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12296 m_errorMonitor->VerifyFound();
12297
12298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12299 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12300 m_errorMonitor->VerifyFound();
12301
12302 vkDestroyEvent(test_device.handle(), event, NULL);
12303 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12304}
12305
Mark Mueller917f6bc2016-08-30 10:57:19 -060012306TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012307 TEST_DESCRIPTION(
12308 "Use vkCmdExecuteCommands with invalid state "
12309 "in primary and secondary command buffers. "
12310 "Delete objects that are inuse. Call VkQueueSubmit "
12311 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012312
12313 ASSERT_NO_FATAL_FAILURE(InitState());
12314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12315
Tony Barbour552f6c02016-12-21 14:34:07 -070012316 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012317
12318 VkEvent event;
12319 VkEventCreateInfo event_create_info = {};
12320 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12321 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012322 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012323
Tony Barbour552f6c02016-12-21 14:34:07 -070012324 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012325 vkDestroyEvent(m_device->device(), event, nullptr);
12326
12327 VkSubmitInfo submit_info = {};
12328 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12329 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012330 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012332 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12333 m_errorMonitor->VerifyFound();
12334
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012335 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012336 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12337
12338 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12339
Mark Mueller917f6bc2016-08-30 10:57:19 -060012340 VkSemaphoreCreateInfo semaphore_create_info = {};
12341 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12342 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012343 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012344 VkFenceCreateInfo fence_create_info = {};
12345 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12346 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012347 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012348
12349 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012350 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012351 descriptor_pool_type_count.descriptorCount = 1;
12352
12353 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12354 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12355 descriptor_pool_create_info.maxSets = 1;
12356 descriptor_pool_create_info.poolSizeCount = 1;
12357 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012359
12360 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012362
12363 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012364 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012365 descriptorset_layout_binding.descriptorCount = 1;
12366 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12367
12368 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012370 descriptorset_layout_create_info.bindingCount = 1;
12371 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12372
12373 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012374 ASSERT_VK_SUCCESS(
12375 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012376
12377 VkDescriptorSet descriptorset;
12378 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012379 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012380 descriptorset_allocate_info.descriptorSetCount = 1;
12381 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12382 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012383 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012384
Mark Mueller4042b652016-09-05 22:52:21 -060012385 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12386
12387 VkDescriptorBufferInfo buffer_info = {};
12388 buffer_info.buffer = buffer_test.GetBuffer();
12389 buffer_info.offset = 0;
12390 buffer_info.range = 1024;
12391
12392 VkWriteDescriptorSet write_descriptor_set = {};
12393 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12394 write_descriptor_set.dstSet = descriptorset;
12395 write_descriptor_set.descriptorCount = 1;
12396 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12397 write_descriptor_set.pBufferInfo = &buffer_info;
12398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012399 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012401 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12402 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012403
12404 VkPipelineObj pipe(m_device);
12405 pipe.AddColorAttachment();
12406 pipe.AddShader(&vs);
12407 pipe.AddShader(&fs);
12408
12409 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012410 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012411 pipeline_layout_create_info.setLayoutCount = 1;
12412 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12413
12414 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012415 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012416
12417 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12418
Tony Barbour552f6c02016-12-21 14:34:07 -070012419 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012420 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012422 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12423 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12424 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012425
Tony Barbour552f6c02016-12-21 14:34:07 -070012426 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012427
Mark Mueller917f6bc2016-08-30 10:57:19 -060012428 submit_info.signalSemaphoreCount = 1;
12429 submit_info.pSignalSemaphores = &semaphore;
12430 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012431 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012432
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012434 vkDestroyEvent(m_device->device(), event, nullptr);
12435 m_errorMonitor->VerifyFound();
12436
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012438 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12439 m_errorMonitor->VerifyFound();
12440
Jeremy Hayes08369882017-02-02 10:31:06 -070012441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012442 vkDestroyFence(m_device->device(), fence, nullptr);
12443 m_errorMonitor->VerifyFound();
12444
Tobin Ehlis122207b2016-09-01 08:50:06 -070012445 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012446 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12447 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012448 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012449 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12450 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012451 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012452 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12453 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012454 vkDestroyEvent(m_device->device(), event, nullptr);
12455 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012456 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012457 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12458}
12459
Tobin Ehlis2adda372016-09-01 08:51:06 -070012460TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12461 TEST_DESCRIPTION("Delete in-use query pool.");
12462
12463 ASSERT_NO_FATAL_FAILURE(InitState());
12464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12465
12466 VkQueryPool query_pool;
12467 VkQueryPoolCreateInfo query_pool_ci{};
12468 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12469 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12470 query_pool_ci.queryCount = 1;
12471 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012472 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012473 // Reset query pool to create binding with cmd buffer
12474 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12475
Tony Barbour552f6c02016-12-21 14:34:07 -070012476 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012477
12478 VkSubmitInfo submit_info = {};
12479 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12480 submit_info.commandBufferCount = 1;
12481 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12482 // Submit cmd buffer and then destroy query pool while in-flight
12483 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12484
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012486 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12487 m_errorMonitor->VerifyFound();
12488
12489 vkQueueWaitIdle(m_device->m_queue);
12490 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012491 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12492 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012493 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12494}
12495
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012496TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12497 TEST_DESCRIPTION("Delete in-use pipeline.");
12498
12499 ASSERT_NO_FATAL_FAILURE(InitState());
12500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12501
12502 // Empty pipeline layout used for binding PSO
12503 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12504 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12505 pipeline_layout_ci.setLayoutCount = 0;
12506 pipeline_layout_ci.pSetLayouts = NULL;
12507
12508 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012509 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012510 ASSERT_VK_SUCCESS(err);
12511
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012513 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012514 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12515 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012516 // Store pipeline handle so we can actually delete it before test finishes
12517 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012518 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012519 VkPipelineObj pipe(m_device);
12520 pipe.AddShader(&vs);
12521 pipe.AddShader(&fs);
12522 pipe.AddColorAttachment();
12523 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12524 delete_this_pipeline = pipe.handle();
12525
Tony Barbour552f6c02016-12-21 14:34:07 -070012526 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012527 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012528 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012529
Tony Barbour552f6c02016-12-21 14:34:07 -070012530 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012531
12532 VkSubmitInfo submit_info = {};
12533 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12534 submit_info.commandBufferCount = 1;
12535 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12536 // Submit cmd buffer and then pipeline destroyed while in-flight
12537 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012538 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012539 m_errorMonitor->VerifyFound();
12540 // Make sure queue finished and then actually delete pipeline
12541 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012542 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12543 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012544 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12545 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12546}
12547
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012548TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12549 TEST_DESCRIPTION("Delete in-use imageView.");
12550
12551 ASSERT_NO_FATAL_FAILURE(InitState());
12552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12553
12554 VkDescriptorPoolSize ds_type_count;
12555 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12556 ds_type_count.descriptorCount = 1;
12557
12558 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12559 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12560 ds_pool_ci.maxSets = 1;
12561 ds_pool_ci.poolSizeCount = 1;
12562 ds_pool_ci.pPoolSizes = &ds_type_count;
12563
12564 VkDescriptorPool ds_pool;
12565 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12566 ASSERT_VK_SUCCESS(err);
12567
12568 VkSamplerCreateInfo sampler_ci = {};
12569 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12570 sampler_ci.pNext = NULL;
12571 sampler_ci.magFilter = VK_FILTER_NEAREST;
12572 sampler_ci.minFilter = VK_FILTER_NEAREST;
12573 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12574 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12575 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12576 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12577 sampler_ci.mipLodBias = 1.0;
12578 sampler_ci.anisotropyEnable = VK_FALSE;
12579 sampler_ci.maxAnisotropy = 1;
12580 sampler_ci.compareEnable = VK_FALSE;
12581 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12582 sampler_ci.minLod = 1.0;
12583 sampler_ci.maxLod = 1.0;
12584 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12585 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12586 VkSampler sampler;
12587
12588 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12589 ASSERT_VK_SUCCESS(err);
12590
12591 VkDescriptorSetLayoutBinding layout_binding;
12592 layout_binding.binding = 0;
12593 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12594 layout_binding.descriptorCount = 1;
12595 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12596 layout_binding.pImmutableSamplers = NULL;
12597
12598 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12599 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12600 ds_layout_ci.bindingCount = 1;
12601 ds_layout_ci.pBindings = &layout_binding;
12602 VkDescriptorSetLayout ds_layout;
12603 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12604 ASSERT_VK_SUCCESS(err);
12605
12606 VkDescriptorSetAllocateInfo alloc_info = {};
12607 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12608 alloc_info.descriptorSetCount = 1;
12609 alloc_info.descriptorPool = ds_pool;
12610 alloc_info.pSetLayouts = &ds_layout;
12611 VkDescriptorSet descriptor_set;
12612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12613 ASSERT_VK_SUCCESS(err);
12614
12615 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12616 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12617 pipeline_layout_ci.pNext = NULL;
12618 pipeline_layout_ci.setLayoutCount = 1;
12619 pipeline_layout_ci.pSetLayouts = &ds_layout;
12620
12621 VkPipelineLayout pipeline_layout;
12622 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12623 ASSERT_VK_SUCCESS(err);
12624
12625 VkImageObj image(m_device);
12626 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12627 ASSERT_TRUE(image.initialized());
12628
12629 VkImageView view;
12630 VkImageViewCreateInfo ivci = {};
12631 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12632 ivci.image = image.handle();
12633 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12634 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12635 ivci.subresourceRange.layerCount = 1;
12636 ivci.subresourceRange.baseMipLevel = 0;
12637 ivci.subresourceRange.levelCount = 1;
12638 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12639
12640 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12641 ASSERT_VK_SUCCESS(err);
12642
12643 VkDescriptorImageInfo image_info{};
12644 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12645 image_info.imageView = view;
12646 image_info.sampler = sampler;
12647
12648 VkWriteDescriptorSet descriptor_write = {};
12649 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12650 descriptor_write.dstSet = descriptor_set;
12651 descriptor_write.dstBinding = 0;
12652 descriptor_write.descriptorCount = 1;
12653 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12654 descriptor_write.pImageInfo = &image_info;
12655
12656 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12657
12658 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012659 char const *vsSource =
12660 "#version 450\n"
12661 "\n"
12662 "out gl_PerVertex { \n"
12663 " vec4 gl_Position;\n"
12664 "};\n"
12665 "void main(){\n"
12666 " gl_Position = vec4(1);\n"
12667 "}\n";
12668 char const *fsSource =
12669 "#version 450\n"
12670 "\n"
12671 "layout(set=0, binding=0) uniform sampler2D s;\n"
12672 "layout(location=0) out vec4 x;\n"
12673 "void main(){\n"
12674 " x = texture(s, vec2(1));\n"
12675 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12677 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12678 VkPipelineObj pipe(m_device);
12679 pipe.AddShader(&vs);
12680 pipe.AddShader(&fs);
12681 pipe.AddColorAttachment();
12682 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12683
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012685
Tony Barbour552f6c02016-12-21 14:34:07 -070012686 m_commandBuffer->BeginCommandBuffer();
12687 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012688 // Bind pipeline to cmd buffer
12689 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12690 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12691 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012692
12693 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12694 VkRect2D scissor = {{0, 0}, {16, 16}};
12695 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12696 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12697
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012698 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012699 m_commandBuffer->EndRenderPass();
12700 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012701 // Submit cmd buffer then destroy sampler
12702 VkSubmitInfo submit_info = {};
12703 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12704 submit_info.commandBufferCount = 1;
12705 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12706 // Submit cmd buffer and then destroy imageView while in-flight
12707 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12708
12709 vkDestroyImageView(m_device->device(), view, nullptr);
12710 m_errorMonitor->VerifyFound();
12711 vkQueueWaitIdle(m_device->m_queue);
12712 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012713 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12714 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012715 vkDestroyImageView(m_device->device(), view, NULL);
12716 vkDestroySampler(m_device->device(), sampler, nullptr);
12717 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12718 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12720}
12721
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012722TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12723 TEST_DESCRIPTION("Delete in-use bufferView.");
12724
12725 ASSERT_NO_FATAL_FAILURE(InitState());
12726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12727
12728 VkDescriptorPoolSize ds_type_count;
12729 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12730 ds_type_count.descriptorCount = 1;
12731
12732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12734 ds_pool_ci.maxSets = 1;
12735 ds_pool_ci.poolSizeCount = 1;
12736 ds_pool_ci.pPoolSizes = &ds_type_count;
12737
12738 VkDescriptorPool ds_pool;
12739 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12740 ASSERT_VK_SUCCESS(err);
12741
12742 VkDescriptorSetLayoutBinding layout_binding;
12743 layout_binding.binding = 0;
12744 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12745 layout_binding.descriptorCount = 1;
12746 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12747 layout_binding.pImmutableSamplers = NULL;
12748
12749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12751 ds_layout_ci.bindingCount = 1;
12752 ds_layout_ci.pBindings = &layout_binding;
12753 VkDescriptorSetLayout ds_layout;
12754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12755 ASSERT_VK_SUCCESS(err);
12756
12757 VkDescriptorSetAllocateInfo alloc_info = {};
12758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12759 alloc_info.descriptorSetCount = 1;
12760 alloc_info.descriptorPool = ds_pool;
12761 alloc_info.pSetLayouts = &ds_layout;
12762 VkDescriptorSet descriptor_set;
12763 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12764 ASSERT_VK_SUCCESS(err);
12765
12766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12768 pipeline_layout_ci.pNext = NULL;
12769 pipeline_layout_ci.setLayoutCount = 1;
12770 pipeline_layout_ci.pSetLayouts = &ds_layout;
12771
12772 VkPipelineLayout pipeline_layout;
12773 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12774 ASSERT_VK_SUCCESS(err);
12775
12776 VkBuffer buffer;
12777 uint32_t queue_family_index = 0;
12778 VkBufferCreateInfo buffer_create_info = {};
12779 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12780 buffer_create_info.size = 1024;
12781 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12782 buffer_create_info.queueFamilyIndexCount = 1;
12783 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12784
12785 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12786 ASSERT_VK_SUCCESS(err);
12787
12788 VkMemoryRequirements memory_reqs;
12789 VkDeviceMemory buffer_memory;
12790
12791 VkMemoryAllocateInfo memory_info = {};
12792 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12793 memory_info.allocationSize = 0;
12794 memory_info.memoryTypeIndex = 0;
12795
12796 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12797 memory_info.allocationSize = memory_reqs.size;
12798 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12799 ASSERT_TRUE(pass);
12800
12801 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12802 ASSERT_VK_SUCCESS(err);
12803 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12804 ASSERT_VK_SUCCESS(err);
12805
12806 VkBufferView view;
12807 VkBufferViewCreateInfo bvci = {};
12808 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12809 bvci.buffer = buffer;
12810 bvci.format = VK_FORMAT_R8_UNORM;
12811 bvci.range = VK_WHOLE_SIZE;
12812
12813 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12814 ASSERT_VK_SUCCESS(err);
12815
12816 VkWriteDescriptorSet descriptor_write = {};
12817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12818 descriptor_write.dstSet = descriptor_set;
12819 descriptor_write.dstBinding = 0;
12820 descriptor_write.descriptorCount = 1;
12821 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12822 descriptor_write.pTexelBufferView = &view;
12823
12824 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012826 char const *vsSource =
12827 "#version 450\n"
12828 "\n"
12829 "out gl_PerVertex { \n"
12830 " vec4 gl_Position;\n"
12831 "};\n"
12832 "void main(){\n"
12833 " gl_Position = vec4(1);\n"
12834 "}\n";
12835 char const *fsSource =
12836 "#version 450\n"
12837 "\n"
12838 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12839 "layout(location=0) out vec4 x;\n"
12840 "void main(){\n"
12841 " x = imageLoad(s, 0);\n"
12842 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012843 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12844 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12845 VkPipelineObj pipe(m_device);
12846 pipe.AddShader(&vs);
12847 pipe.AddShader(&fs);
12848 pipe.AddColorAttachment();
12849 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12850
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012852
Tony Barbour552f6c02016-12-21 14:34:07 -070012853 m_commandBuffer->BeginCommandBuffer();
12854 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012855 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12856 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12857 VkRect2D scissor = {{0, 0}, {16, 16}};
12858 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12859 // Bind pipeline to cmd buffer
12860 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12861 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12862 &descriptor_set, 0, nullptr);
12863 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012864 m_commandBuffer->EndRenderPass();
12865 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012866
12867 VkSubmitInfo submit_info = {};
12868 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12869 submit_info.commandBufferCount = 1;
12870 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12871 // Submit cmd buffer and then destroy bufferView while in-flight
12872 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12873
12874 vkDestroyBufferView(m_device->device(), view, nullptr);
12875 m_errorMonitor->VerifyFound();
12876 vkQueueWaitIdle(m_device->m_queue);
12877 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012878 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12879 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012880 vkDestroyBufferView(m_device->device(), view, NULL);
12881 vkDestroyBuffer(m_device->device(), buffer, NULL);
12882 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12883 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12884 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12885 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12886}
12887
Tobin Ehlis209532e2016-09-07 13:52:18 -060012888TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12889 TEST_DESCRIPTION("Delete in-use sampler.");
12890
12891 ASSERT_NO_FATAL_FAILURE(InitState());
12892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12893
12894 VkDescriptorPoolSize ds_type_count;
12895 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12896 ds_type_count.descriptorCount = 1;
12897
12898 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12899 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12900 ds_pool_ci.maxSets = 1;
12901 ds_pool_ci.poolSizeCount = 1;
12902 ds_pool_ci.pPoolSizes = &ds_type_count;
12903
12904 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012905 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012906 ASSERT_VK_SUCCESS(err);
12907
12908 VkSamplerCreateInfo sampler_ci = {};
12909 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12910 sampler_ci.pNext = NULL;
12911 sampler_ci.magFilter = VK_FILTER_NEAREST;
12912 sampler_ci.minFilter = VK_FILTER_NEAREST;
12913 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12914 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12915 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12916 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12917 sampler_ci.mipLodBias = 1.0;
12918 sampler_ci.anisotropyEnable = VK_FALSE;
12919 sampler_ci.maxAnisotropy = 1;
12920 sampler_ci.compareEnable = VK_FALSE;
12921 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12922 sampler_ci.minLod = 1.0;
12923 sampler_ci.maxLod = 1.0;
12924 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12925 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12926 VkSampler sampler;
12927
12928 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12929 ASSERT_VK_SUCCESS(err);
12930
12931 VkDescriptorSetLayoutBinding layout_binding;
12932 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012933 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012934 layout_binding.descriptorCount = 1;
12935 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12936 layout_binding.pImmutableSamplers = NULL;
12937
12938 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12939 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12940 ds_layout_ci.bindingCount = 1;
12941 ds_layout_ci.pBindings = &layout_binding;
12942 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012944 ASSERT_VK_SUCCESS(err);
12945
12946 VkDescriptorSetAllocateInfo alloc_info = {};
12947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12948 alloc_info.descriptorSetCount = 1;
12949 alloc_info.descriptorPool = ds_pool;
12950 alloc_info.pSetLayouts = &ds_layout;
12951 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012953 ASSERT_VK_SUCCESS(err);
12954
12955 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12956 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12957 pipeline_layout_ci.pNext = NULL;
12958 pipeline_layout_ci.setLayoutCount = 1;
12959 pipeline_layout_ci.pSetLayouts = &ds_layout;
12960
12961 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012962 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012963 ASSERT_VK_SUCCESS(err);
12964
12965 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012966 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 -060012967 ASSERT_TRUE(image.initialized());
12968
12969 VkImageView view;
12970 VkImageViewCreateInfo ivci = {};
12971 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12972 ivci.image = image.handle();
12973 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12974 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12975 ivci.subresourceRange.layerCount = 1;
12976 ivci.subresourceRange.baseMipLevel = 0;
12977 ivci.subresourceRange.levelCount = 1;
12978 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12979
12980 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12981 ASSERT_VK_SUCCESS(err);
12982
12983 VkDescriptorImageInfo image_info{};
12984 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12985 image_info.imageView = view;
12986 image_info.sampler = sampler;
12987
12988 VkWriteDescriptorSet descriptor_write = {};
12989 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12990 descriptor_write.dstSet = descriptor_set;
12991 descriptor_write.dstBinding = 0;
12992 descriptor_write.descriptorCount = 1;
12993 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12994 descriptor_write.pImageInfo = &image_info;
12995
12996 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12997
12998 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012999 char const *vsSource =
13000 "#version 450\n"
13001 "\n"
13002 "out gl_PerVertex { \n"
13003 " vec4 gl_Position;\n"
13004 "};\n"
13005 "void main(){\n"
13006 " gl_Position = vec4(1);\n"
13007 "}\n";
13008 char const *fsSource =
13009 "#version 450\n"
13010 "\n"
13011 "layout(set=0, binding=0) uniform sampler2D s;\n"
13012 "layout(location=0) out vec4 x;\n"
13013 "void main(){\n"
13014 " x = texture(s, vec2(1));\n"
13015 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013016 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13017 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13018 VkPipelineObj pipe(m_device);
13019 pipe.AddShader(&vs);
13020 pipe.AddShader(&fs);
13021 pipe.AddColorAttachment();
13022 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13023
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013025
Tony Barbour552f6c02016-12-21 14:34:07 -070013026 m_commandBuffer->BeginCommandBuffer();
13027 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013028 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013029 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13030 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13031 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013032
13033 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13034 VkRect2D scissor = {{0, 0}, {16, 16}};
13035 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13036 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13037
Tobin Ehlis209532e2016-09-07 13:52:18 -060013038 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013039 m_commandBuffer->EndRenderPass();
13040 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013041 // Submit cmd buffer then destroy sampler
13042 VkSubmitInfo submit_info = {};
13043 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13044 submit_info.commandBufferCount = 1;
13045 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13046 // Submit cmd buffer and then destroy sampler while in-flight
13047 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13048
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013049 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013050 m_errorMonitor->VerifyFound();
13051 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013052
Tobin Ehlis209532e2016-09-07 13:52:18 -060013053 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013054 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13055 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013056 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013057 vkDestroyImageView(m_device->device(), view, NULL);
13058 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13059 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13060 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13061}
13062
Mark Mueller1cd9f412016-08-25 13:23:52 -060013063TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013064 TEST_DESCRIPTION(
13065 "Call VkQueueSubmit with a semaphore that is already "
13066 "signaled but not waited on by the queue. Wait on a "
13067 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013068
13069 ASSERT_NO_FATAL_FAILURE(InitState());
13070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013072 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 -070013073 const char *invalid_fence_wait_message =
13074 " which has not been submitted on a Queue or during "
13075 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013076
Tony Barbour552f6c02016-12-21 14:34:07 -070013077 m_commandBuffer->BeginCommandBuffer();
13078 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013079
13080 VkSemaphoreCreateInfo semaphore_create_info = {};
13081 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13082 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013083 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013084 VkSubmitInfo submit_info = {};
13085 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13086 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013088 submit_info.signalSemaphoreCount = 1;
13089 submit_info.pSignalSemaphores = &semaphore;
13090 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013091 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013092 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013093 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013094 m_commandBuffer->BeginCommandBuffer();
13095 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013097 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13098 m_errorMonitor->VerifyFound();
13099
Mark Mueller1cd9f412016-08-25 13:23:52 -060013100 VkFenceCreateInfo fence_create_info = {};
13101 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13102 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013103 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013106 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13107 m_errorMonitor->VerifyFound();
13108
Mark Mueller4042b652016-09-05 22:52:21 -060013109 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013110 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013111 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13112}
13113
Tobin Ehlis4af23302016-07-19 10:50:30 -060013114TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013115 TEST_DESCRIPTION(
13116 "Bind a secondary command buffer with with a framebuffer "
13117 "that does not match the framebuffer for the active "
13118 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013119 ASSERT_NO_FATAL_FAILURE(InitState());
13120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13121
13122 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013123 VkAttachmentDescription attachment = {0,
13124 VK_FORMAT_B8G8R8A8_UNORM,
13125 VK_SAMPLE_COUNT_1_BIT,
13126 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13127 VK_ATTACHMENT_STORE_OP_STORE,
13128 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13129 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13130 VK_IMAGE_LAYOUT_UNDEFINED,
13131 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013133 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013135 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013137 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013138
13139 VkRenderPass rp;
13140 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13141 ASSERT_VK_SUCCESS(err);
13142
13143 // A compatible framebuffer.
13144 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013145 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 -060013146 ASSERT_TRUE(image.initialized());
13147
13148 VkImageViewCreateInfo ivci = {
13149 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13150 nullptr,
13151 0,
13152 image.handle(),
13153 VK_IMAGE_VIEW_TYPE_2D,
13154 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013155 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13156 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013157 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13158 };
13159 VkImageView view;
13160 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13161 ASSERT_VK_SUCCESS(err);
13162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013163 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013164 VkFramebuffer fb;
13165 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13166 ASSERT_VK_SUCCESS(err);
13167
13168 VkCommandBufferAllocateInfo cbai = {};
13169 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13170 cbai.commandPool = m_commandPool;
13171 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13172 cbai.commandBufferCount = 1;
13173
13174 VkCommandBuffer sec_cb;
13175 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13176 ASSERT_VK_SUCCESS(err);
13177 VkCommandBufferBeginInfo cbbi = {};
13178 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013179 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013180 cbii.renderPass = renderPass();
13181 cbii.framebuffer = fb;
13182 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13183 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013184 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 -060013185 cbbi.pInheritanceInfo = &cbii;
13186 vkBeginCommandBuffer(sec_cb, &cbbi);
13187 vkEndCommandBuffer(sec_cb);
13188
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013189 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013190 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13191 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013194 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013195 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13196 m_errorMonitor->VerifyFound();
13197 // Cleanup
13198 vkDestroyImageView(m_device->device(), view, NULL);
13199 vkDestroyRenderPass(m_device->device(), rp, NULL);
13200 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13201}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013202
13203TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013204 TEST_DESCRIPTION(
13205 "If logicOp is available on the device, set it to an "
13206 "invalid value. If logicOp is not available, attempt to "
13207 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013208 ASSERT_NO_FATAL_FAILURE(InitState());
13209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13210
13211 auto features = m_device->phy().features();
13212 // Set the expected error depending on whether or not logicOp available
13213 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13215 "If logic operations feature not "
13216 "enabled, logicOpEnable must be "
13217 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013218 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013220 }
13221 // Create a pipeline using logicOp
13222 VkResult err;
13223
13224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13226
13227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013229 ASSERT_VK_SUCCESS(err);
13230
13231 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13232 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13233 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013234 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013235 vp_state_ci.pViewports = &vp;
13236 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013237 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013238 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013239
13240 VkPipelineShaderStageCreateInfo shaderStages[2];
13241 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013243 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13244 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013245 shaderStages[0] = vs.GetStageCreateInfo();
13246 shaderStages[1] = fs.GetStageCreateInfo();
13247
13248 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13249 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13250
13251 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13252 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13253 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13254
13255 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13256 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013257 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013258
13259 VkPipelineColorBlendAttachmentState att = {};
13260 att.blendEnable = VK_FALSE;
13261 att.colorWriteMask = 0xf;
13262
13263 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13264 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13265 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13266 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013267 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013268 cb_ci.attachmentCount = 1;
13269 cb_ci.pAttachments = &att;
13270
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013271 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13272 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13273 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13274
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013275 VkGraphicsPipelineCreateInfo gp_ci = {};
13276 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13277 gp_ci.stageCount = 2;
13278 gp_ci.pStages = shaderStages;
13279 gp_ci.pVertexInputState = &vi_ci;
13280 gp_ci.pInputAssemblyState = &ia_ci;
13281 gp_ci.pViewportState = &vp_state_ci;
13282 gp_ci.pRasterizationState = &rs_ci;
13283 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013284 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013285 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13286 gp_ci.layout = pipeline_layout;
13287 gp_ci.renderPass = renderPass();
13288
13289 VkPipelineCacheCreateInfo pc_ci = {};
13290 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13291
13292 VkPipeline pipeline;
13293 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013295 ASSERT_VK_SUCCESS(err);
13296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013297 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013298 m_errorMonitor->VerifyFound();
13299 if (VK_SUCCESS == err) {
13300 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13301 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013302 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13304}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013305
Mike Stroyanaccf7692015-05-12 16:00:45 -060013306#if GTEST_IS_THREADSAFE
13307struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013308 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013309 VkEvent event;
13310 bool bailout;
13311};
13312
Karl Schultz6addd812016-02-02 17:17:23 -070013313extern "C" void *AddToCommandBuffer(void *arg) {
13314 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013315
Mike Stroyana6d14942016-07-13 15:10:05 -060013316 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013317 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013318 if (data->bailout) {
13319 break;
13320 }
13321 }
13322 return NULL;
13323}
13324
Karl Schultz6addd812016-02-02 17:17:23 -070013325TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013326 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013329
Mike Stroyanaccf7692015-05-12 16:00:45 -060013330 ASSERT_NO_FATAL_FAILURE(InitState());
13331 ASSERT_NO_FATAL_FAILURE(InitViewport());
13332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13333
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013334 // Calls AllocateCommandBuffers
13335 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013336
13337 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013338 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013339
13340 VkEventCreateInfo event_info;
13341 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013342 VkResult err;
13343
13344 memset(&event_info, 0, sizeof(event_info));
13345 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13346
Chia-I Wuf7458c52015-10-26 21:10:41 +080013347 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013348 ASSERT_VK_SUCCESS(err);
13349
Mike Stroyanaccf7692015-05-12 16:00:45 -060013350 err = vkResetEvent(device(), event);
13351 ASSERT_VK_SUCCESS(err);
13352
13353 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013354 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013355 data.event = event;
13356 data.bailout = false;
13357 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013358
13359 // First do some correct operations using multiple threads.
13360 // Add many entries to command buffer from another thread.
13361 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13362 // Make non-conflicting calls from this thread at the same time.
13363 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013364 uint32_t count;
13365 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013366 }
13367 test_platform_thread_join(thread, NULL);
13368
13369 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013370 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013371 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013372 // Add many entries to command buffer from this thread at the same time.
13373 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013374
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013375 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013376 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013377
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013378 m_errorMonitor->SetBailout(NULL);
13379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013380 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013381
Chia-I Wuf7458c52015-10-26 21:10:41 +080013382 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013383}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013384#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013385
Karl Schultz6addd812016-02-02 17:17:23 -070013386TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013387 TEST_DESCRIPTION(
13388 "Test that an error is produced for a spirv module "
13389 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013392
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013393 ASSERT_NO_FATAL_FAILURE(InitState());
13394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13395
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013396 VkShaderModule module;
13397 VkShaderModuleCreateInfo moduleCreateInfo;
13398 struct icd_spv_header spv;
13399
13400 spv.magic = ICD_SPV_MAGIC;
13401 spv.version = ICD_SPV_VERSION;
13402 spv.gen_magic = 0;
13403
13404 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13405 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013406 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013407 moduleCreateInfo.codeSize = 4;
13408 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013409 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013411 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013412}
13413
Karl Schultz6addd812016-02-02 17:17:23 -070013414TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013415 TEST_DESCRIPTION(
13416 "Test that an error is produced for a spirv module "
13417 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013420
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013421 ASSERT_NO_FATAL_FAILURE(InitState());
13422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13423
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013424 VkShaderModule module;
13425 VkShaderModuleCreateInfo moduleCreateInfo;
13426 struct icd_spv_header spv;
13427
13428 spv.magic = ~ICD_SPV_MAGIC;
13429 spv.version = ICD_SPV_VERSION;
13430 spv.gen_magic = 0;
13431
13432 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13433 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013434 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013435 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13436 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013437 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013438
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013439 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013440}
13441
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013442#if 0
13443// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013444TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013446 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013447
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013448 ASSERT_NO_FATAL_FAILURE(InitState());
13449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13450
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013451 VkShaderModule module;
13452 VkShaderModuleCreateInfo moduleCreateInfo;
13453 struct icd_spv_header spv;
13454
13455 spv.magic = ICD_SPV_MAGIC;
13456 spv.version = ~ICD_SPV_VERSION;
13457 spv.gen_magic = 0;
13458
13459 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13460 moduleCreateInfo.pNext = NULL;
13461
Karl Schultz6addd812016-02-02 17:17:23 -070013462 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013463 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13464 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013465 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013466
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013467 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013468}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013469#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013470
Karl Schultz6addd812016-02-02 17:17:23 -070013471TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013472 TEST_DESCRIPTION(
13473 "Test that a warning is produced for a vertex output that "
13474 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013476
Chris Forbes9f7ff632015-05-25 11:13:08 +120013477 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013479
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013480 char const *vsSource =
13481 "#version 450\n"
13482 "\n"
13483 "layout(location=0) out float x;\n"
13484 "out gl_PerVertex {\n"
13485 " vec4 gl_Position;\n"
13486 "};\n"
13487 "void main(){\n"
13488 " gl_Position = vec4(1);\n"
13489 " x = 0;\n"
13490 "}\n";
13491 char const *fsSource =
13492 "#version 450\n"
13493 "\n"
13494 "layout(location=0) out vec4 color;\n"
13495 "void main(){\n"
13496 " color = vec4(1);\n"
13497 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013498
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013501
13502 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013503 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013504 pipe.AddShader(&vs);
13505 pipe.AddShader(&fs);
13506
Chris Forbes9f7ff632015-05-25 11:13:08 +120013507 VkDescriptorSetObj descriptorSet(m_device);
13508 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013509 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013510
Tony Barbour5781e8f2015-08-04 16:23:11 -060013511 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013512
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013513 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013514}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013515
Mark Mueller098c9cb2016-09-08 09:01:57 -060013516TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13517 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13518
13519 ASSERT_NO_FATAL_FAILURE(InitState());
13520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13521
13522 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013523 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013524
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013525 char const *vsSource =
13526 "#version 450\n"
13527 "\n"
13528 "out gl_PerVertex {\n"
13529 " vec4 gl_Position;\n"
13530 "};\n"
13531 "void main(){\n"
13532 " gl_Position = vec4(1);\n"
13533 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013534
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013535 char const *fsSource =
13536 "#version 450\n"
13537 "\n"
13538 "layout (constant_id = 0) const float r = 0.0f;\n"
13539 "layout(location = 0) out vec4 uFragColor;\n"
13540 "void main(){\n"
13541 " uFragColor = vec4(r,1,0,1);\n"
13542 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013543
13544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13546
13547 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13548 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13549
13550 VkPipelineLayout pipeline_layout;
13551 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13552
13553 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13554 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13555 vp_state_create_info.viewportCount = 1;
13556 VkViewport viewport = {};
13557 vp_state_create_info.pViewports = &viewport;
13558 vp_state_create_info.scissorCount = 1;
13559 VkRect2D scissors = {};
13560 vp_state_create_info.pScissors = &scissors;
13561
13562 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13563
13564 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13565 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13566 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13567 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13568
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013569 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013570
13571 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13572 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13573
13574 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13575 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13576 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13577
13578 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13579 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13580 rasterization_state_create_info.pNext = nullptr;
13581 rasterization_state_create_info.lineWidth = 1.0f;
13582 rasterization_state_create_info.rasterizerDiscardEnable = true;
13583
13584 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13585 color_blend_attachment_state.blendEnable = VK_FALSE;
13586 color_blend_attachment_state.colorWriteMask = 0xf;
13587
13588 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13589 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13590 color_blend_state_create_info.attachmentCount = 1;
13591 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13592
13593 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13594 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13595 graphicspipe_create_info.stageCount = 2;
13596 graphicspipe_create_info.pStages = shader_stage_create_info;
13597 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13598 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13599 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13600 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13601 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13602 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13603 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13604 graphicspipe_create_info.layout = pipeline_layout;
13605 graphicspipe_create_info.renderPass = renderPass();
13606
13607 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13608 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13609
13610 VkPipelineCache pipelineCache;
13611 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13612
13613 // This structure maps constant ids to data locations.
13614 const VkSpecializationMapEntry entry =
13615 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013616 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013617
13618 uint32_t data = 1;
13619
13620 // Set up the info describing spec map and data
13621 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013622 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013623 };
13624 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13625
13626 VkPipeline pipeline;
13627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13628 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13629 m_errorMonitor->VerifyFound();
13630
13631 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13632 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13633}
13634
13635TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13636 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13637
13638 ASSERT_NO_FATAL_FAILURE(InitState());
13639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13640
13641 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13642
13643 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13644 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13645 descriptor_pool_type_count[0].descriptorCount = 1;
13646 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13647 descriptor_pool_type_count[1].descriptorCount = 1;
13648
13649 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13650 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13651 descriptor_pool_create_info.maxSets = 1;
13652 descriptor_pool_create_info.poolSizeCount = 2;
13653 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13654 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13655
13656 VkDescriptorPool descriptorset_pool;
13657 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13658
13659 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13660 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13661 descriptorset_layout_binding.descriptorCount = 1;
13662 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013663 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013664
13665 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13666 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13667 descriptorset_layout_create_info.bindingCount = 1;
13668 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13669
13670 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013671 ASSERT_VK_SUCCESS(
13672 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013673
13674 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13675 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13676 descriptorset_allocate_info.descriptorSetCount = 1;
13677 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13678 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13679 VkDescriptorSet descriptorset;
13680 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13681
13682 // Challenge core_validation with a non uniform buffer type.
13683 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13684
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013685 char const *vsSource =
13686 "#version 450\n"
13687 "\n"
13688 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13689 " mat4 mvp;\n"
13690 "} ubuf;\n"
13691 "out gl_PerVertex {\n"
13692 " vec4 gl_Position;\n"
13693 "};\n"
13694 "void main(){\n"
13695 " gl_Position = ubuf.mvp * vec4(1);\n"
13696 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013697
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013698 char const *fsSource =
13699 "#version 450\n"
13700 "\n"
13701 "layout(location = 0) out vec4 uFragColor;\n"
13702 "void main(){\n"
13703 " uFragColor = vec4(0,1,0,1);\n"
13704 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013705
13706 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13707 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13708
13709 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13710 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13711 pipeline_layout_create_info.setLayoutCount = 1;
13712 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13713
13714 VkPipelineLayout pipeline_layout;
13715 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13716
13717 VkPipelineObj pipe(m_device);
13718 pipe.AddColorAttachment();
13719 pipe.AddShader(&vs);
13720 pipe.AddShader(&fs);
13721
13722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13723 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13724 m_errorMonitor->VerifyFound();
13725
13726 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13727 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13728 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13729}
13730
13731TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13732 TEST_DESCRIPTION(
13733 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13734
13735 ASSERT_NO_FATAL_FAILURE(InitState());
13736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13737
13738 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13739
13740 VkDescriptorPoolSize descriptor_pool_type_count = {};
13741 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13742 descriptor_pool_type_count.descriptorCount = 1;
13743
13744 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13745 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13746 descriptor_pool_create_info.maxSets = 1;
13747 descriptor_pool_create_info.poolSizeCount = 1;
13748 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13749 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13750
13751 VkDescriptorPool descriptorset_pool;
13752 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13753
13754 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13755 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13756 descriptorset_layout_binding.descriptorCount = 1;
13757 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13758 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070013759 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013760
13761 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13762 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13763 descriptorset_layout_create_info.bindingCount = 1;
13764 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13765
13766 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013767 ASSERT_VK_SUCCESS(
13768 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013769
13770 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13771 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13772 descriptorset_allocate_info.descriptorSetCount = 1;
13773 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13774 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13775 VkDescriptorSet descriptorset;
13776 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13777
13778 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13779
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013780 char const *vsSource =
13781 "#version 450\n"
13782 "\n"
13783 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13784 " mat4 mvp;\n"
13785 "} ubuf;\n"
13786 "out gl_PerVertex {\n"
13787 " vec4 gl_Position;\n"
13788 "};\n"
13789 "void main(){\n"
13790 " gl_Position = ubuf.mvp * vec4(1);\n"
13791 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013792
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013793 char const *fsSource =
13794 "#version 450\n"
13795 "\n"
13796 "layout(location = 0) out vec4 uFragColor;\n"
13797 "void main(){\n"
13798 " uFragColor = vec4(0,1,0,1);\n"
13799 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013800
13801 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13802 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13803
13804 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13805 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13806 pipeline_layout_create_info.setLayoutCount = 1;
13807 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13808
13809 VkPipelineLayout pipeline_layout;
13810 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13811
13812 VkPipelineObj pipe(m_device);
13813 pipe.AddColorAttachment();
13814 pipe.AddShader(&vs);
13815 pipe.AddShader(&fs);
13816
13817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13818 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13819 m_errorMonitor->VerifyFound();
13820
13821 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13822 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13823 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13824}
13825
13826TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013827 TEST_DESCRIPTION(
13828 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13829 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013830
13831 ASSERT_NO_FATAL_FAILURE(InitState());
13832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13833
13834 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013835 "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 -060013836
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013837 char const *vsSource =
13838 "#version 450\n"
13839 "\n"
13840 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13841 "out gl_PerVertex {\n"
13842 " vec4 gl_Position;\n"
13843 "};\n"
13844 "void main(){\n"
13845 " gl_Position = vec4(consts.x);\n"
13846 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013847
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013848 char const *fsSource =
13849 "#version 450\n"
13850 "\n"
13851 "layout(location = 0) out vec4 uFragColor;\n"
13852 "void main(){\n"
13853 " uFragColor = vec4(0,1,0,1);\n"
13854 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013855
13856 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13857 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13858
13859 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13860 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13861
13862 // Set up a push constant range
13863 VkPushConstantRange push_constant_ranges = {};
13864 // Set to the wrong stage to challenge core_validation
13865 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13866 push_constant_ranges.size = 4;
13867
13868 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13869 pipeline_layout_create_info.pushConstantRangeCount = 1;
13870
13871 VkPipelineLayout pipeline_layout;
13872 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13873
13874 VkPipelineObj pipe(m_device);
13875 pipe.AddColorAttachment();
13876 pipe.AddShader(&vs);
13877 pipe.AddShader(&fs);
13878
13879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13880 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13881 m_errorMonitor->VerifyFound();
13882
13883 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13884}
13885
13886TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13887 TEST_DESCRIPTION(
13888 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13889
13890 ASSERT_NO_FATAL_FAILURE(InitState());
13891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13892
13893 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013894 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013895
13896 // Some awkward steps are required to test with custom device features.
13897 std::vector<const char *> device_extension_names;
13898 auto features = m_device->phy().features();
13899 // Disable support for 64 bit floats
13900 features.shaderFloat64 = false;
13901 // The sacrificial device object
13902 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013904 char const *vsSource =
13905 "#version 450\n"
13906 "\n"
13907 "out gl_PerVertex {\n"
13908 " vec4 gl_Position;\n"
13909 "};\n"
13910 "void main(){\n"
13911 " gl_Position = vec4(1);\n"
13912 "}\n";
13913 char const *fsSource =
13914 "#version 450\n"
13915 "\n"
13916 "layout(location=0) out vec4 color;\n"
13917 "void main(){\n"
13918 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13919 " color = vec4(green);\n"
13920 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013921
13922 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13923 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13924
13925 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013926
13927 VkPipelineObj pipe(&test_device);
13928 pipe.AddColorAttachment();
13929 pipe.AddShader(&vs);
13930 pipe.AddShader(&fs);
13931
13932 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13933 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13934 VkPipelineLayout pipeline_layout;
13935 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13936
13937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13938 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13939 m_errorMonitor->VerifyFound();
13940
13941 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13942}
13943
13944TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13945 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13946
13947 ASSERT_NO_FATAL_FAILURE(InitState());
13948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13949
13950 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013952 char const *vsSource =
13953 "#version 450\n"
13954 "\n"
13955 "out gl_PerVertex {\n"
13956 " vec4 gl_Position;\n"
13957 "};\n"
13958 "layout(xfb_buffer = 1) out;"
13959 "void main(){\n"
13960 " gl_Position = vec4(1);\n"
13961 "}\n";
13962 char const *fsSource =
13963 "#version 450\n"
13964 "\n"
13965 "layout(location=0) out vec4 color;\n"
13966 "void main(){\n"
13967 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13968 " color = vec4(green);\n"
13969 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013970
13971 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13972 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13973
13974 VkPipelineObj pipe(m_device);
13975 pipe.AddColorAttachment();
13976 pipe.AddShader(&vs);
13977 pipe.AddShader(&fs);
13978
13979 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13980 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13981 VkPipelineLayout pipeline_layout;
13982 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13983
13984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13985 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13986 m_errorMonitor->VerifyFound();
13987
13988 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13989}
13990
Karl Schultz6addd812016-02-02 17:17:23 -070013991TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013992 TEST_DESCRIPTION(
13993 "Test that an error is produced for a fragment shader input "
13994 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013997
Chris Forbes59cb88d2015-05-25 11:13:13 +120013998 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014000
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014001 char const *vsSource =
14002 "#version 450\n"
14003 "\n"
14004 "out gl_PerVertex {\n"
14005 " vec4 gl_Position;\n"
14006 "};\n"
14007 "void main(){\n"
14008 " gl_Position = vec4(1);\n"
14009 "}\n";
14010 char const *fsSource =
14011 "#version 450\n"
14012 "\n"
14013 "layout(location=0) in float x;\n"
14014 "layout(location=0) out vec4 color;\n"
14015 "void main(){\n"
14016 " color = vec4(x);\n"
14017 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014018
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014019 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14020 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014021
14022 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014023 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014024 pipe.AddShader(&vs);
14025 pipe.AddShader(&fs);
14026
Chris Forbes59cb88d2015-05-25 11:13:13 +120014027 VkDescriptorSetObj descriptorSet(m_device);
14028 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014029 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014030
Tony Barbour5781e8f2015-08-04 16:23:11 -060014031 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014032
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014033 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014034}
14035
Karl Schultz6addd812016-02-02 17:17:23 -070014036TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014037 TEST_DESCRIPTION(
14038 "Test that an error is produced for a fragment shader input "
14039 "within an interace block, which is not present in the outputs "
14040 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014042
14043 ASSERT_NO_FATAL_FAILURE(InitState());
14044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14045
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014046 char const *vsSource =
14047 "#version 450\n"
14048 "\n"
14049 "out gl_PerVertex {\n"
14050 " vec4 gl_Position;\n"
14051 "};\n"
14052 "void main(){\n"
14053 " gl_Position = vec4(1);\n"
14054 "}\n";
14055 char const *fsSource =
14056 "#version 450\n"
14057 "\n"
14058 "in block { layout(location=0) float x; } ins;\n"
14059 "layout(location=0) out vec4 color;\n"
14060 "void main(){\n"
14061 " color = vec4(ins.x);\n"
14062 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014063
14064 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14066
14067 VkPipelineObj pipe(m_device);
14068 pipe.AddColorAttachment();
14069 pipe.AddShader(&vs);
14070 pipe.AddShader(&fs);
14071
14072 VkDescriptorSetObj descriptorSet(m_device);
14073 descriptorSet.AppendDummy();
14074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14075
14076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14077
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014078 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014079}
14080
Karl Schultz6addd812016-02-02 17:17:23 -070014081TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014082 TEST_DESCRIPTION(
14083 "Test that an error is produced for mismatched array sizes "
14084 "across the vertex->fragment shader interface");
14085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14086 "Type mismatch on location 0.0: 'ptr to "
14087 "output arr[2] of float32' vs 'ptr to "
14088 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014089
14090 ASSERT_NO_FATAL_FAILURE(InitState());
14091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14092
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014093 char const *vsSource =
14094 "#version 450\n"
14095 "\n"
14096 "layout(location=0) out float x[2];\n"
14097 "out gl_PerVertex {\n"
14098 " vec4 gl_Position;\n"
14099 "};\n"
14100 "void main(){\n"
14101 " x[0] = 0; x[1] = 0;\n"
14102 " gl_Position = vec4(1);\n"
14103 "}\n";
14104 char const *fsSource =
14105 "#version 450\n"
14106 "\n"
14107 "layout(location=0) in float x[1];\n"
14108 "layout(location=0) out vec4 color;\n"
14109 "void main(){\n"
14110 " color = vec4(x[0]);\n"
14111 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014112
14113 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14114 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14115
14116 VkPipelineObj pipe(m_device);
14117 pipe.AddColorAttachment();
14118 pipe.AddShader(&vs);
14119 pipe.AddShader(&fs);
14120
14121 VkDescriptorSetObj descriptorSet(m_device);
14122 descriptorSet.AppendDummy();
14123 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14124
14125 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14126
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014127 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014128}
14129
Karl Schultz6addd812016-02-02 17:17:23 -070014130TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014131 TEST_DESCRIPTION(
14132 "Test that an error is produced for mismatched types across "
14133 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014135
Chris Forbesb56af562015-05-25 11:13:17 +120014136 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014138
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014139 char const *vsSource =
14140 "#version 450\n"
14141 "\n"
14142 "layout(location=0) out int x;\n"
14143 "out gl_PerVertex {\n"
14144 " vec4 gl_Position;\n"
14145 "};\n"
14146 "void main(){\n"
14147 " x = 0;\n"
14148 " gl_Position = vec4(1);\n"
14149 "}\n";
14150 char const *fsSource =
14151 "#version 450\n"
14152 "\n"
14153 "layout(location=0) in float x;\n" /* VS writes int */
14154 "layout(location=0) out vec4 color;\n"
14155 "void main(){\n"
14156 " color = vec4(x);\n"
14157 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014158
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14160 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014161
14162 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014163 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014164 pipe.AddShader(&vs);
14165 pipe.AddShader(&fs);
14166
Chris Forbesb56af562015-05-25 11:13:17 +120014167 VkDescriptorSetObj descriptorSet(m_device);
14168 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014169 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014170
Tony Barbour5781e8f2015-08-04 16:23:11 -060014171 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014172
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014173 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014174}
14175
Karl Schultz6addd812016-02-02 17:17:23 -070014176TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014177 TEST_DESCRIPTION(
14178 "Test that an error is produced for mismatched types across "
14179 "the vertex->fragment shader interface, when the variable is contained within "
14180 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014182
14183 ASSERT_NO_FATAL_FAILURE(InitState());
14184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14185
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014186 char const *vsSource =
14187 "#version 450\n"
14188 "\n"
14189 "out block { layout(location=0) int x; } outs;\n"
14190 "out gl_PerVertex {\n"
14191 " vec4 gl_Position;\n"
14192 "};\n"
14193 "void main(){\n"
14194 " outs.x = 0;\n"
14195 " gl_Position = vec4(1);\n"
14196 "}\n";
14197 char const *fsSource =
14198 "#version 450\n"
14199 "\n"
14200 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14201 "layout(location=0) out vec4 color;\n"
14202 "void main(){\n"
14203 " color = vec4(ins.x);\n"
14204 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014205
14206 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14207 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14208
14209 VkPipelineObj pipe(m_device);
14210 pipe.AddColorAttachment();
14211 pipe.AddShader(&vs);
14212 pipe.AddShader(&fs);
14213
14214 VkDescriptorSetObj descriptorSet(m_device);
14215 descriptorSet.AppendDummy();
14216 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14217
14218 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14219
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014220 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014221}
14222
14223TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014224 TEST_DESCRIPTION(
14225 "Test that an error is produced for location mismatches across "
14226 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14227 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 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 +130014229
14230 ASSERT_NO_FATAL_FAILURE(InitState());
14231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14232
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014233 char const *vsSource =
14234 "#version 450\n"
14235 "\n"
14236 "out block { layout(location=1) float x; } outs;\n"
14237 "out gl_PerVertex {\n"
14238 " vec4 gl_Position;\n"
14239 "};\n"
14240 "void main(){\n"
14241 " outs.x = 0;\n"
14242 " gl_Position = vec4(1);\n"
14243 "}\n";
14244 char const *fsSource =
14245 "#version 450\n"
14246 "\n"
14247 "in block { layout(location=0) float x; } ins;\n"
14248 "layout(location=0) out vec4 color;\n"
14249 "void main(){\n"
14250 " color = vec4(ins.x);\n"
14251 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014252
14253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14255
14256 VkPipelineObj pipe(m_device);
14257 pipe.AddColorAttachment();
14258 pipe.AddShader(&vs);
14259 pipe.AddShader(&fs);
14260
14261 VkDescriptorSetObj descriptorSet(m_device);
14262 descriptorSet.AppendDummy();
14263 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14264
14265 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14266
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014267 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014268}
14269
14270TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014271 TEST_DESCRIPTION(
14272 "Test that an error is produced for component mismatches across the "
14273 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14274 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014275 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 +130014276
14277 ASSERT_NO_FATAL_FAILURE(InitState());
14278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14279
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014280 char const *vsSource =
14281 "#version 450\n"
14282 "\n"
14283 "out block { layout(location=0, component=0) float x; } outs;\n"
14284 "out gl_PerVertex {\n"
14285 " vec4 gl_Position;\n"
14286 "};\n"
14287 "void main(){\n"
14288 " outs.x = 0;\n"
14289 " gl_Position = vec4(1);\n"
14290 "}\n";
14291 char const *fsSource =
14292 "#version 450\n"
14293 "\n"
14294 "in block { layout(location=0, component=1) float x; } ins;\n"
14295 "layout(location=0) out vec4 color;\n"
14296 "void main(){\n"
14297 " color = vec4(ins.x);\n"
14298 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014299
14300 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14301 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14302
14303 VkPipelineObj pipe(m_device);
14304 pipe.AddColorAttachment();
14305 pipe.AddShader(&vs);
14306 pipe.AddShader(&fs);
14307
14308 VkDescriptorSetObj descriptorSet(m_device);
14309 descriptorSet.AppendDummy();
14310 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14311
14312 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014314 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014315}
14316
Chris Forbes1f3b0152016-11-30 12:48:40 +130014317TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14318 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14319
14320 ASSERT_NO_FATAL_FAILURE(InitState());
14321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014323 char const *vsSource =
14324 "#version 450\n"
14325 "layout(location=0) out mediump float x;\n"
14326 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14327 char const *fsSource =
14328 "#version 450\n"
14329 "layout(location=0) in highp float x;\n"
14330 "layout(location=0) out vec4 color;\n"
14331 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014332
14333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14335
14336 VkPipelineObj pipe(m_device);
14337 pipe.AddColorAttachment();
14338 pipe.AddShader(&vs);
14339 pipe.AddShader(&fs);
14340
14341 VkDescriptorSetObj descriptorSet(m_device);
14342 descriptorSet.AppendDummy();
14343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14344
14345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14346
14347 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14348
14349 m_errorMonitor->VerifyFound();
14350}
14351
Chris Forbes870a39e2016-11-30 12:55:56 +130014352TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14353 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14354
14355 ASSERT_NO_FATAL_FAILURE(InitState());
14356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14357
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014358 char const *vsSource =
14359 "#version 450\n"
14360 "out block { layout(location=0) mediump float x; };\n"
14361 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14362 char const *fsSource =
14363 "#version 450\n"
14364 "in block { layout(location=0) highp float x; };\n"
14365 "layout(location=0) out vec4 color;\n"
14366 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014367
14368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14370
14371 VkPipelineObj pipe(m_device);
14372 pipe.AddColorAttachment();
14373 pipe.AddShader(&vs);
14374 pipe.AddShader(&fs);
14375
14376 VkDescriptorSetObj descriptorSet(m_device);
14377 descriptorSet.AppendDummy();
14378 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14379
14380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14381
14382 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14383
14384 m_errorMonitor->VerifyFound();
14385}
14386
Karl Schultz6addd812016-02-02 17:17:23 -070014387TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014388 TEST_DESCRIPTION(
14389 "Test that a warning is produced for a vertex attribute which is "
14390 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014392
Chris Forbesde136e02015-05-25 11:13:28 +120014393 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014395
14396 VkVertexInputBindingDescription input_binding;
14397 memset(&input_binding, 0, sizeof(input_binding));
14398
14399 VkVertexInputAttributeDescription input_attrib;
14400 memset(&input_attrib, 0, sizeof(input_attrib));
14401 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14402
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014403 char const *vsSource =
14404 "#version 450\n"
14405 "\n"
14406 "out gl_PerVertex {\n"
14407 " vec4 gl_Position;\n"
14408 "};\n"
14409 "void main(){\n"
14410 " gl_Position = vec4(1);\n"
14411 "}\n";
14412 char const *fsSource =
14413 "#version 450\n"
14414 "\n"
14415 "layout(location=0) out vec4 color;\n"
14416 "void main(){\n"
14417 " color = vec4(1);\n"
14418 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014419
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014422
14423 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014424 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014425 pipe.AddShader(&vs);
14426 pipe.AddShader(&fs);
14427
14428 pipe.AddVertexInputBindings(&input_binding, 1);
14429 pipe.AddVertexInputAttribs(&input_attrib, 1);
14430
Chris Forbesde136e02015-05-25 11:13:28 +120014431 VkDescriptorSetObj descriptorSet(m_device);
14432 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014434
Tony Barbour5781e8f2015-08-04 16:23:11 -060014435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014437 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014438}
14439
Karl Schultz6addd812016-02-02 17:17:23 -070014440TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014441 TEST_DESCRIPTION(
14442 "Test that a warning is produced for a location mismatch on "
14443 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014445
14446 ASSERT_NO_FATAL_FAILURE(InitState());
14447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14448
14449 VkVertexInputBindingDescription input_binding;
14450 memset(&input_binding, 0, sizeof(input_binding));
14451
14452 VkVertexInputAttributeDescription input_attrib;
14453 memset(&input_attrib, 0, sizeof(input_attrib));
14454 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014456 char const *vsSource =
14457 "#version 450\n"
14458 "\n"
14459 "layout(location=1) in float x;\n"
14460 "out gl_PerVertex {\n"
14461 " vec4 gl_Position;\n"
14462 "};\n"
14463 "void main(){\n"
14464 " gl_Position = vec4(x);\n"
14465 "}\n";
14466 char const *fsSource =
14467 "#version 450\n"
14468 "\n"
14469 "layout(location=0) out vec4 color;\n"
14470 "void main(){\n"
14471 " color = vec4(1);\n"
14472 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014473
14474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14476
14477 VkPipelineObj pipe(m_device);
14478 pipe.AddColorAttachment();
14479 pipe.AddShader(&vs);
14480 pipe.AddShader(&fs);
14481
14482 pipe.AddVertexInputBindings(&input_binding, 1);
14483 pipe.AddVertexInputAttribs(&input_attrib, 1);
14484
14485 VkDescriptorSetObj descriptorSet(m_device);
14486 descriptorSet.AppendDummy();
14487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14488
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014489 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014490 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14491
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014492 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014493}
14494
Karl Schultz6addd812016-02-02 17:17:23 -070014495TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014496 TEST_DESCRIPTION(
14497 "Test that an error is produced for a vertex shader input which is not "
14498 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14500 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014501
Chris Forbes62e8e502015-05-25 11:13:29 +120014502 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014505 char const *vsSource =
14506 "#version 450\n"
14507 "\n"
14508 "layout(location=0) in vec4 x;\n" /* not provided */
14509 "out gl_PerVertex {\n"
14510 " vec4 gl_Position;\n"
14511 "};\n"
14512 "void main(){\n"
14513 " gl_Position = x;\n"
14514 "}\n";
14515 char const *fsSource =
14516 "#version 450\n"
14517 "\n"
14518 "layout(location=0) out vec4 color;\n"
14519 "void main(){\n"
14520 " color = vec4(1);\n"
14521 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014522
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014525
14526 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014527 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014528 pipe.AddShader(&vs);
14529 pipe.AddShader(&fs);
14530
Chris Forbes62e8e502015-05-25 11:13:29 +120014531 VkDescriptorSetObj descriptorSet(m_device);
14532 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014534
Tony Barbour5781e8f2015-08-04 16:23:11 -060014535 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014536
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014537 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014538}
14539
Karl Schultz6addd812016-02-02 17:17:23 -070014540TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014541 TEST_DESCRIPTION(
14542 "Test that an error is produced for a mismatch between the "
14543 "fundamental type (float/int/uint) of an attribute and the "
14544 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014545 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 -060014546
Chris Forbesc97d98e2015-05-25 11:13:31 +120014547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014549
14550 VkVertexInputBindingDescription input_binding;
14551 memset(&input_binding, 0, sizeof(input_binding));
14552
14553 VkVertexInputAttributeDescription input_attrib;
14554 memset(&input_attrib, 0, sizeof(input_attrib));
14555 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14556
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014557 char const *vsSource =
14558 "#version 450\n"
14559 "\n"
14560 "layout(location=0) in int x;\n" /* attrib provided float */
14561 "out gl_PerVertex {\n"
14562 " vec4 gl_Position;\n"
14563 "};\n"
14564 "void main(){\n"
14565 " gl_Position = vec4(x);\n"
14566 "}\n";
14567 char const *fsSource =
14568 "#version 450\n"
14569 "\n"
14570 "layout(location=0) out vec4 color;\n"
14571 "void main(){\n"
14572 " color = vec4(1);\n"
14573 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014574
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014575 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14576 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014577
14578 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014579 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014580 pipe.AddShader(&vs);
14581 pipe.AddShader(&fs);
14582
14583 pipe.AddVertexInputBindings(&input_binding, 1);
14584 pipe.AddVertexInputAttribs(&input_attrib, 1);
14585
Chris Forbesc97d98e2015-05-25 11:13:31 +120014586 VkDescriptorSetObj descriptorSet(m_device);
14587 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014589
Tony Barbour5781e8f2015-08-04 16:23:11 -060014590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014591
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014592 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014593}
14594
Chris Forbesc68b43c2016-04-06 11:18:47 +120014595TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014596 TEST_DESCRIPTION(
14597 "Test that an error is produced for a pipeline containing multiple "
14598 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14600 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014601
14602 ASSERT_NO_FATAL_FAILURE(InitState());
14603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014605 char const *vsSource =
14606 "#version 450\n"
14607 "\n"
14608 "out gl_PerVertex {\n"
14609 " vec4 gl_Position;\n"
14610 "};\n"
14611 "void main(){\n"
14612 " gl_Position = vec4(1);\n"
14613 "}\n";
14614 char const *fsSource =
14615 "#version 450\n"
14616 "\n"
14617 "layout(location=0) out vec4 color;\n"
14618 "void main(){\n"
14619 " color = vec4(1);\n"
14620 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014621
14622 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14623 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14624
14625 VkPipelineObj pipe(m_device);
14626 pipe.AddColorAttachment();
14627 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014628 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014629 pipe.AddShader(&fs);
14630
14631 VkDescriptorSetObj descriptorSet(m_device);
14632 descriptorSet.AppendDummy();
14633 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14634
14635 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014637 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014638}
14639
Chris Forbes82ff92a2016-09-09 10:50:24 +120014640TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014642
14643 ASSERT_NO_FATAL_FAILURE(InitState());
14644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14645
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014646 char const *vsSource =
14647 "#version 450\n"
14648 "out gl_PerVertex {\n"
14649 " vec4 gl_Position;\n"
14650 "};\n"
14651 "void main(){\n"
14652 " gl_Position = vec4(0);\n"
14653 "}\n";
14654 char const *fsSource =
14655 "#version 450\n"
14656 "\n"
14657 "layout(location=0) out vec4 color;\n"
14658 "void main(){\n"
14659 " color = vec4(1);\n"
14660 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014661
14662 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14663 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14664
14665 VkPipelineObj pipe(m_device);
14666 pipe.AddColorAttachment();
14667 pipe.AddShader(&vs);
14668 pipe.AddShader(&fs);
14669
14670 VkDescriptorSetObj descriptorSet(m_device);
14671 descriptorSet.AppendDummy();
14672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14673
14674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14675
14676 m_errorMonitor->VerifyFound();
14677}
14678
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014679TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14681 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14682 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014683
14684 ASSERT_NO_FATAL_FAILURE(InitState());
14685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14686
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014687 char const *vsSource =
14688 "#version 450\n"
14689 "void main(){ gl_Position = vec4(0); }\n";
14690 char const *fsSource =
14691 "#version 450\n"
14692 "\n"
14693 "layout(location=0) out vec4 color;\n"
14694 "void main(){\n"
14695 " color = vec4(1);\n"
14696 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014697
14698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14700
14701 VkPipelineObj pipe(m_device);
14702 pipe.AddColorAttachment();
14703 pipe.AddShader(&vs);
14704 pipe.AddShader(&fs);
14705
14706 VkDescriptorSetObj descriptorSet(m_device);
14707 descriptorSet.AppendDummy();
14708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14709
14710 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014711 {
14712 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14714 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014715 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014716 {
14717 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14718 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14719 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014720 },
14721 };
14722 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014723 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014724 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014725 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14726 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014727 VkRenderPass rp;
14728 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14729 ASSERT_VK_SUCCESS(err);
14730
14731 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14732
14733 m_errorMonitor->VerifyFound();
14734
14735 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14736}
14737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014738TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014739 TEST_DESCRIPTION(
14740 "Test that an error is produced for a variable output from "
14741 "the TCS without the patch decoration, but consumed in the TES "
14742 "with the decoration.");
14743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14744 "is per-vertex in tessellation control shader stage "
14745 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014746
14747 ASSERT_NO_FATAL_FAILURE(InitState());
14748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14749
Chris Forbesc1e852d2016-04-04 19:26:42 +120014750 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014751 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014752 return;
14753 }
14754
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014755 char const *vsSource =
14756 "#version 450\n"
14757 "void main(){}\n";
14758 char const *tcsSource =
14759 "#version 450\n"
14760 "layout(location=0) out int x[];\n"
14761 "layout(vertices=3) out;\n"
14762 "void main(){\n"
14763 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14764 " gl_TessLevelInner[0] = 1;\n"
14765 " x[gl_InvocationID] = gl_InvocationID;\n"
14766 "}\n";
14767 char const *tesSource =
14768 "#version 450\n"
14769 "layout(triangles, equal_spacing, cw) in;\n"
14770 "layout(location=0) patch in int x;\n"
14771 "out gl_PerVertex { vec4 gl_Position; };\n"
14772 "void main(){\n"
14773 " gl_Position.xyz = gl_TessCoord;\n"
14774 " gl_Position.w = x;\n"
14775 "}\n";
14776 char const *fsSource =
14777 "#version 450\n"
14778 "layout(location=0) out vec4 color;\n"
14779 "void main(){\n"
14780 " color = vec4(1);\n"
14781 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014782
14783 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14784 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14785 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14789 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014791 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014792
14793 VkPipelineObj pipe(m_device);
14794 pipe.SetInputAssembly(&iasci);
14795 pipe.SetTessellation(&tsci);
14796 pipe.AddColorAttachment();
14797 pipe.AddShader(&vs);
14798 pipe.AddShader(&tcs);
14799 pipe.AddShader(&tes);
14800 pipe.AddShader(&fs);
14801
14802 VkDescriptorSetObj descriptorSet(m_device);
14803 descriptorSet.AppendDummy();
14804 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14805
14806 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14807
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014808 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014809}
14810
Karl Schultz6addd812016-02-02 17:17:23 -070014811TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014812 TEST_DESCRIPTION(
14813 "Test that an error is produced for a vertex attribute setup where multiple "
14814 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14816 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014817
Chris Forbes280ba2c2015-06-12 11:16:41 +120014818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014820
14821 /* Two binding descriptions for binding 0 */
14822 VkVertexInputBindingDescription input_bindings[2];
14823 memset(input_bindings, 0, sizeof(input_bindings));
14824
14825 VkVertexInputAttributeDescription input_attrib;
14826 memset(&input_attrib, 0, sizeof(input_attrib));
14827 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14828
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014829 char const *vsSource =
14830 "#version 450\n"
14831 "\n"
14832 "layout(location=0) in float x;\n" /* attrib provided float */
14833 "out gl_PerVertex {\n"
14834 " vec4 gl_Position;\n"
14835 "};\n"
14836 "void main(){\n"
14837 " gl_Position = vec4(x);\n"
14838 "}\n";
14839 char const *fsSource =
14840 "#version 450\n"
14841 "\n"
14842 "layout(location=0) out vec4 color;\n"
14843 "void main(){\n"
14844 " color = vec4(1);\n"
14845 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014846
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014849
14850 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014851 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014852 pipe.AddShader(&vs);
14853 pipe.AddShader(&fs);
14854
14855 pipe.AddVertexInputBindings(input_bindings, 2);
14856 pipe.AddVertexInputAttribs(&input_attrib, 1);
14857
Chris Forbes280ba2c2015-06-12 11:16:41 +120014858 VkDescriptorSetObj descriptorSet(m_device);
14859 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014860 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014861
Tony Barbour5781e8f2015-08-04 16:23:11 -060014862 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014863
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014864 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014865}
Chris Forbes8f68b562015-05-25 11:13:32 +120014866
Karl Schultz6addd812016-02-02 17:17:23 -070014867TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014868 TEST_DESCRIPTION(
14869 "Test that an error is produced for a fragment shader which does not "
14870 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014872
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014873 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014874
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014875 char const *vsSource =
14876 "#version 450\n"
14877 "\n"
14878 "out gl_PerVertex {\n"
14879 " vec4 gl_Position;\n"
14880 "};\n"
14881 "void main(){\n"
14882 " gl_Position = vec4(1);\n"
14883 "}\n";
14884 char const *fsSource =
14885 "#version 450\n"
14886 "\n"
14887 "void main(){\n"
14888 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014889
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014892
14893 VkPipelineObj pipe(m_device);
14894 pipe.AddShader(&vs);
14895 pipe.AddShader(&fs);
14896
Chia-I Wu08accc62015-07-07 11:50:03 +080014897 /* set up CB 0, not written */
14898 pipe.AddColorAttachment();
14899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014900
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014901 VkDescriptorSetObj descriptorSet(m_device);
14902 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014903 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014904
Tony Barbour5781e8f2015-08-04 16:23:11 -060014905 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014906
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014907 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014908}
14909
Karl Schultz6addd812016-02-02 17:17:23 -070014910TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014911 TEST_DESCRIPTION(
14912 "Test that a warning is produced for a fragment shader which provides a spurious "
14913 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014915 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014916
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014917 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014918
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014919 char const *vsSource =
14920 "#version 450\n"
14921 "\n"
14922 "out gl_PerVertex {\n"
14923 " vec4 gl_Position;\n"
14924 "};\n"
14925 "void main(){\n"
14926 " gl_Position = vec4(1);\n"
14927 "}\n";
14928 char const *fsSource =
14929 "#version 450\n"
14930 "\n"
14931 "layout(location=0) out vec4 x;\n"
14932 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14933 "void main(){\n"
14934 " x = vec4(1);\n"
14935 " y = vec4(1);\n"
14936 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014937
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014940
14941 VkPipelineObj pipe(m_device);
14942 pipe.AddShader(&vs);
14943 pipe.AddShader(&fs);
14944
Chia-I Wu08accc62015-07-07 11:50:03 +080014945 /* set up CB 0, not written */
14946 pipe.AddColorAttachment();
14947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014948 /* FS writes CB 1, but we don't configure it */
14949
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014950 VkDescriptorSetObj descriptorSet(m_device);
14951 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014953
Tony Barbour5781e8f2015-08-04 16:23:11 -060014954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014956 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014957}
14958
Karl Schultz6addd812016-02-02 17:17:23 -070014959TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014960 TEST_DESCRIPTION(
14961 "Test that an error is produced for a mismatch between the fundamental "
14962 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014964
Chris Forbesa36d69e2015-05-25 11:13:44 +120014965 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014966
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014967 char const *vsSource =
14968 "#version 450\n"
14969 "\n"
14970 "out gl_PerVertex {\n"
14971 " vec4 gl_Position;\n"
14972 "};\n"
14973 "void main(){\n"
14974 " gl_Position = vec4(1);\n"
14975 "}\n";
14976 char const *fsSource =
14977 "#version 450\n"
14978 "\n"
14979 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14980 "void main(){\n"
14981 " x = ivec4(1);\n"
14982 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014983
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014984 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14985 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014986
14987 VkPipelineObj pipe(m_device);
14988 pipe.AddShader(&vs);
14989 pipe.AddShader(&fs);
14990
Chia-I Wu08accc62015-07-07 11:50:03 +080014991 /* set up CB 0; type is UNORM by default */
14992 pipe.AddColorAttachment();
14993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014994
Chris Forbesa36d69e2015-05-25 11:13:44 +120014995 VkDescriptorSetObj descriptorSet(m_device);
14996 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014997 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014998
Tony Barbour5781e8f2015-08-04 16:23:11 -060014999 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015000
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015001 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015002}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015003
Karl Schultz6addd812016-02-02 17:17:23 -070015004TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015005 TEST_DESCRIPTION(
15006 "Test that an error is produced for a shader consuming a uniform "
15007 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015009
Chris Forbes556c76c2015-08-14 12:04:59 +120015010 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015011
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015012 char const *vsSource =
15013 "#version 450\n"
15014 "\n"
15015 "out gl_PerVertex {\n"
15016 " vec4 gl_Position;\n"
15017 "};\n"
15018 "void main(){\n"
15019 " gl_Position = vec4(1);\n"
15020 "}\n";
15021 char const *fsSource =
15022 "#version 450\n"
15023 "\n"
15024 "layout(location=0) out vec4 x;\n"
15025 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15026 "void main(){\n"
15027 " x = vec4(bar.y);\n"
15028 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015029
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015032
Chris Forbes556c76c2015-08-14 12:04:59 +120015033 VkPipelineObj pipe(m_device);
15034 pipe.AddShader(&vs);
15035 pipe.AddShader(&fs);
15036
15037 /* set up CB 0; type is UNORM by default */
15038 pipe.AddColorAttachment();
15039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15040
15041 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015042 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015043
15044 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15045
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015046 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015047}
15048
Chris Forbes5c59e902016-02-26 16:56:09 +130015049TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015050 TEST_DESCRIPTION(
15051 "Test that an error is produced for a shader consuming push constants "
15052 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015054
15055 ASSERT_NO_FATAL_FAILURE(InitState());
15056
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015057 char const *vsSource =
15058 "#version 450\n"
15059 "\n"
15060 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15061 "out gl_PerVertex {\n"
15062 " vec4 gl_Position;\n"
15063 "};\n"
15064 "void main(){\n"
15065 " gl_Position = vec4(consts.x);\n"
15066 "}\n";
15067 char const *fsSource =
15068 "#version 450\n"
15069 "\n"
15070 "layout(location=0) out vec4 x;\n"
15071 "void main(){\n"
15072 " x = vec4(1);\n"
15073 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015074
15075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15077
15078 VkPipelineObj pipe(m_device);
15079 pipe.AddShader(&vs);
15080 pipe.AddShader(&fs);
15081
15082 /* set up CB 0; type is UNORM by default */
15083 pipe.AddColorAttachment();
15084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15085
15086 VkDescriptorSetObj descriptorSet(m_device);
15087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15088
15089 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15090
15091 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015092 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015093}
15094
Chris Forbes3fb17902016-08-22 14:57:55 +120015095TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015096 TEST_DESCRIPTION(
15097 "Test that an error is produced for a shader consuming an input attachment "
15098 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15100 "consumes input attachment index 0 but not provided in subpass");
15101
15102 ASSERT_NO_FATAL_FAILURE(InitState());
15103
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015104 char const *vsSource =
15105 "#version 450\n"
15106 "\n"
15107 "out gl_PerVertex {\n"
15108 " vec4 gl_Position;\n"
15109 "};\n"
15110 "void main(){\n"
15111 " gl_Position = vec4(1);\n"
15112 "}\n";
15113 char const *fsSource =
15114 "#version 450\n"
15115 "\n"
15116 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15117 "layout(location=0) out vec4 color;\n"
15118 "void main() {\n"
15119 " color = subpassLoad(x);\n"
15120 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015121
15122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15124
15125 VkPipelineObj pipe(m_device);
15126 pipe.AddShader(&vs);
15127 pipe.AddShader(&fs);
15128 pipe.AddColorAttachment();
15129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15132 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015133 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015134 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015135 ASSERT_VK_SUCCESS(err);
15136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015138 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015139 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015140 ASSERT_VK_SUCCESS(err);
15141
15142 // error here.
15143 pipe.CreateVKPipeline(pl, renderPass());
15144
15145 m_errorMonitor->VerifyFound();
15146
15147 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15148 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15149}
15150
Chris Forbes5a9a0472016-08-22 16:02:09 +120015151TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015152 TEST_DESCRIPTION(
15153 "Test that an error is produced for a shader consuming an input attachment "
15154 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15156 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15157
15158 ASSERT_NO_FATAL_FAILURE(InitState());
15159
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015160 char const *vsSource =
15161 "#version 450\n"
15162 "\n"
15163 "out gl_PerVertex {\n"
15164 " vec4 gl_Position;\n"
15165 "};\n"
15166 "void main(){\n"
15167 " gl_Position = vec4(1);\n"
15168 "}\n";
15169 char const *fsSource =
15170 "#version 450\n"
15171 "\n"
15172 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15173 "layout(location=0) out vec4 color;\n"
15174 "void main() {\n"
15175 " color = subpassLoad(x);\n"
15176 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015177
15178 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15179 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15180
15181 VkPipelineObj pipe(m_device);
15182 pipe.AddShader(&vs);
15183 pipe.AddShader(&fs);
15184 pipe.AddColorAttachment();
15185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15188 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015189 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015191 ASSERT_VK_SUCCESS(err);
15192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015194 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015196 ASSERT_VK_SUCCESS(err);
15197
15198 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015199 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15200 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15201 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15202 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15203 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 +120015204 };
15205 VkAttachmentReference color = {
15206 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15207 };
15208 VkAttachmentReference input = {
15209 1, VK_IMAGE_LAYOUT_GENERAL,
15210 };
15211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015212 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015214 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015215 VkRenderPass rp;
15216 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15217 ASSERT_VK_SUCCESS(err);
15218
15219 // error here.
15220 pipe.CreateVKPipeline(pl, rp);
15221
15222 m_errorMonitor->VerifyFound();
15223
15224 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15225 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15226 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15227}
15228
Chris Forbes541f7b02016-08-22 15:30:27 +120015229TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015230 TEST_DESCRIPTION(
15231 "Test that an error is produced for a shader consuming an input attachment "
15232 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015234 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015235
15236 ASSERT_NO_FATAL_FAILURE(InitState());
15237
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015238 char const *vsSource =
15239 "#version 450\n"
15240 "\n"
15241 "out gl_PerVertex {\n"
15242 " vec4 gl_Position;\n"
15243 "};\n"
15244 "void main(){\n"
15245 " gl_Position = vec4(1);\n"
15246 "}\n";
15247 char const *fsSource =
15248 "#version 450\n"
15249 "\n"
15250 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15251 "layout(location=0) out vec4 color;\n"
15252 "void main() {\n"
15253 " color = subpassLoad(xs[0]);\n"
15254 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015255
15256 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15257 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15258
15259 VkPipelineObj pipe(m_device);
15260 pipe.AddShader(&vs);
15261 pipe.AddShader(&fs);
15262 pipe.AddColorAttachment();
15263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15266 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015267 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015269 ASSERT_VK_SUCCESS(err);
15270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015272 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015274 ASSERT_VK_SUCCESS(err);
15275
15276 // error here.
15277 pipe.CreateVKPipeline(pl, renderPass());
15278
15279 m_errorMonitor->VerifyFound();
15280
15281 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15282 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15283}
15284
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015285TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015286 TEST_DESCRIPTION(
15287 "Test that an error is produced for a compute pipeline consuming a "
15288 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015290
15291 ASSERT_NO_FATAL_FAILURE(InitState());
15292
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015293 char const *csSource =
15294 "#version 450\n"
15295 "\n"
15296 "layout(local_size_x=1) in;\n"
15297 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15298 "void main(){\n"
15299 " x = vec4(1);\n"
15300 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015301
15302 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15303
15304 VkDescriptorSetObj descriptorSet(m_device);
15305 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015307 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15308 nullptr,
15309 0,
15310 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15311 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15312 descriptorSet.GetPipelineLayout(),
15313 VK_NULL_HANDLE,
15314 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015315
15316 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015317 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015318
15319 m_errorMonitor->VerifyFound();
15320
15321 if (err == VK_SUCCESS) {
15322 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15323 }
15324}
15325
Chris Forbes22a9b092016-07-19 14:34:05 +120015326TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015327 TEST_DESCRIPTION(
15328 "Test that an error is produced for a pipeline consuming a "
15329 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15331 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015332
15333 ASSERT_NO_FATAL_FAILURE(InitState());
15334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015335 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15336 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015337 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015339 ASSERT_VK_SUCCESS(err);
15340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015341 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015342 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015343 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015344 ASSERT_VK_SUCCESS(err);
15345
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015346 char const *csSource =
15347 "#version 450\n"
15348 "\n"
15349 "layout(local_size_x=1) in;\n"
15350 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15351 "void main() {\n"
15352 " x.x = 1.0f;\n"
15353 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015354 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015356 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15357 nullptr,
15358 0,
15359 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15360 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15361 pl,
15362 VK_NULL_HANDLE,
15363 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015364
15365 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015366 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015367
15368 m_errorMonitor->VerifyFound();
15369
15370 if (err == VK_SUCCESS) {
15371 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15372 }
15373
15374 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15375 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15376}
15377
Chris Forbes50020592016-07-27 13:52:41 +120015378TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015379 TEST_DESCRIPTION(
15380 "Test that an error is produced when an image view type "
15381 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 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 +120015384
15385 ASSERT_NO_FATAL_FAILURE(InitState());
15386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15387
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015388 char const *vsSource =
15389 "#version 450\n"
15390 "\n"
15391 "out gl_PerVertex { vec4 gl_Position; };\n"
15392 "void main() { gl_Position = vec4(0); }\n";
15393 char const *fsSource =
15394 "#version 450\n"
15395 "\n"
15396 "layout(set=0, binding=0) uniform sampler3D s;\n"
15397 "layout(location=0) out vec4 color;\n"
15398 "void main() {\n"
15399 " color = texture(s, vec3(0));\n"
15400 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015401 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15402 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15403
15404 VkPipelineObj pipe(m_device);
15405 pipe.AddShader(&vs);
15406 pipe.AddShader(&fs);
15407 pipe.AddColorAttachment();
15408
15409 VkTextureObj texture(m_device, nullptr);
15410 VkSamplerObj sampler(m_device);
15411
15412 VkDescriptorSetObj descriptorSet(m_device);
15413 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15414 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15415
15416 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15417 ASSERT_VK_SUCCESS(err);
15418
Tony Barbour552f6c02016-12-21 14:34:07 -070015419 m_commandBuffer->BeginCommandBuffer();
15420 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015421
15422 m_commandBuffer->BindPipeline(pipe);
15423 m_commandBuffer->BindDescriptorSet(descriptorSet);
15424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015425 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015426 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015427 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015428 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15429
15430 // error produced here.
15431 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15432
15433 m_errorMonitor->VerifyFound();
15434
Tony Barbour552f6c02016-12-21 14:34:07 -070015435 m_commandBuffer->EndRenderPass();
15436 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015437}
15438
Chris Forbes5533bfc2016-07-27 14:12:34 +120015439TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015440 TEST_DESCRIPTION(
15441 "Test that an error is produced when a multisampled images "
15442 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015445
15446 ASSERT_NO_FATAL_FAILURE(InitState());
15447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15448
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015449 char const *vsSource =
15450 "#version 450\n"
15451 "\n"
15452 "out gl_PerVertex { vec4 gl_Position; };\n"
15453 "void main() { gl_Position = vec4(0); }\n";
15454 char const *fsSource =
15455 "#version 450\n"
15456 "\n"
15457 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15458 "layout(location=0) out vec4 color;\n"
15459 "void main() {\n"
15460 " color = texelFetch(s, ivec2(0), 0);\n"
15461 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15464
15465 VkPipelineObj pipe(m_device);
15466 pipe.AddShader(&vs);
15467 pipe.AddShader(&fs);
15468 pipe.AddColorAttachment();
15469
15470 VkTextureObj texture(m_device, nullptr);
15471 VkSamplerObj sampler(m_device);
15472
15473 VkDescriptorSetObj descriptorSet(m_device);
15474 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15475 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15476
15477 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15478 ASSERT_VK_SUCCESS(err);
15479
Tony Barbour552f6c02016-12-21 14:34:07 -070015480 m_commandBuffer->BeginCommandBuffer();
15481 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015482
15483 m_commandBuffer->BindPipeline(pipe);
15484 m_commandBuffer->BindDescriptorSet(descriptorSet);
15485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015487 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015489 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15490
15491 // error produced here.
15492 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15493
15494 m_errorMonitor->VerifyFound();
15495
Tony Barbour552f6c02016-12-21 14:34:07 -070015496 m_commandBuffer->EndRenderPass();
15497 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015498}
15499
Mark Youngc48c4c12016-04-11 14:26:49 -060015500TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015502
15503 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015504
15505 // Create an image
15506 VkImage image;
15507
Karl Schultz6addd812016-02-02 17:17:23 -070015508 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15509 const int32_t tex_width = 32;
15510 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015511
15512 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015513 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15514 image_create_info.pNext = NULL;
15515 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15516 image_create_info.format = tex_format;
15517 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015518 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015519 image_create_info.extent.depth = 1;
15520 image_create_info.mipLevels = 1;
15521 image_create_info.arrayLayers = 1;
15522 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15523 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15524 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15525 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015526
15527 // Introduce error by sending down a bogus width extent
15528 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015529 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015530
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015531 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015532}
15533
Mark Youngc48c4c12016-04-11 14:26:49 -060015534TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015536
15537 ASSERT_NO_FATAL_FAILURE(InitState());
15538
15539 // Create an image
15540 VkImage image;
15541
15542 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15543 const int32_t tex_width = 32;
15544 const int32_t tex_height = 32;
15545
15546 VkImageCreateInfo image_create_info = {};
15547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15548 image_create_info.pNext = NULL;
15549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15550 image_create_info.format = tex_format;
15551 image_create_info.extent.width = tex_width;
15552 image_create_info.extent.height = tex_height;
15553 image_create_info.extent.depth = 1;
15554 image_create_info.mipLevels = 1;
15555 image_create_info.arrayLayers = 1;
15556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15557 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15558 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15559 image_create_info.flags = 0;
15560
15561 // Introduce error by sending down a bogus width extent
15562 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015563 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015564 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15565
15566 m_errorMonitor->VerifyFound();
15567}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015568
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015569TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015570 TEST_DESCRIPTION(
15571 "Create a render pass with an attachment description "
15572 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015573
15574 ASSERT_NO_FATAL_FAILURE(InitState());
15575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15576
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015578
15579 VkAttachmentReference color_attach = {};
15580 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15581 color_attach.attachment = 0;
15582 VkSubpassDescription subpass = {};
15583 subpass.colorAttachmentCount = 1;
15584 subpass.pColorAttachments = &color_attach;
15585
15586 VkRenderPassCreateInfo rpci = {};
15587 rpci.subpassCount = 1;
15588 rpci.pSubpasses = &subpass;
15589 rpci.attachmentCount = 1;
15590 VkAttachmentDescription attach_desc = {};
15591 attach_desc.format = VK_FORMAT_UNDEFINED;
15592 rpci.pAttachments = &attach_desc;
15593 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15594 VkRenderPass rp;
15595 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15596
15597 m_errorMonitor->VerifyFound();
15598
15599 if (result == VK_SUCCESS) {
15600 vkDestroyRenderPass(m_device->device(), rp, NULL);
15601 }
15602}
15603
Karl Schultz6addd812016-02-02 17:17:23 -070015604TEST_F(VkLayerTest, InvalidImageView) {
Tobin Ehliscde08892015-09-22 10:11:37 -060015605 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015606
Mike Stroyana3082432015-09-25 13:39:21 -060015607 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015608 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15609 const int32_t tex_width = 32;
15610 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015611
15612 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015613 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15614 image_create_info.pNext = NULL;
15615 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15616 image_create_info.format = tex_format;
15617 image_create_info.extent.width = tex_width;
15618 image_create_info.extent.height = tex_height;
15619 image_create_info.extent.depth = 1;
15620 image_create_info.mipLevels = 1;
15621 image_create_info.arrayLayers = 1;
15622 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15623 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15624 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15625 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015626
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015627 VkImage image;
15628 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015629 ASSERT_VK_SUCCESS(err);
15630
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015631 VkMemoryRequirements requirements;
15632 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
15633
15634 VkMemoryAllocateInfo alloc_info{};
15635 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15636 alloc_info.pNext = NULL;
15637 alloc_info.memoryTypeIndex = 0;
15638 alloc_info.allocationSize = requirements.size;
15639 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15640 ASSERT_TRUE(pass);
15641
15642 VkDeviceMemory memory;
15643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
15644 ASSERT_VK_SUCCESS(err);
15645
15646 err = vkBindImageMemory(m_device->device(), image, memory, 0);
15647
Tobin Ehliscde08892015-09-22 10:11:37 -060015648 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015649 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015650 image_view_create_info.image = image;
15651 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15652 image_view_create_info.format = tex_format;
15653 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015654 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015655 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015656 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015657
15658 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015660 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015661 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070015662
15663 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060015664 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015665}
Mike Stroyana3082432015-09-25 13:39:21 -060015666
Mark Youngd339ba32016-05-30 13:28:35 -060015667TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15668 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015670 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015671
15672 ASSERT_NO_FATAL_FAILURE(InitState());
15673
15674 // Create an image and try to create a view with no memory backing the image
15675 VkImage image;
15676
15677 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15678 const int32_t tex_width = 32;
15679 const int32_t tex_height = 32;
15680
15681 VkImageCreateInfo image_create_info = {};
15682 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15683 image_create_info.pNext = NULL;
15684 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15685 image_create_info.format = tex_format;
15686 image_create_info.extent.width = tex_width;
15687 image_create_info.extent.height = tex_height;
15688 image_create_info.extent.depth = 1;
15689 image_create_info.mipLevels = 1;
15690 image_create_info.arrayLayers = 1;
15691 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15692 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15693 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15694 image_create_info.flags = 0;
15695
15696 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15697 ASSERT_VK_SUCCESS(err);
15698
15699 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015700 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015701 image_view_create_info.image = image;
15702 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15703 image_view_create_info.format = tex_format;
15704 image_view_create_info.subresourceRange.layerCount = 1;
15705 image_view_create_info.subresourceRange.baseMipLevel = 0;
15706 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015707 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015708
15709 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015710 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015711
15712 m_errorMonitor->VerifyFound();
15713 vkDestroyImage(m_device->device(), image, NULL);
15714 // If last error is success, it still created the view, so delete it.
15715 if (err == VK_SUCCESS) {
15716 vkDestroyImageView(m_device->device(), view, NULL);
15717 }
Mark Youngd339ba32016-05-30 13:28:35 -060015718}
15719
Karl Schultz6addd812016-02-02 17:17:23 -070015720TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015721 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015723
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015724 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015725
Karl Schultz6addd812016-02-02 17:17:23 -070015726 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015727 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015728 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015729 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015730
15731 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015732 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015733 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015734 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15735 image_view_create_info.format = tex_format;
15736 image_view_create_info.subresourceRange.baseMipLevel = 0;
15737 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015738 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015739 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015740 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015741
15742 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015743 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015744
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015745 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015746}
15747
Mike Weiblena1e13f42017-02-09 21:25:59 -070015748TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15749 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15750
15751 ASSERT_NO_FATAL_FAILURE(InitState());
15752 VkSubresourceLayout subres_layout = {};
15753
15754 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15755 {
15756 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15757 VkImageObj img(m_device);
15758 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15759 ASSERT_TRUE(img.initialized());
15760
15761 VkImageSubresource subres = {};
15762 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15763 subres.mipLevel = 0;
15764 subres.arrayLayer = 0;
15765
15766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15767 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15768 m_errorMonitor->VerifyFound();
15769 }
15770
15771 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15772 {
15773 VkImageObj img(m_device);
15774 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15775 ASSERT_TRUE(img.initialized());
15776
15777 VkImageSubresource subres = {};
15778 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15779 subres.mipLevel = 0;
15780 subres.arrayLayer = 0;
15781
15782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15784 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15785 m_errorMonitor->VerifyFound();
15786 }
15787
15788 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15789 {
15790 VkImageObj img(m_device);
15791 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15792 ASSERT_TRUE(img.initialized());
15793
15794 VkImageSubresource subres = {};
15795 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15796 subres.mipLevel = 1; // ERROR: triggers VU 00739
15797 subres.arrayLayer = 0;
15798
15799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15800 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15801 m_errorMonitor->VerifyFound();
15802 }
15803
15804 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15805 {
15806 VkImageObj img(m_device);
15807 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15808 ASSERT_TRUE(img.initialized());
15809
15810 VkImageSubresource subres = {};
15811 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15812 subres.mipLevel = 0;
15813 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15814
15815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15816 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15817 m_errorMonitor->VerifyFound();
15818 }
15819}
15820
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015821TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015822 VkResult err;
15823 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015824
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015826
Mike Stroyana3082432015-09-25 13:39:21 -060015827 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015828
15829 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015830 VkImage srcImage;
15831 VkImage dstImage;
15832 VkDeviceMemory srcMem;
15833 VkDeviceMemory destMem;
15834 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015835
15836 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015837 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15838 image_create_info.pNext = NULL;
15839 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15840 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15841 image_create_info.extent.width = 32;
15842 image_create_info.extent.height = 32;
15843 image_create_info.extent.depth = 1;
15844 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015845 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015846 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15847 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15849 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015851 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015852 ASSERT_VK_SUCCESS(err);
15853
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015854 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015856 ASSERT_VK_SUCCESS(err);
15857
15858 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015859 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015860 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15861 memAlloc.pNext = NULL;
15862 memAlloc.allocationSize = 0;
15863 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015864
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015865 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015866 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015867 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015868 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015869 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015870 ASSERT_VK_SUCCESS(err);
15871
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015872 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015873 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015874 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015875 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015876 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015877 ASSERT_VK_SUCCESS(err);
15878
15879 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15880 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015881 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015882 ASSERT_VK_SUCCESS(err);
15883
Tony Barbour552f6c02016-12-21 14:34:07 -070015884 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015885 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015886 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015887 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015888 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015889 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015890 copyRegion.srcOffset.x = 0;
15891 copyRegion.srcOffset.y = 0;
15892 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015893 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015894 copyRegion.dstSubresource.mipLevel = 0;
15895 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015896 // Introduce failure by forcing the dst layerCount to differ from src
15897 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015898 copyRegion.dstOffset.x = 0;
15899 copyRegion.dstOffset.y = 0;
15900 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015901 copyRegion.extent.width = 1;
15902 copyRegion.extent.height = 1;
15903 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015904 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015905 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015906
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015907 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015908
Chia-I Wuf7458c52015-10-26 21:10:41 +080015909 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015910 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015911 vkFreeMemory(m_device->device(), srcMem, NULL);
15912 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015913}
15914
Tony Barbourd6673642016-05-05 14:46:39 -060015915TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015916 TEST_DESCRIPTION("Creating images with unsuported formats ");
15917
15918 ASSERT_NO_FATAL_FAILURE(InitState());
15919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060015920
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015921 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015922 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015923 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015924 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15925 image_create_info.format = VK_FORMAT_UNDEFINED;
15926 image_create_info.extent.width = 32;
15927 image_create_info.extent.height = 32;
15928 image_create_info.extent.depth = 1;
15929 image_create_info.mipLevels = 1;
15930 image_create_info.arrayLayers = 1;
15931 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15932 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15933 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15936 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015937
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015938 VkImage image;
15939 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015940 m_errorMonitor->VerifyFound();
15941
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015942 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015943 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060015944 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15945 VkFormat format = static_cast<VkFormat>(f);
15946 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015947 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015948 unsupported = format;
15949 break;
15950 }
15951 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015952
Tony Barbourd6673642016-05-05 14:46:39 -060015953 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015954 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015956
Jeremy Hayes96dcd812017-03-14 14:04:19 -060015957 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060015958 m_errorMonitor->VerifyFound();
15959 }
15960}
15961
15962TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015963 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15964
15965 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015966 auto depth_format = find_depth_stencil_format(m_device);
15967 if (!depth_format) {
15968 return;
15969 }
Tony Barbourd6673642016-05-05 14:46:39 -060015970
15971 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015972 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 -060015973 VK_IMAGE_TILING_OPTIMAL, 0);
15974 ASSERT_TRUE(image.initialized());
15975
15976 VkImageView imgView;
15977 VkImageViewCreateInfo imgViewInfo = {};
15978 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15979 imgViewInfo.image = image.handle();
15980 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15981 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15982 imgViewInfo.subresourceRange.layerCount = 1;
15983 imgViewInfo.subresourceRange.baseMipLevel = 0;
15984 imgViewInfo.subresourceRange.levelCount = 1;
15985 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15986
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015987 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060015988 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015990 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15991 m_errorMonitor->VerifyFound();
15992 imgViewInfo.subresourceRange.baseMipLevel = 0;
15993
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015994 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060015995 imgViewInfo.subresourceRange.baseArrayLayer = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060015996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015997 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15998 m_errorMonitor->VerifyFound();
15999 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16000
Tony Barbourd6673642016-05-05 14:46:39 -060016001 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16002 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016004 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16005 m_errorMonitor->VerifyFound();
16006 imgViewInfo.subresourceRange.levelCount = 1;
16007
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016008 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16009 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016010 m_errorMonitor->SetDesiredFailureMsg(
16011 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16012 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016013 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16014 m_errorMonitor->VerifyFound();
16015 imgViewInfo.subresourceRange.layerCount = 1;
16016
Tony Barbourd6673642016-05-05 14:46:39 -060016017 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016018 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016019 m_errorMonitor->SetDesiredFailureMsg(
16020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16021 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016022 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16023 m_errorMonitor->VerifyFound();
16024 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16025
Tony Barbourd6673642016-05-05 14:46:39 -060016026 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16027 // VIEW_CREATE_ERROR
16028 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016030 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16031 m_errorMonitor->VerifyFound();
16032 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16033
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016034 // TODO: Update framework to easily passing mutable flag into ImageObj init
16035 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016036 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16037 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16038 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016039 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16040 // VIEW_CREATE_ERROR
16041 VkImageCreateInfo mutImgInfo = image.create_info();
16042 VkImage mutImage;
16043 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016045 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16046 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016047 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016048 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016049
16050 VkMemoryRequirements requirements;
16051 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16052
16053 VkMemoryAllocateInfo alloc_info{};
16054 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16055 alloc_info.pNext = NULL;
16056 alloc_info.memoryTypeIndex = 0;
16057 alloc_info.allocationSize = requirements.size;
16058 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16059 ASSERT_TRUE(pass);
16060
16061 VkDeviceMemory memory;
16062 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16063 ASSERT_VK_SUCCESS(ret);
16064
16065 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16066 ASSERT_VK_SUCCESS(ret);
16067
Tony Barbourd6673642016-05-05 14:46:39 -060016068 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016070 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16071 m_errorMonitor->VerifyFound();
16072 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016073
16074 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016075 vkDestroyImage(m_device->handle(), mutImage, NULL);
16076}
16077
Dave Houlton75967fc2017-03-06 17:21:16 -070016078TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16079 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16080
16081 ASSERT_NO_FATAL_FAILURE(InitState());
16082
Jamie Madill35127872017-03-15 16:17:46 -040016083 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016084 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16085 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16086 if (device_features.textureCompressionBC) {
16087 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16088 } else if (device_features.textureCompressionETC2) {
16089 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16090 } else if (device_features.textureCompressionASTC_LDR) {
16091 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16092 } else {
16093 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16094 return;
16095 }
16096
16097 VkImageCreateInfo ci;
16098 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16099 ci.pNext = NULL;
16100 ci.flags = 0;
16101 ci.imageType = VK_IMAGE_TYPE_2D;
16102 ci.format = compressed_format;
16103 ci.extent = {32, 32, 1};
16104 ci.mipLevels = 6;
16105 ci.arrayLayers = 1;
16106 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16107 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16108 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16109 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16110 ci.queueFamilyIndexCount = 0;
16111 ci.pQueueFamilyIndices = NULL;
16112 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16113
16114 VkImageObj image(m_device);
16115 image.init(&ci);
16116 ASSERT_TRUE(image.initialized());
16117
16118 VkImageObj odd_image(m_device);
16119 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16120 odd_image.init(&ci);
16121 ASSERT_TRUE(odd_image.initialized());
16122
16123 // Allocate buffers
16124 VkMemoryPropertyFlags reqs = 0;
16125 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16126 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16127 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16128 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16129 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16130
16131 VkBufferImageCopy region = {};
16132 region.bufferRowLength = 0;
16133 region.bufferImageHeight = 0;
16134 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16135 region.imageSubresource.layerCount = 1;
16136 region.imageOffset = {0, 0, 0};
16137 region.bufferOffset = 0;
16138
16139 // start recording
16140 m_commandBuffer->BeginCommandBuffer();
16141
16142 // Mip level copies that work - 5 levels
16143 m_errorMonitor->ExpectSuccess();
16144
16145 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16146 region.imageExtent = {32, 32, 1};
16147 region.imageSubresource.mipLevel = 0;
16148 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16149 &region);
16150 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16151 &region);
16152
16153 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16154 region.imageExtent = {8, 8, 1};
16155 region.imageSubresource.mipLevel = 2;
16156 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16157 &region);
16158 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16159 &region);
16160
16161 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16162 region.imageExtent = {4, 4, 1};
16163 region.imageSubresource.mipLevel = 3;
16164 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16165 &region);
16166 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16167 &region);
16168
16169 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16170 region.imageExtent = {2, 2, 1};
16171 region.imageSubresource.mipLevel = 4;
16172 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16173 &region);
16174 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16175 &region);
16176
16177 region.imageExtent = {1, 1, 1};
16178 region.imageSubresource.mipLevel = 5;
16179 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16180 &region);
16181 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16182 &region);
16183 m_errorMonitor->VerifyNotFound();
16184
16185 // Buffer must accomodate a full compressed block, regardless of texel count
16186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16187 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16188 &region);
16189 m_errorMonitor->VerifyFound();
16190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16191 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16192 &region);
16193 m_errorMonitor->VerifyFound();
16194
16195 // Copy width < compressed block size, but not the full mip width
16196 region.imageExtent = {1, 2, 1};
16197 region.imageSubresource.mipLevel = 4;
16198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16199 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16200 &region);
16201 m_errorMonitor->VerifyFound();
16202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16203 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16204 &region);
16205 m_errorMonitor->VerifyFound();
16206
16207 // Copy height < compressed block size but not the full mip height
16208 region.imageExtent = {2, 1, 1};
16209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16210 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16211 &region);
16212 m_errorMonitor->VerifyFound();
16213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16214 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16215 &region);
16216 m_errorMonitor->VerifyFound();
16217
16218 // Offsets must be multiple of compressed block size
16219 region.imageOffset = {1, 1, 0};
16220 region.imageExtent = {1, 1, 1};
16221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16222 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16223 &region);
16224 m_errorMonitor->VerifyFound();
16225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16226 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16227 &region);
16228 m_errorMonitor->VerifyFound();
16229
16230 // Offset + extent width = mip width - should succeed
16231 region.imageOffset = {4, 4, 0};
16232 region.imageExtent = {3, 4, 1};
16233 region.imageSubresource.mipLevel = 2;
16234 m_errorMonitor->ExpectSuccess();
16235 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16236 &region);
16237 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16238 &region);
16239 m_errorMonitor->VerifyNotFound();
16240
16241 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16242 region.imageExtent = {4, 4, 1};
16243 m_errorMonitor->ExpectSuccess();
16244 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16245 &region);
16246 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16247 &region);
16248 m_errorMonitor->VerifyNotFound();
16249
16250 // Offset + extent width < mip width and not a multiple of block width - should fail
16251 region.imageExtent = {3, 3, 1};
16252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16253 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16254 &region);
16255 m_errorMonitor->VerifyFound();
16256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16257 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16258 &region);
16259 m_errorMonitor->VerifyFound();
16260}
16261
Dave Houlton59a20702017-02-02 17:26:23 -070016262TEST_F(VkLayerTest, ImageBufferCopyTests) {
16263 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16264
16265 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016266 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16267 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16268 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16269 return;
16270 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016271
16272 // Bail if any dimension of transfer granularity is 0.
16273 auto index = m_device->graphics_queue_node_index_;
16274 auto queue_family_properties = m_device->phy().queue_properties();
16275 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16276 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16277 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16278 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16279 return;
16280 }
16281
Dave Houlton59a20702017-02-02 17:26:23 -070016282 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16283 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16284 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016285 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16286 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16287 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16288 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16289
Dave Houlton59a20702017-02-02 17:26:23 -070016290 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16291 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16292 VK_IMAGE_TILING_OPTIMAL, 0);
16293 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16294 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16295 VK_IMAGE_TILING_OPTIMAL, 0);
16296 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16297 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016298 ASSERT_TRUE(image_64k.initialized());
16299 ASSERT_TRUE(image_16k.initialized());
16300 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016301
Dave Houltonf3229d52017-02-21 15:59:08 -070016302 // Verify all needed Depth/Stencil formats are supported
16303 bool missing_ds_support = false;
16304 VkFormatProperties props = {0, 0, 0};
16305 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16306 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16307 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16308 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16309 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16310 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16311 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16312 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16313
16314 if (!missing_ds_support) {
16315 ds_image_4D_1S.init(
16316 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16317 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16318 VK_IMAGE_TILING_OPTIMAL, 0);
16319 ASSERT_TRUE(ds_image_4D_1S.initialized());
16320
16321 ds_image_3D_1S.init(
16322 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16323 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16324 VK_IMAGE_TILING_OPTIMAL, 0);
16325 ASSERT_TRUE(ds_image_3D_1S.initialized());
16326
16327 ds_image_2D.init(
16328 256, 256, VK_FORMAT_D16_UNORM,
16329 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16330 VK_IMAGE_TILING_OPTIMAL, 0);
16331 ASSERT_TRUE(ds_image_2D.initialized());
16332
16333 ds_image_1S.init(
16334 256, 256, VK_FORMAT_S8_UINT,
16335 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16336 VK_IMAGE_TILING_OPTIMAL, 0);
16337 ASSERT_TRUE(ds_image_1S.initialized());
16338 }
16339
16340 // Allocate buffers
16341 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016342 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016343 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16344 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16345 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16346 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016347
16348 VkBufferImageCopy region = {};
16349 region.bufferRowLength = 0;
16350 region.bufferImageHeight = 0;
16351 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16352 region.imageSubresource.layerCount = 1;
16353 region.imageOffset = {0, 0, 0};
16354 region.imageExtent = {64, 64, 1};
16355 region.bufferOffset = 0;
16356
16357 // attempt copies before putting command buffer in recording state
16358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16359 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16360 &region);
16361 m_errorMonitor->VerifyFound();
16362
16363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16365 &region);
16366 m_errorMonitor->VerifyFound();
16367
16368 // start recording
16369 m_commandBuffer->BeginCommandBuffer();
16370
16371 // successful copies
16372 m_errorMonitor->ExpectSuccess();
16373 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16374 &region);
16375 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16376 &region);
16377 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16378 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16379 &region);
16380 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16381 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16382 &region);
16383 region.imageOffset.x = 0;
16384 region.imageExtent.height = 64;
16385 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16386 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16387 &region);
16388 m_errorMonitor->VerifyNotFound();
16389
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016390 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016391 region.imageExtent = {65, 64, 1};
16392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16393 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16394 &region);
16395 m_errorMonitor->VerifyFound();
16396
16397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16398 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16399 &region);
16400 m_errorMonitor->VerifyFound();
16401
16402 // image/buffer too small (offset) on copy to image
16403 region.imageExtent = {64, 64, 1};
16404 region.imageOffset = {0, 4, 0};
16405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16406 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16407 &region);
16408 m_errorMonitor->VerifyFound();
16409
16410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16411 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16412 &region);
16413 m_errorMonitor->VerifyFound();
16414
16415 // image/buffer too small on copy to buffer
16416 region.imageExtent = {64, 64, 1};
16417 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016418 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16420 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16421 &region);
16422 m_errorMonitor->VerifyFound();
16423
16424 region.imageExtent = {64, 65, 1};
16425 region.bufferOffset = 0;
16426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16427 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16428 &region);
16429 m_errorMonitor->VerifyFound();
16430
16431 // buffer size ok but rowlength causes loose packing
16432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16433 region.imageExtent = {64, 64, 1};
16434 region.bufferRowLength = 68;
16435 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16436 &region);
16437 m_errorMonitor->VerifyFound();
16438
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016439 // An extent with zero area should produce a warning, but no error
16440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16441 region.imageExtent.width = 0;
16442 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16443 &region);
16444 m_errorMonitor->VerifyFound();
16445
Dave Houlton59a20702017-02-02 17:26:23 -070016446 // aspect bits
16447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16448 region.imageExtent = {64, 64, 1};
16449 region.bufferRowLength = 0;
16450 region.bufferImageHeight = 0;
16451 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16452 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16453 buffer_16k.handle(), 1, &region);
16454 m_errorMonitor->VerifyFound();
16455
16456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16457 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16458 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16459 &region);
16460 m_errorMonitor->VerifyFound();
16461
16462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16463 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16464 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16465 buffer_16k.handle(), 1, &region);
16466 m_errorMonitor->VerifyFound();
16467
Dave Houltonf3229d52017-02-21 15:59:08 -070016468 // Test Depth/Stencil copies
16469 if (missing_ds_support) {
16470 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16471 } else {
16472 VkBufferImageCopy ds_region = {};
16473 ds_region.bufferOffset = 0;
16474 ds_region.bufferRowLength = 0;
16475 ds_region.bufferImageHeight = 0;
16476 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16477 ds_region.imageSubresource.mipLevel = 0;
16478 ds_region.imageSubresource.baseArrayLayer = 0;
16479 ds_region.imageSubresource.layerCount = 1;
16480 ds_region.imageOffset = {0, 0, 0};
16481 ds_region.imageExtent = {256, 256, 1};
16482
16483 // Depth copies that should succeed
16484 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16485 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16486 buffer_256k.handle(), 1, &ds_region);
16487 m_errorMonitor->VerifyNotFound();
16488
16489 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16490 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16491 buffer_256k.handle(), 1, &ds_region);
16492 m_errorMonitor->VerifyNotFound();
16493
16494 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16495 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16496 buffer_128k.handle(), 1, &ds_region);
16497 m_errorMonitor->VerifyNotFound();
16498
16499 // Depth copies that should fail
16500 ds_region.bufferOffset = 4;
16501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16502 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16503 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16504 buffer_256k.handle(), 1, &ds_region);
16505 m_errorMonitor->VerifyFound();
16506
16507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16508 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16509 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16510 buffer_256k.handle(), 1, &ds_region);
16511 m_errorMonitor->VerifyFound();
16512
16513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16514 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16515 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16516 buffer_128k.handle(), 1, &ds_region);
16517 m_errorMonitor->VerifyFound();
16518
16519 // Stencil copies that should succeed
16520 ds_region.bufferOffset = 0;
16521 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16522 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16523 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16524 buffer_64k.handle(), 1, &ds_region);
16525 m_errorMonitor->VerifyNotFound();
16526
16527 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16528 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16529 buffer_64k.handle(), 1, &ds_region);
16530 m_errorMonitor->VerifyNotFound();
16531
16532 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16533 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16534 buffer_64k.handle(), 1, &ds_region);
16535 m_errorMonitor->VerifyNotFound();
16536
16537 // Stencil copies that should fail
16538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16539 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16540 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16541 buffer_16k.handle(), 1, &ds_region);
16542 m_errorMonitor->VerifyFound();
16543
16544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16545 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16546 ds_region.bufferRowLength = 260;
16547 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16548 buffer_64k.handle(), 1, &ds_region);
16549 m_errorMonitor->VerifyFound();
16550
16551 ds_region.bufferRowLength = 0;
16552 ds_region.bufferOffset = 4;
16553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16554 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16555 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16556 buffer_64k.handle(), 1, &ds_region);
16557 m_errorMonitor->VerifyFound();
16558 }
16559
Dave Houlton584d51e2017-02-16 12:52:54 -070016560 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040016561 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070016562 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016563 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16564 device_features.textureCompressionASTC_LDR)) {
16565 printf(" No compressed formats supported - block compression tests skipped.\n");
16566 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016567 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16568 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016569 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016570 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 -070016571 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16572 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016573 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016574 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 -070016575 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016576 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16577 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016578 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016579 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16580 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016581 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16582 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016583 }
16584 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016585
Dave Houlton584d51e2017-02-16 12:52:54 -070016586 // Just fits
16587 m_errorMonitor->ExpectSuccess();
16588 region.imageExtent = {128, 128, 1};
16589 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16590 buffer_16k.handle(), 1, &region);
16591 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016592
Dave Houlton584d51e2017-02-16 12:52:54 -070016593 // with offset, too big for buffer
16594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16595 region.bufferOffset = 16;
16596 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16597 buffer_16k.handle(), 1, &region);
16598 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016599 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016600
Dave Houlton67e9b532017-03-02 17:00:10 -070016601 // extents that are not a multiple of compressed block size
16602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16603 region.imageExtent.width = 66;
16604 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16605 buffer_16k.handle(), 1, &region);
16606 m_errorMonitor->VerifyFound();
16607 region.imageExtent.width = 128;
16608
16609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016610 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016611 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16612 buffer_16k.handle(), 1, &region);
16613 m_errorMonitor->VerifyFound();
16614 region.imageExtent.height = 128;
16615
16616 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16617
16618 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16619 m_errorMonitor->ExpectSuccess();
16620 region.imageExtent.width = 66;
16621 region.imageOffset.x = 64;
16622 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16623 buffer_16k.handle(), 1, &region);
16624 region.imageExtent.width = 16;
16625 region.imageOffset.x = 0;
16626 region.imageExtent.height = 2;
16627 region.imageOffset.y = 128;
16628 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016629 buffer_16k.handle(), 1, &region);
16630 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016631 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016632
Dave Houlton584d51e2017-02-16 12:52:54 -070016633 // buffer offset must be a multiple of texel block size (16)
16634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16636 region.imageExtent = {64, 64, 1};
16637 region.bufferOffset = 24;
16638 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16639 buffer_16k.handle(), 1, &region);
16640 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016641
Dave Houlton584d51e2017-02-16 12:52:54 -070016642 // rowlength not a multiple of block width (4)
16643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16644 region.bufferOffset = 0;
16645 region.bufferRowLength = 130;
16646 region.bufferImageHeight = 0;
16647 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16648 buffer_64k.handle(), 1, &region);
16649 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016650
Dave Houlton584d51e2017-02-16 12:52:54 -070016651 // imageheight not a multiple of block height (4)
16652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16653 region.bufferRowLength = 0;
16654 region.bufferImageHeight = 130;
16655 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16656 buffer_64k.handle(), 1, &region);
16657 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016658 }
Dave Houlton59a20702017-02-02 17:26:23 -070016659}
16660
Tony Barbourd6673642016-05-05 14:46:39 -060016661TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016662 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016663
16664 ASSERT_NO_FATAL_FAILURE(InitState());
16665
Rene Lindsay135204f2016-12-22 17:11:09 -070016666 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016667 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016668 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 -070016669 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016670 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016671 vk_testing::Buffer buffer;
16672 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016673 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016674 VkBufferImageCopy region = {};
16675 region.bufferRowLength = 128;
16676 region.bufferImageHeight = 128;
16677 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16678 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016679 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016680 region.imageExtent.height = 4;
16681 region.imageExtent.width = 4;
16682 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016683
16684 VkImageObj image2(m_device);
16685 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 -070016686 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016687 ASSERT_TRUE(image2.initialized());
16688 vk_testing::Buffer buffer2;
16689 VkMemoryPropertyFlags reqs2 = 0;
16690 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16691 VkBufferImageCopy region2 = {};
16692 region2.bufferRowLength = 128;
16693 region2.bufferImageHeight = 128;
16694 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16695 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16696 region2.imageSubresource.layerCount = 1;
16697 region2.imageExtent.height = 4;
16698 region2.imageExtent.width = 4;
16699 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016700 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016701
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016702 // Image must have offset.z of 0 and extent.depth of 1
16703 // Introduce failure by setting imageExtent.depth to 0
16704 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016706 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016707 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016708 m_errorMonitor->VerifyFound();
16709
16710 region.imageExtent.depth = 1;
16711
16712 // Image must have offset.z of 0 and extent.depth of 1
16713 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016714 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016715 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016718 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016719 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016720 m_errorMonitor->VerifyFound();
16721
16722 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016723 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16724 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016725 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016727 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16728 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016729 m_errorMonitor->VerifyFound();
16730
16731 // BufferOffset must be a multiple of 4
16732 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016733 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016735 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16736 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016737 m_errorMonitor->VerifyFound();
16738
16739 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16740 region.bufferOffset = 0;
16741 region.imageExtent.height = 128;
16742 region.imageExtent.width = 128;
16743 // Introduce failure by setting bufferRowLength > 0 but less than width
16744 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016746 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16747 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016748 m_errorMonitor->VerifyFound();
16749
16750 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16751 region.bufferRowLength = 128;
16752 // Introduce failure by setting bufferRowHeight > 0 but less than height
16753 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016755 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16756 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016757 m_errorMonitor->VerifyFound();
16758
16759 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016760 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016761 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16762 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016763 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016764 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16765 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016766 VkImageBlit blitRegion = {};
16767 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16768 blitRegion.srcSubresource.baseArrayLayer = 0;
16769 blitRegion.srcSubresource.layerCount = 1;
16770 blitRegion.srcSubresource.mipLevel = 0;
16771 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16772 blitRegion.dstSubresource.baseArrayLayer = 0;
16773 blitRegion.dstSubresource.layerCount = 1;
16774 blitRegion.dstSubresource.mipLevel = 0;
16775
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016776 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060016777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
16778 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
16779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
16780 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016781 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16782 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016783 m_errorMonitor->VerifyFound();
16784
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016786 VkImageMemoryBarrier img_barrier;
16787 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16788 img_barrier.pNext = NULL;
16789 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16790 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16791 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16792 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16793 img_barrier.image = image.handle();
16794 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16795 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16796 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16797 img_barrier.subresourceRange.baseArrayLayer = 0;
16798 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016799 img_barrier.subresourceRange.layerCount = 0;
16800 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016801 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16802 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016803 m_errorMonitor->VerifyFound();
16804 img_barrier.subresourceRange.layerCount = 1;
16805}
16806
16807TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016808 TEST_DESCRIPTION("Exceed the limits of image format ");
16809
Cody Northropc31a84f2016-08-22 10:41:47 -060016810 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016812 VkImageCreateInfo image_create_info = {};
16813 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16814 image_create_info.pNext = NULL;
16815 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16816 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16817 image_create_info.extent.width = 32;
16818 image_create_info.extent.height = 32;
16819 image_create_info.extent.depth = 1;
16820 image_create_info.mipLevels = 1;
16821 image_create_info.arrayLayers = 1;
16822 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16823 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16824 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16825 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16826 image_create_info.flags = 0;
16827
16828 VkImage nullImg;
16829 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016830 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16831 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016832 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016833 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16834 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16835 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016836 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016837
Tony Barbour0907e362017-03-09 15:05:30 -070016838 uint32_t maxDim =
16839 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16840 // If max mip levels exceeds image extents, skip the max mip levels test
16841 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16843 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16844 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16845 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16846 m_errorMonitor->VerifyFound();
16847 image_create_info.mipLevels = 1;
16848 }
Tony Barbourd6673642016-05-05 14:46:39 -060016849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016851 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16852 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16853 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16854 m_errorMonitor->VerifyFound();
16855 image_create_info.arrayLayers = 1;
16856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016858 int samples = imgFmtProps.sampleCounts >> 1;
16859 image_create_info.samples = (VkSampleCountFlagBits)samples;
16860 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16861 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16862 m_errorMonitor->VerifyFound();
16863 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16864
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16866 "pCreateInfo->initialLayout, must be "
16867 "VK_IMAGE_LAYOUT_UNDEFINED or "
16868 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016869 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16870 // Expect INVALID_LAYOUT
16871 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16872 m_errorMonitor->VerifyFound();
16873 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16874}
16875
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016876TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016877 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016879
16880 ASSERT_NO_FATAL_FAILURE(InitState());
16881
16882 VkImageObj src_image(m_device);
16883 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16884 VkImageObj dst_image(m_device);
16885 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16886
Tony Barbour552f6c02016-12-21 14:34:07 -070016887 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016888 VkImageCopy copy_region;
16889 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16890 copy_region.srcSubresource.mipLevel = 0;
16891 copy_region.srcSubresource.baseArrayLayer = 0;
16892 copy_region.srcSubresource.layerCount = 0;
16893 copy_region.srcOffset.x = 0;
16894 copy_region.srcOffset.y = 0;
16895 copy_region.srcOffset.z = 0;
16896 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16897 copy_region.dstSubresource.mipLevel = 0;
16898 copy_region.dstSubresource.baseArrayLayer = 0;
16899 copy_region.dstSubresource.layerCount = 0;
16900 copy_region.dstOffset.x = 0;
16901 copy_region.dstOffset.y = 0;
16902 copy_region.dstOffset.z = 0;
16903 copy_region.extent.width = 64;
16904 copy_region.extent.height = 64;
16905 copy_region.extent.depth = 1;
16906 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16907 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016908 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016909
16910 m_errorMonitor->VerifyFound();
16911}
16912
16913TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016914 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016916
16917 ASSERT_NO_FATAL_FAILURE(InitState());
16918
16919 VkImageObj src_image(m_device);
16920 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16921 VkImageObj dst_image(m_device);
16922 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16923
Tony Barbour552f6c02016-12-21 14:34:07 -070016924 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016925 VkImageCopy copy_region;
16926 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16927 copy_region.srcSubresource.mipLevel = 0;
16928 copy_region.srcSubresource.baseArrayLayer = 0;
16929 copy_region.srcSubresource.layerCount = 0;
16930 copy_region.srcOffset.x = 0;
16931 copy_region.srcOffset.y = 0;
16932 copy_region.srcOffset.z = 0;
16933 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16934 copy_region.dstSubresource.mipLevel = 0;
16935 copy_region.dstSubresource.baseArrayLayer = 0;
16936 copy_region.dstSubresource.layerCount = 0;
16937 copy_region.dstOffset.x = 0;
16938 copy_region.dstOffset.y = 0;
16939 copy_region.dstOffset.z = 0;
16940 copy_region.extent.width = 64;
16941 copy_region.extent.height = 64;
16942 copy_region.extent.depth = 1;
16943 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16944 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016945 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016946
16947 m_errorMonitor->VerifyFound();
16948}
16949
Karl Schultz6addd812016-02-02 17:17:23 -070016950TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016951 VkResult err;
16952 bool pass;
16953
16954 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016956
16957 ASSERT_NO_FATAL_FAILURE(InitState());
16958
16959 // Create two images of different types and try to copy between them
16960 VkImage srcImage;
16961 VkImage dstImage;
16962 VkDeviceMemory srcMem;
16963 VkDeviceMemory destMem;
16964 VkMemoryRequirements memReqs;
16965
16966 VkImageCreateInfo image_create_info = {};
16967 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16968 image_create_info.pNext = NULL;
16969 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16970 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16971 image_create_info.extent.width = 32;
16972 image_create_info.extent.height = 32;
16973 image_create_info.extent.depth = 1;
16974 image_create_info.mipLevels = 1;
16975 image_create_info.arrayLayers = 1;
16976 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16977 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16978 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16979 image_create_info.flags = 0;
16980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016981 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016982 ASSERT_VK_SUCCESS(err);
16983
16984 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16985 // Introduce failure by creating second image with a different-sized format.
16986 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016988 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016989 ASSERT_VK_SUCCESS(err);
16990
16991 // Allocate memory
16992 VkMemoryAllocateInfo memAlloc = {};
16993 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16994 memAlloc.pNext = NULL;
16995 memAlloc.allocationSize = 0;
16996 memAlloc.memoryTypeIndex = 0;
16997
16998 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16999 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017000 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017001 ASSERT_TRUE(pass);
17002 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
17003 ASSERT_VK_SUCCESS(err);
17004
17005 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
17006 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017007 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017008 ASSERT_TRUE(pass);
17009 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
17010 ASSERT_VK_SUCCESS(err);
17011
17012 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17013 ASSERT_VK_SUCCESS(err);
17014 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
17015 ASSERT_VK_SUCCESS(err);
17016
Tony Barbour552f6c02016-12-21 14:34:07 -070017017 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017018 VkImageCopy copyRegion;
17019 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17020 copyRegion.srcSubresource.mipLevel = 0;
17021 copyRegion.srcSubresource.baseArrayLayer = 0;
17022 copyRegion.srcSubresource.layerCount = 0;
17023 copyRegion.srcOffset.x = 0;
17024 copyRegion.srcOffset.y = 0;
17025 copyRegion.srcOffset.z = 0;
17026 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17027 copyRegion.dstSubresource.mipLevel = 0;
17028 copyRegion.dstSubresource.baseArrayLayer = 0;
17029 copyRegion.dstSubresource.layerCount = 0;
17030 copyRegion.dstOffset.x = 0;
17031 copyRegion.dstOffset.y = 0;
17032 copyRegion.dstOffset.z = 0;
17033 copyRegion.extent.width = 1;
17034 copyRegion.extent.height = 1;
17035 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017036 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017037 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017038
17039 m_errorMonitor->VerifyFound();
17040
17041 vkDestroyImage(m_device->device(), srcImage, NULL);
17042 vkDestroyImage(m_device->device(), dstImage, NULL);
17043 vkFreeMemory(m_device->device(), srcMem, NULL);
17044 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017045}
17046
Karl Schultz6addd812016-02-02 17:17:23 -070017047TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
17048 VkResult err;
17049 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017050
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017051 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17053 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017054
Mike Stroyana3082432015-09-25 13:39:21 -060017055 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017056 auto depth_format = find_depth_stencil_format(m_device);
17057 if (!depth_format) {
17058 return;
17059 }
Mike Stroyana3082432015-09-25 13:39:21 -060017060
17061 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017062 VkImage srcImage;
17063 VkImage dstImage;
17064 VkDeviceMemory srcMem;
17065 VkDeviceMemory destMem;
17066 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017067
17068 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017069 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17070 image_create_info.pNext = NULL;
17071 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17072 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17073 image_create_info.extent.width = 32;
17074 image_create_info.extent.height = 32;
17075 image_create_info.extent.depth = 1;
17076 image_create_info.mipLevels = 1;
17077 image_create_info.arrayLayers = 1;
17078 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17079 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17080 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17081 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017083 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017084 ASSERT_VK_SUCCESS(err);
17085
Karl Schultzbdb75952016-04-19 11:36:49 -060017086 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17087
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017088 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070017089 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070017090 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060017091 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017093 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017094 ASSERT_VK_SUCCESS(err);
17095
17096 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017097 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017098 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17099 memAlloc.pNext = NULL;
17100 memAlloc.allocationSize = 0;
17101 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017102
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017103 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017104 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017105 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017106 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017107 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017108 ASSERT_VK_SUCCESS(err);
17109
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017110 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017111 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017112 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017113 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017114 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017115 ASSERT_VK_SUCCESS(err);
17116
17117 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17118 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017119 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017120 ASSERT_VK_SUCCESS(err);
17121
Tony Barbour552f6c02016-12-21 14:34:07 -070017122 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017123 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017124 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017125 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017126 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017127 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017128 copyRegion.srcOffset.x = 0;
17129 copyRegion.srcOffset.y = 0;
17130 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017131 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017132 copyRegion.dstSubresource.mipLevel = 0;
17133 copyRegion.dstSubresource.baseArrayLayer = 0;
17134 copyRegion.dstSubresource.layerCount = 0;
17135 copyRegion.dstOffset.x = 0;
17136 copyRegion.dstOffset.y = 0;
17137 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017138 copyRegion.extent.width = 1;
17139 copyRegion.extent.height = 1;
17140 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017141 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017142 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017143
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017144 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017145
Chia-I Wuf7458c52015-10-26 21:10:41 +080017146 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017147 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017148 vkFreeMemory(m_device->device(), srcMem, NULL);
17149 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017150}
17151
Karl Schultz6addd812016-02-02 17:17:23 -070017152TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17153 VkResult err;
17154 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17157 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017158
Mike Stroyana3082432015-09-25 13:39:21 -060017159 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017160
17161 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017162 VkImage srcImage;
17163 VkImage dstImage;
17164 VkDeviceMemory srcMem;
17165 VkDeviceMemory destMem;
17166 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017167
17168 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017169 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17170 image_create_info.pNext = NULL;
17171 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17172 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17173 image_create_info.extent.width = 32;
17174 image_create_info.extent.height = 1;
17175 image_create_info.extent.depth = 1;
17176 image_create_info.mipLevels = 1;
17177 image_create_info.arrayLayers = 1;
17178 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17179 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17180 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17181 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017183 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017184 ASSERT_VK_SUCCESS(err);
17185
Karl Schultz6addd812016-02-02 17:17:23 -070017186 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017189 ASSERT_VK_SUCCESS(err);
17190
17191 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017192 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017193 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17194 memAlloc.pNext = NULL;
17195 memAlloc.allocationSize = 0;
17196 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017197
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017198 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017199 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017200 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017201 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017202 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017203 ASSERT_VK_SUCCESS(err);
17204
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017205 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017206 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017207 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017208 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017209 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017210 ASSERT_VK_SUCCESS(err);
17211
17212 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17213 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017214 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017215 ASSERT_VK_SUCCESS(err);
17216
Tony Barbour552f6c02016-12-21 14:34:07 -070017217 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017218 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017219 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17220 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017221 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017222 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017223 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017224 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017225 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017226 resolveRegion.srcOffset.x = 0;
17227 resolveRegion.srcOffset.y = 0;
17228 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017229 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017230 resolveRegion.dstSubresource.mipLevel = 0;
17231 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017232 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017233 resolveRegion.dstOffset.x = 0;
17234 resolveRegion.dstOffset.y = 0;
17235 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017236 resolveRegion.extent.width = 1;
17237 resolveRegion.extent.height = 1;
17238 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017239 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017240 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017241
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017242 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017243
Chia-I Wuf7458c52015-10-26 21:10:41 +080017244 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017245 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017246 vkFreeMemory(m_device->device(), srcMem, NULL);
17247 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017248}
17249
Karl Schultz6addd812016-02-02 17:17:23 -070017250TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17251 VkResult err;
17252 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17255 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017256
Mike Stroyana3082432015-09-25 13:39:21 -060017257 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017258
Chris Forbesa7530692016-05-08 12:35:39 +120017259 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017260 VkImage srcImage;
17261 VkImage dstImage;
17262 VkDeviceMemory srcMem;
17263 VkDeviceMemory destMem;
17264 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017265
17266 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017267 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17268 image_create_info.pNext = NULL;
17269 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17270 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17271 image_create_info.extent.width = 32;
17272 image_create_info.extent.height = 1;
17273 image_create_info.extent.depth = 1;
17274 image_create_info.mipLevels = 1;
17275 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017276 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017277 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17278 // Note: Some implementations expect color attachment usage for any
17279 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017280 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017281 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017284 ASSERT_VK_SUCCESS(err);
17285
Karl Schultz6addd812016-02-02 17:17:23 -070017286 // Note: Some implementations expect color attachment usage for any
17287 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017288 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017291 ASSERT_VK_SUCCESS(err);
17292
17293 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017294 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017295 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17296 memAlloc.pNext = NULL;
17297 memAlloc.allocationSize = 0;
17298 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017299
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017300 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017301 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017302 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017303 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017304 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017305 ASSERT_VK_SUCCESS(err);
17306
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017307 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017308 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017309 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017310 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017311 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017312 ASSERT_VK_SUCCESS(err);
17313
17314 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17315 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017316 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017317 ASSERT_VK_SUCCESS(err);
17318
Tony Barbour552f6c02016-12-21 14:34:07 -070017319 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017320 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017321 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17322 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017323 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017324 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017325 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017326 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017327 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017328 resolveRegion.srcOffset.x = 0;
17329 resolveRegion.srcOffset.y = 0;
17330 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017331 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017332 resolveRegion.dstSubresource.mipLevel = 0;
17333 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017334 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017335 resolveRegion.dstOffset.x = 0;
17336 resolveRegion.dstOffset.y = 0;
17337 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017338 resolveRegion.extent.width = 1;
17339 resolveRegion.extent.height = 1;
17340 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017341 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017342 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017343
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017344 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017345
Chia-I Wuf7458c52015-10-26 21:10:41 +080017346 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017347 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017348 vkFreeMemory(m_device->device(), srcMem, NULL);
17349 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017350}
17351
Karl Schultz6addd812016-02-02 17:17:23 -070017352TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17353 VkResult err;
17354 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017355
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017357 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017358
Mike Stroyana3082432015-09-25 13:39:21 -060017359 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017360
17361 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017362 VkImage srcImage;
17363 VkImage dstImage;
17364 VkDeviceMemory srcMem;
17365 VkDeviceMemory destMem;
17366 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017367
17368 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017369 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17370 image_create_info.pNext = NULL;
17371 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17372 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17373 image_create_info.extent.width = 32;
17374 image_create_info.extent.height = 1;
17375 image_create_info.extent.depth = 1;
17376 image_create_info.mipLevels = 1;
17377 image_create_info.arrayLayers = 1;
17378 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17379 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17380 // Note: Some implementations expect color attachment usage for any
17381 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017382 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017383 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017386 ASSERT_VK_SUCCESS(err);
17387
Karl Schultz6addd812016-02-02 17:17:23 -070017388 // Set format to something other than source image
17389 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17390 // Note: Some implementations expect color attachment usage for any
17391 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017392 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017393 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017395 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017396 ASSERT_VK_SUCCESS(err);
17397
17398 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017399 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017400 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17401 memAlloc.pNext = NULL;
17402 memAlloc.allocationSize = 0;
17403 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017404
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017405 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017406 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017407 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017408 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017409 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017410 ASSERT_VK_SUCCESS(err);
17411
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017412 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017413 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017414 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017415 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017416 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017417 ASSERT_VK_SUCCESS(err);
17418
17419 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17420 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017421 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017422 ASSERT_VK_SUCCESS(err);
17423
Tony Barbour552f6c02016-12-21 14:34:07 -070017424 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017425 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017426 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17427 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017428 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017429 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017430 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017431 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017432 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017433 resolveRegion.srcOffset.x = 0;
17434 resolveRegion.srcOffset.y = 0;
17435 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017436 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017437 resolveRegion.dstSubresource.mipLevel = 0;
17438 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017439 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017440 resolveRegion.dstOffset.x = 0;
17441 resolveRegion.dstOffset.y = 0;
17442 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017443 resolveRegion.extent.width = 1;
17444 resolveRegion.extent.height = 1;
17445 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017446 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017447 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017449 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017450
Chia-I Wuf7458c52015-10-26 21:10:41 +080017451 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017452 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017453 vkFreeMemory(m_device->device(), srcMem, NULL);
17454 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017455}
17456
Karl Schultz6addd812016-02-02 17:17:23 -070017457TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17458 VkResult err;
17459 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017460
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017462 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017463
Mike Stroyana3082432015-09-25 13:39:21 -060017464 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017465
17466 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017467 VkImage srcImage;
17468 VkImage dstImage;
17469 VkDeviceMemory srcMem;
17470 VkDeviceMemory destMem;
17471 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017472
17473 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017474 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17475 image_create_info.pNext = NULL;
17476 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17477 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17478 image_create_info.extent.width = 32;
17479 image_create_info.extent.height = 1;
17480 image_create_info.extent.depth = 1;
17481 image_create_info.mipLevels = 1;
17482 image_create_info.arrayLayers = 1;
17483 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17484 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17485 // Note: Some implementations expect color attachment usage for any
17486 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017487 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017488 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017491 ASSERT_VK_SUCCESS(err);
17492
Karl Schultz6addd812016-02-02 17:17:23 -070017493 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17494 // Note: Some implementations expect color attachment usage for any
17495 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017496 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017497 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017499 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017500 ASSERT_VK_SUCCESS(err);
17501
17502 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017503 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017504 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17505 memAlloc.pNext = NULL;
17506 memAlloc.allocationSize = 0;
17507 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017508
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017509 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017510 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017511 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017512 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017513 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017514 ASSERT_VK_SUCCESS(err);
17515
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017516 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017517 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017518 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017519 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017520 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017521 ASSERT_VK_SUCCESS(err);
17522
17523 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17524 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017525 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017526 ASSERT_VK_SUCCESS(err);
17527
Tony Barbour552f6c02016-12-21 14:34:07 -070017528 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017529 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017530 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17531 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017532 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017533 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017534 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017535 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017536 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017537 resolveRegion.srcOffset.x = 0;
17538 resolveRegion.srcOffset.y = 0;
17539 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017540 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017541 resolveRegion.dstSubresource.mipLevel = 0;
17542 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017543 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017544 resolveRegion.dstOffset.x = 0;
17545 resolveRegion.dstOffset.y = 0;
17546 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017547 resolveRegion.extent.width = 1;
17548 resolveRegion.extent.height = 1;
17549 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017550 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017551 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017552
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017553 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017554
Chia-I Wuf7458c52015-10-26 21:10:41 +080017555 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017556 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017557 vkFreeMemory(m_device->device(), srcMem, NULL);
17558 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017559}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017560
Karl Schultz6addd812016-02-02 17:17:23 -070017561TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017562 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017563 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17564 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017565 // The image format check comes 2nd in validation so we trigger it first,
17566 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017567 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17570 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017571
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017572 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017573 auto depth_format = find_depth_stencil_format(m_device);
17574 if (!depth_format) {
17575 return;
17576 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017577
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017578 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017579 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17580 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017581
17582 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017583 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17584 ds_pool_ci.pNext = NULL;
17585 ds_pool_ci.maxSets = 1;
17586 ds_pool_ci.poolSizeCount = 1;
17587 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017588
17589 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017590 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017591 ASSERT_VK_SUCCESS(err);
17592
17593 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017594 dsl_binding.binding = 0;
17595 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17596 dsl_binding.descriptorCount = 1;
17597 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17598 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017599
17600 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017601 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17602 ds_layout_ci.pNext = NULL;
17603 ds_layout_ci.bindingCount = 1;
17604 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017605 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017606 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017607 ASSERT_VK_SUCCESS(err);
17608
17609 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017610 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017611 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017612 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017613 alloc_info.descriptorPool = ds_pool;
17614 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017615 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017616 ASSERT_VK_SUCCESS(err);
17617
Karl Schultz6addd812016-02-02 17:17:23 -070017618 VkImage image_bad;
17619 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017620 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017621 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017622 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017623 const int32_t tex_width = 32;
17624 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017625
17626 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017627 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17628 image_create_info.pNext = NULL;
17629 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17630 image_create_info.format = tex_format_bad;
17631 image_create_info.extent.width = tex_width;
17632 image_create_info.extent.height = tex_height;
17633 image_create_info.extent.depth = 1;
17634 image_create_info.mipLevels = 1;
17635 image_create_info.arrayLayers = 1;
17636 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17637 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017638 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017639 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017641 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017642 ASSERT_VK_SUCCESS(err);
17643 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017644 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17645 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017646 ASSERT_VK_SUCCESS(err);
17647
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017648 // ---Bind image memory---
17649 VkMemoryRequirements img_mem_reqs;
17650 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17651 VkMemoryAllocateInfo image_alloc_info = {};
17652 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17653 image_alloc_info.pNext = NULL;
17654 image_alloc_info.memoryTypeIndex = 0;
17655 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017656 bool pass =
17657 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 -070017658 ASSERT_TRUE(pass);
17659 VkDeviceMemory mem;
17660 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17661 ASSERT_VK_SUCCESS(err);
17662 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17663 ASSERT_VK_SUCCESS(err);
17664 // -----------------------
17665
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017666 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017667 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017668 image_view_create_info.image = image_bad;
17669 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17670 image_view_create_info.format = tex_format_bad;
17671 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17672 image_view_create_info.subresourceRange.baseMipLevel = 0;
17673 image_view_create_info.subresourceRange.layerCount = 1;
17674 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017675 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017676
17677 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017678 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017680 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017681
Chia-I Wuf7458c52015-10-26 21:10:41 +080017682 vkDestroyImage(m_device->device(), image_bad, NULL);
17683 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017686
17687 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017688}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017689
17690TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017691 TEST_DESCRIPTION(
17692 "Call ClearColorImage w/ a depth|stencil image and "
17693 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017694
17695 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017696 auto depth_format = find_depth_stencil_format(m_device);
17697 if (!depth_format) {
17698 return;
17699 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17701
Tony Barbour552f6c02016-12-21 14:34:07 -070017702 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017703
17704 // Color image
17705 VkClearColorValue clear_color;
17706 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17707 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17708 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17709 const int32_t img_width = 32;
17710 const int32_t img_height = 32;
17711 VkImageCreateInfo image_create_info = {};
17712 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17713 image_create_info.pNext = NULL;
17714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17715 image_create_info.format = color_format;
17716 image_create_info.extent.width = img_width;
17717 image_create_info.extent.height = img_height;
17718 image_create_info.extent.depth = 1;
17719 image_create_info.mipLevels = 1;
17720 image_create_info.arrayLayers = 1;
17721 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17722 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17723 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17724
17725 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017726 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017727
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017728 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017729
17730 // Depth/Stencil image
17731 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017732 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017733 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17734 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017735 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017736 ds_image_create_info.extent.width = 64;
17737 ds_image_create_info.extent.height = 64;
17738 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017739 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 -060017740
17741 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017742 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017743
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017744 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 -060017745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017748 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017749 &color_range);
17750
17751 m_errorMonitor->VerifyFound();
17752
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17754 "vkCmdClearColorImage called with "
17755 "image created without "
17756 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017757
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017758 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017759 &color_range);
17760
17761 m_errorMonitor->VerifyFound();
17762
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017763 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17765 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017766
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017767 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17768 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017769
17770 m_errorMonitor->VerifyFound();
17771}
Tobin Ehliscde08892015-09-22 10:11:37 -060017772
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017773// WSI Enabled Tests
17774//
Chris Forbes09368e42016-10-13 11:59:22 +130017775#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017776TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17777
17778#if defined(VK_USE_PLATFORM_XCB_KHR)
17779 VkSurfaceKHR surface = VK_NULL_HANDLE;
17780
17781 VkResult err;
17782 bool pass;
17783 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17784 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17785 // uint32_t swapchain_image_count = 0;
17786 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17787 // uint32_t image_index = 0;
17788 // VkPresentInfoKHR present_info = {};
17789
17790 ASSERT_NO_FATAL_FAILURE(InitState());
17791
17792 // Use the create function from one of the VK_KHR_*_surface extension in
17793 // order to create a surface, testing all known errors in the process,
17794 // before successfully creating a surface:
17795 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17797 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17798 pass = (err != VK_SUCCESS);
17799 ASSERT_TRUE(pass);
17800 m_errorMonitor->VerifyFound();
17801
17802 // Next, try to create a surface with the wrong
17803 // VkXcbSurfaceCreateInfoKHR::sType:
17804 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17805 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17807 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17808 pass = (err != VK_SUCCESS);
17809 ASSERT_TRUE(pass);
17810 m_errorMonitor->VerifyFound();
17811
17812 // Create a native window, and then correctly create a surface:
17813 xcb_connection_t *connection;
17814 xcb_screen_t *screen;
17815 xcb_window_t xcb_window;
17816 xcb_intern_atom_reply_t *atom_wm_delete_window;
17817
17818 const xcb_setup_t *setup;
17819 xcb_screen_iterator_t iter;
17820 int scr;
17821 uint32_t value_mask, value_list[32];
17822 int width = 1;
17823 int height = 1;
17824
17825 connection = xcb_connect(NULL, &scr);
17826 ASSERT_TRUE(connection != NULL);
17827 setup = xcb_get_setup(connection);
17828 iter = xcb_setup_roots_iterator(setup);
17829 while (scr-- > 0)
17830 xcb_screen_next(&iter);
17831 screen = iter.data;
17832
17833 xcb_window = xcb_generate_id(connection);
17834
17835 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17836 value_list[0] = screen->black_pixel;
17837 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17838
17839 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17840 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17841
17842 /* Magic code that will send notification when window is destroyed */
17843 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17844 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17845
17846 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17847 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17848 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17849 free(reply);
17850
17851 xcb_map_window(connection, xcb_window);
17852
17853 // Force the x/y coordinates to 100,100 results are identical in consecutive
17854 // runs
17855 const uint32_t coords[] = { 100, 100 };
17856 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17857
17858 // Finally, try to correctly create a surface:
17859 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17860 xcb_create_info.pNext = NULL;
17861 xcb_create_info.flags = 0;
17862 xcb_create_info.connection = connection;
17863 xcb_create_info.window = xcb_window;
17864 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17865 pass = (err == VK_SUCCESS);
17866 ASSERT_TRUE(pass);
17867
17868 // Check if surface supports presentation:
17869
17870 // 1st, do so without having queried the queue families:
17871 VkBool32 supported = false;
17872 // TODO: Get the following error to come out:
17873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17874 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17875 "function");
17876 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17877 pass = (err != VK_SUCCESS);
17878 // ASSERT_TRUE(pass);
17879 // m_errorMonitor->VerifyFound();
17880
17881 // Next, query a queue family index that's too large:
17882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17883 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17884 pass = (err != VK_SUCCESS);
17885 ASSERT_TRUE(pass);
17886 m_errorMonitor->VerifyFound();
17887
17888 // Finally, do so correctly:
17889 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17890 // SUPPORTED
17891 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17892 pass = (err == VK_SUCCESS);
17893 ASSERT_TRUE(pass);
17894
17895 // Before proceeding, try to create a swapchain without having called
17896 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17897 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17898 swapchain_create_info.pNext = NULL;
17899 swapchain_create_info.flags = 0;
17900 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17901 swapchain_create_info.surface = surface;
17902 swapchain_create_info.imageArrayLayers = 1;
17903 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17904 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17906 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17907 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17908 pass = (err != VK_SUCCESS);
17909 ASSERT_TRUE(pass);
17910 m_errorMonitor->VerifyFound();
17911
17912 // Get the surface capabilities:
17913 VkSurfaceCapabilitiesKHR surface_capabilities;
17914
17915 // Do so correctly (only error logged by this entrypoint is if the
17916 // extension isn't enabled):
17917 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17918 pass = (err == VK_SUCCESS);
17919 ASSERT_TRUE(pass);
17920
17921 // Get the surface formats:
17922 uint32_t surface_format_count;
17923
17924 // First, try without a pointer to surface_format_count:
17925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17926 "specified as NULL");
17927 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17928 pass = (err == VK_SUCCESS);
17929 ASSERT_TRUE(pass);
17930 m_errorMonitor->VerifyFound();
17931
17932 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17933 // correctly done a 1st try (to get the count):
17934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17935 surface_format_count = 0;
17936 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17937 pass = (err == VK_SUCCESS);
17938 ASSERT_TRUE(pass);
17939 m_errorMonitor->VerifyFound();
17940
17941 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17942 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17943 pass = (err == VK_SUCCESS);
17944 ASSERT_TRUE(pass);
17945
17946 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17947 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17948
17949 // Next, do a 2nd try with surface_format_count being set too high:
17950 surface_format_count += 5;
17951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17952 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17953 pass = (err == VK_SUCCESS);
17954 ASSERT_TRUE(pass);
17955 m_errorMonitor->VerifyFound();
17956
17957 // Finally, do a correct 1st and 2nd try:
17958 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17959 pass = (err == VK_SUCCESS);
17960 ASSERT_TRUE(pass);
17961 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17962 pass = (err == VK_SUCCESS);
17963 ASSERT_TRUE(pass);
17964
17965 // Get the surface present modes:
17966 uint32_t surface_present_mode_count;
17967
17968 // First, try without a pointer to surface_format_count:
17969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17970 "specified as NULL");
17971
17972 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17973 pass = (err == VK_SUCCESS);
17974 ASSERT_TRUE(pass);
17975 m_errorMonitor->VerifyFound();
17976
17977 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17978 // correctly done a 1st try (to get the count):
17979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17980 surface_present_mode_count = 0;
17981 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17982 (VkPresentModeKHR *)&surface_present_mode_count);
17983 pass = (err == VK_SUCCESS);
17984 ASSERT_TRUE(pass);
17985 m_errorMonitor->VerifyFound();
17986
17987 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17988 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17989 pass = (err == VK_SUCCESS);
17990 ASSERT_TRUE(pass);
17991
17992 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17993 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17994
17995 // Next, do a 2nd try with surface_format_count being set too high:
17996 surface_present_mode_count += 5;
17997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17998 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17999 pass = (err == VK_SUCCESS);
18000 ASSERT_TRUE(pass);
18001 m_errorMonitor->VerifyFound();
18002
18003 // Finally, do a correct 1st and 2nd try:
18004 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
18005 pass = (err == VK_SUCCESS);
18006 ASSERT_TRUE(pass);
18007 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
18008 pass = (err == VK_SUCCESS);
18009 ASSERT_TRUE(pass);
18010
18011 // Create a swapchain:
18012
18013 // First, try without a pointer to swapchain_create_info:
18014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
18015 "specified as NULL");
18016
18017 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
18018 pass = (err != VK_SUCCESS);
18019 ASSERT_TRUE(pass);
18020 m_errorMonitor->VerifyFound();
18021
18022 // Next, call with a non-NULL swapchain_create_info, that has the wrong
18023 // sType:
18024 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
18025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
18026
18027 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18028 pass = (err != VK_SUCCESS);
18029 ASSERT_TRUE(pass);
18030 m_errorMonitor->VerifyFound();
18031
18032 // Next, call with a NULL swapchain pointer:
18033 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
18034 swapchain_create_info.pNext = NULL;
18035 swapchain_create_info.flags = 0;
18036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
18037 "specified as NULL");
18038
18039 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
18040 pass = (err != VK_SUCCESS);
18041 ASSERT_TRUE(pass);
18042 m_errorMonitor->VerifyFound();
18043
18044 // TODO: Enhance swapchain layer so that
18045 // swapchain_create_info.queueFamilyIndexCount is checked against something?
18046
18047 // Next, call with a queue family index that's too large:
18048 uint32_t queueFamilyIndex[2] = { 100000, 0 };
18049 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18050 swapchain_create_info.queueFamilyIndexCount = 2;
18051 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
18052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
18053 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18054 pass = (err != VK_SUCCESS);
18055 ASSERT_TRUE(pass);
18056 m_errorMonitor->VerifyFound();
18057
18058 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
18059 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18060 swapchain_create_info.queueFamilyIndexCount = 1;
18061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18062 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
18063 "pCreateInfo->pQueueFamilyIndices).");
18064 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18065 pass = (err != VK_SUCCESS);
18066 ASSERT_TRUE(pass);
18067 m_errorMonitor->VerifyFound();
18068
18069 // Next, call with an invalid imageSharingMode:
18070 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
18071 swapchain_create_info.queueFamilyIndexCount = 1;
18072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18073 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
18074 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18075 pass = (err != VK_SUCCESS);
18076 ASSERT_TRUE(pass);
18077 m_errorMonitor->VerifyFound();
18078 // Fix for the future:
18079 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
18080 // SUPPORTED
18081 swapchain_create_info.queueFamilyIndexCount = 0;
18082 queueFamilyIndex[0] = 0;
18083 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
18084
18085 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
18086 // Get the images from a swapchain:
18087 // Acquire an image from a swapchain:
18088 // Present an image to a swapchain:
18089 // Destroy the swapchain:
18090
18091 // TODOs:
18092 //
18093 // - Try destroying the device without first destroying the swapchain
18094 //
18095 // - Try destroying the device without first destroying the surface
18096 //
18097 // - Try destroying the surface without first destroying the swapchain
18098
18099 // Destroy the surface:
18100 vkDestroySurfaceKHR(instance(), surface, NULL);
18101
18102 // Tear down the window:
18103 xcb_destroy_window(connection, xcb_window);
18104 xcb_disconnect(connection);
18105
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018106#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018107 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018108#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018109}
Chris Forbes09368e42016-10-13 11:59:22 +130018110#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018111
18112//
18113// POSITIVE VALIDATION TESTS
18114//
18115// These tests do not expect to encounter ANY validation errors pass only if this is true
18116
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018117TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18118 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18119 ASSERT_NO_FATAL_FAILURE(InitState());
18120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18121
18122 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18123 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18124 command_buffer_allocate_info.commandPool = m_commandPool;
18125 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18126 command_buffer_allocate_info.commandBufferCount = 1;
18127
18128 VkCommandBuffer secondary_command_buffer;
18129 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18130 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18131 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18132 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18133 command_buffer_inheritance_info.renderPass = m_renderPass;
18134 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18135
18136 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18137 command_buffer_begin_info.flags =
18138 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18139 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18140
18141 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18142 VkClearAttachment color_attachment;
18143 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18144 color_attachment.clearValue.color.float32[0] = 0;
18145 color_attachment.clearValue.color.float32[1] = 0;
18146 color_attachment.clearValue.color.float32[2] = 0;
18147 color_attachment.clearValue.color.float32[3] = 0;
18148 color_attachment.colorAttachment = 0;
18149 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18150 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18151}
18152
Tobin Ehlise0006882016-11-03 10:14:28 -060018153TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018154 TEST_DESCRIPTION(
18155 "Perform an image layout transition in a secondary command buffer followed "
18156 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018157 VkResult err;
18158 m_errorMonitor->ExpectSuccess();
18159 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018160 auto depth_format = find_depth_stencil_format(m_device);
18161 if (!depth_format) {
18162 return;
18163 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18165 // Allocate a secondary and primary cmd buffer
18166 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18167 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18168 command_buffer_allocate_info.commandPool = m_commandPool;
18169 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18170 command_buffer_allocate_info.commandBufferCount = 1;
18171
18172 VkCommandBuffer secondary_command_buffer;
18173 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18174 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18175 VkCommandBuffer primary_command_buffer;
18176 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18177 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18178 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18179 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18180 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18181 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18182 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18183
18184 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18185 ASSERT_VK_SUCCESS(err);
18186 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018187 image.init(128, 128, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlise0006882016-11-03 10:14:28 -060018188 ASSERT_TRUE(image.initialized());
18189 VkImageMemoryBarrier img_barrier = {};
18190 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18191 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18192 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18193 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18194 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18195 img_barrier.image = image.handle();
18196 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18197 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18198 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18199 img_barrier.subresourceRange.baseArrayLayer = 0;
18200 img_barrier.subresourceRange.baseMipLevel = 0;
18201 img_barrier.subresourceRange.layerCount = 1;
18202 img_barrier.subresourceRange.levelCount = 1;
18203 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18204 0, nullptr, 1, &img_barrier);
18205 err = vkEndCommandBuffer(secondary_command_buffer);
18206 ASSERT_VK_SUCCESS(err);
18207
18208 // Now update primary cmd buffer to execute secondary and transitions image
18209 command_buffer_begin_info.pInheritanceInfo = nullptr;
18210 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18211 ASSERT_VK_SUCCESS(err);
18212 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18213 VkImageMemoryBarrier img_barrier2 = {};
18214 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18215 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18216 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18217 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18218 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18219 img_barrier2.image = image.handle();
18220 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18221 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18222 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18223 img_barrier2.subresourceRange.baseArrayLayer = 0;
18224 img_barrier2.subresourceRange.baseMipLevel = 0;
18225 img_barrier2.subresourceRange.layerCount = 1;
18226 img_barrier2.subresourceRange.levelCount = 1;
18227 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18228 nullptr, 1, &img_barrier2);
18229 err = vkEndCommandBuffer(primary_command_buffer);
18230 ASSERT_VK_SUCCESS(err);
18231 VkSubmitInfo submit_info = {};
18232 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18233 submit_info.commandBufferCount = 1;
18234 submit_info.pCommandBuffers = &primary_command_buffer;
18235 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18236 ASSERT_VK_SUCCESS(err);
18237 m_errorMonitor->VerifyNotFound();
18238 err = vkDeviceWaitIdle(m_device->device());
18239 ASSERT_VK_SUCCESS(err);
18240 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18241 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18242}
18243
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018244// This is a positive test. No failures are expected.
18245TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018246 TEST_DESCRIPTION(
18247 "Ensure that the vkUpdateDescriptorSets validation code "
18248 "is ignoring VkWriteDescriptorSet members that are not "
18249 "related to the descriptor type specified by "
18250 "VkWriteDescriptorSet::descriptorType. Correct "
18251 "validation behavior will result in the test running to "
18252 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018253
18254 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18255
18256 ASSERT_NO_FATAL_FAILURE(InitState());
18257
18258 // Image Case
18259 {
18260 m_errorMonitor->ExpectSuccess();
18261
18262 VkImage image;
18263 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18264 const int32_t tex_width = 32;
18265 const int32_t tex_height = 32;
18266 VkImageCreateInfo image_create_info = {};
18267 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18268 image_create_info.pNext = NULL;
18269 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18270 image_create_info.format = tex_format;
18271 image_create_info.extent.width = tex_width;
18272 image_create_info.extent.height = tex_height;
18273 image_create_info.extent.depth = 1;
18274 image_create_info.mipLevels = 1;
18275 image_create_info.arrayLayers = 1;
18276 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18277 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18278 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18279 image_create_info.flags = 0;
18280 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18281 ASSERT_VK_SUCCESS(err);
18282
18283 VkMemoryRequirements memory_reqs;
18284 VkDeviceMemory image_memory;
18285 bool pass;
18286 VkMemoryAllocateInfo memory_info = {};
18287 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18288 memory_info.pNext = NULL;
18289 memory_info.allocationSize = 0;
18290 memory_info.memoryTypeIndex = 0;
18291 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18292 memory_info.allocationSize = memory_reqs.size;
18293 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18294 ASSERT_TRUE(pass);
18295 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18296 ASSERT_VK_SUCCESS(err);
18297 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18298 ASSERT_VK_SUCCESS(err);
18299
18300 VkImageViewCreateInfo image_view_create_info = {};
18301 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18302 image_view_create_info.image = image;
18303 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18304 image_view_create_info.format = tex_format;
18305 image_view_create_info.subresourceRange.layerCount = 1;
18306 image_view_create_info.subresourceRange.baseMipLevel = 0;
18307 image_view_create_info.subresourceRange.levelCount = 1;
18308 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18309
18310 VkImageView view;
18311 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18312 ASSERT_VK_SUCCESS(err);
18313
18314 VkDescriptorPoolSize ds_type_count = {};
18315 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18316 ds_type_count.descriptorCount = 1;
18317
18318 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18319 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18320 ds_pool_ci.pNext = NULL;
18321 ds_pool_ci.maxSets = 1;
18322 ds_pool_ci.poolSizeCount = 1;
18323 ds_pool_ci.pPoolSizes = &ds_type_count;
18324
18325 VkDescriptorPool ds_pool;
18326 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18327 ASSERT_VK_SUCCESS(err);
18328
18329 VkDescriptorSetLayoutBinding dsl_binding = {};
18330 dsl_binding.binding = 0;
18331 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18332 dsl_binding.descriptorCount = 1;
18333 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18334 dsl_binding.pImmutableSamplers = NULL;
18335
18336 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18337 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18338 ds_layout_ci.pNext = NULL;
18339 ds_layout_ci.bindingCount = 1;
18340 ds_layout_ci.pBindings = &dsl_binding;
18341 VkDescriptorSetLayout ds_layout;
18342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18343 ASSERT_VK_SUCCESS(err);
18344
18345 VkDescriptorSet descriptor_set;
18346 VkDescriptorSetAllocateInfo alloc_info = {};
18347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18348 alloc_info.descriptorSetCount = 1;
18349 alloc_info.descriptorPool = ds_pool;
18350 alloc_info.pSetLayouts = &ds_layout;
18351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18352 ASSERT_VK_SUCCESS(err);
18353
18354 VkDescriptorImageInfo image_info = {};
18355 image_info.imageView = view;
18356 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18357
18358 VkWriteDescriptorSet descriptor_write;
18359 memset(&descriptor_write, 0, sizeof(descriptor_write));
18360 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18361 descriptor_write.dstSet = descriptor_set;
18362 descriptor_write.dstBinding = 0;
18363 descriptor_write.descriptorCount = 1;
18364 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18365 descriptor_write.pImageInfo = &image_info;
18366
18367 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18368 // be
18369 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18370 // This will most likely produce a crash if the parameter_validation
18371 // layer
18372 // does not correctly ignore pBufferInfo.
18373 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18374 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18375
18376 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18377
18378 m_errorMonitor->VerifyNotFound();
18379
18380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18382 vkDestroyImageView(m_device->device(), view, NULL);
18383 vkDestroyImage(m_device->device(), image, NULL);
18384 vkFreeMemory(m_device->device(), image_memory, NULL);
18385 }
18386
18387 // Buffer Case
18388 {
18389 m_errorMonitor->ExpectSuccess();
18390
18391 VkBuffer buffer;
18392 uint32_t queue_family_index = 0;
18393 VkBufferCreateInfo buffer_create_info = {};
18394 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18395 buffer_create_info.size = 1024;
18396 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18397 buffer_create_info.queueFamilyIndexCount = 1;
18398 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18399
18400 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18401 ASSERT_VK_SUCCESS(err);
18402
18403 VkMemoryRequirements memory_reqs;
18404 VkDeviceMemory buffer_memory;
18405 bool pass;
18406 VkMemoryAllocateInfo memory_info = {};
18407 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18408 memory_info.pNext = NULL;
18409 memory_info.allocationSize = 0;
18410 memory_info.memoryTypeIndex = 0;
18411
18412 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18413 memory_info.allocationSize = memory_reqs.size;
18414 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18415 ASSERT_TRUE(pass);
18416
18417 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18418 ASSERT_VK_SUCCESS(err);
18419 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18420 ASSERT_VK_SUCCESS(err);
18421
18422 VkDescriptorPoolSize ds_type_count = {};
18423 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18424 ds_type_count.descriptorCount = 1;
18425
18426 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18427 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18428 ds_pool_ci.pNext = NULL;
18429 ds_pool_ci.maxSets = 1;
18430 ds_pool_ci.poolSizeCount = 1;
18431 ds_pool_ci.pPoolSizes = &ds_type_count;
18432
18433 VkDescriptorPool ds_pool;
18434 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18435 ASSERT_VK_SUCCESS(err);
18436
18437 VkDescriptorSetLayoutBinding dsl_binding = {};
18438 dsl_binding.binding = 0;
18439 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18440 dsl_binding.descriptorCount = 1;
18441 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18442 dsl_binding.pImmutableSamplers = NULL;
18443
18444 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18445 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18446 ds_layout_ci.pNext = NULL;
18447 ds_layout_ci.bindingCount = 1;
18448 ds_layout_ci.pBindings = &dsl_binding;
18449 VkDescriptorSetLayout ds_layout;
18450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18451 ASSERT_VK_SUCCESS(err);
18452
18453 VkDescriptorSet descriptor_set;
18454 VkDescriptorSetAllocateInfo alloc_info = {};
18455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18456 alloc_info.descriptorSetCount = 1;
18457 alloc_info.descriptorPool = ds_pool;
18458 alloc_info.pSetLayouts = &ds_layout;
18459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18460 ASSERT_VK_SUCCESS(err);
18461
18462 VkDescriptorBufferInfo buffer_info = {};
18463 buffer_info.buffer = buffer;
18464 buffer_info.offset = 0;
18465 buffer_info.range = 1024;
18466
18467 VkWriteDescriptorSet descriptor_write;
18468 memset(&descriptor_write, 0, sizeof(descriptor_write));
18469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18470 descriptor_write.dstSet = descriptor_set;
18471 descriptor_write.dstBinding = 0;
18472 descriptor_write.descriptorCount = 1;
18473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18474 descriptor_write.pBufferInfo = &buffer_info;
18475
18476 // Set pImageInfo and pTexelBufferView to invalid values, which should
18477 // be
18478 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18479 // This will most likely produce a crash if the parameter_validation
18480 // layer
18481 // does not correctly ignore pImageInfo.
18482 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18483 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18484
18485 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18486
18487 m_errorMonitor->VerifyNotFound();
18488
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018489 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18490 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18491 vkDestroyBuffer(m_device->device(), buffer, NULL);
18492 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18493 }
18494
18495 // Texel Buffer Case
18496 {
18497 m_errorMonitor->ExpectSuccess();
18498
18499 VkBuffer buffer;
18500 uint32_t queue_family_index = 0;
18501 VkBufferCreateInfo buffer_create_info = {};
18502 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18503 buffer_create_info.size = 1024;
18504 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18505 buffer_create_info.queueFamilyIndexCount = 1;
18506 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18507
18508 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18509 ASSERT_VK_SUCCESS(err);
18510
18511 VkMemoryRequirements memory_reqs;
18512 VkDeviceMemory buffer_memory;
18513 bool pass;
18514 VkMemoryAllocateInfo memory_info = {};
18515 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18516 memory_info.pNext = NULL;
18517 memory_info.allocationSize = 0;
18518 memory_info.memoryTypeIndex = 0;
18519
18520 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18521 memory_info.allocationSize = memory_reqs.size;
18522 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18523 ASSERT_TRUE(pass);
18524
18525 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18526 ASSERT_VK_SUCCESS(err);
18527 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18528 ASSERT_VK_SUCCESS(err);
18529
18530 VkBufferViewCreateInfo buff_view_ci = {};
18531 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18532 buff_view_ci.buffer = buffer;
18533 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18534 buff_view_ci.range = VK_WHOLE_SIZE;
18535 VkBufferView buffer_view;
18536 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18537
18538 VkDescriptorPoolSize ds_type_count = {};
18539 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18540 ds_type_count.descriptorCount = 1;
18541
18542 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18543 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18544 ds_pool_ci.pNext = NULL;
18545 ds_pool_ci.maxSets = 1;
18546 ds_pool_ci.poolSizeCount = 1;
18547 ds_pool_ci.pPoolSizes = &ds_type_count;
18548
18549 VkDescriptorPool ds_pool;
18550 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18551 ASSERT_VK_SUCCESS(err);
18552
18553 VkDescriptorSetLayoutBinding dsl_binding = {};
18554 dsl_binding.binding = 0;
18555 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18556 dsl_binding.descriptorCount = 1;
18557 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18558 dsl_binding.pImmutableSamplers = NULL;
18559
18560 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18561 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18562 ds_layout_ci.pNext = NULL;
18563 ds_layout_ci.bindingCount = 1;
18564 ds_layout_ci.pBindings = &dsl_binding;
18565 VkDescriptorSetLayout ds_layout;
18566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18567 ASSERT_VK_SUCCESS(err);
18568
18569 VkDescriptorSet descriptor_set;
18570 VkDescriptorSetAllocateInfo alloc_info = {};
18571 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18572 alloc_info.descriptorSetCount = 1;
18573 alloc_info.descriptorPool = ds_pool;
18574 alloc_info.pSetLayouts = &ds_layout;
18575 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18576 ASSERT_VK_SUCCESS(err);
18577
18578 VkWriteDescriptorSet descriptor_write;
18579 memset(&descriptor_write, 0, sizeof(descriptor_write));
18580 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18581 descriptor_write.dstSet = descriptor_set;
18582 descriptor_write.dstBinding = 0;
18583 descriptor_write.descriptorCount = 1;
18584 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18585 descriptor_write.pTexelBufferView = &buffer_view;
18586
18587 // Set pImageInfo and pBufferInfo to invalid values, which should be
18588 // ignored for descriptorType ==
18589 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18590 // This will most likely produce a crash if the parameter_validation
18591 // layer
18592 // does not correctly ignore pImageInfo and pBufferInfo.
18593 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18594 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18595
18596 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18597
18598 m_errorMonitor->VerifyNotFound();
18599
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018600 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18601 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18602 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18603 vkDestroyBuffer(m_device->device(), buffer, NULL);
18604 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18605 }
18606}
18607
Tobin Ehlisf7428442016-10-25 07:58:24 -060018608TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18609 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18610
18611 ASSERT_NO_FATAL_FAILURE(InitState());
18612 // Create layout where two binding #s are "1"
18613 static const uint32_t NUM_BINDINGS = 3;
18614 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18615 dsl_binding[0].binding = 1;
18616 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18617 dsl_binding[0].descriptorCount = 1;
18618 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18619 dsl_binding[0].pImmutableSamplers = NULL;
18620 dsl_binding[1].binding = 0;
18621 dsl_binding[1].descriptorCount = 1;
18622 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18623 dsl_binding[1].descriptorCount = 1;
18624 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18625 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018626 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018627 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18628 dsl_binding[2].descriptorCount = 1;
18629 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18630 dsl_binding[2].pImmutableSamplers = NULL;
18631
18632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18634 ds_layout_ci.pNext = NULL;
18635 ds_layout_ci.bindingCount = NUM_BINDINGS;
18636 ds_layout_ci.pBindings = dsl_binding;
18637 VkDescriptorSetLayout ds_layout;
18638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18639 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18640 m_errorMonitor->VerifyFound();
18641}
18642
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018643TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018644 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18645
18646 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018647
Tony Barbour552f6c02016-12-21 14:34:07 -070018648 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018649
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018650 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18651
18652 {
18653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18654 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18655 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18656 m_errorMonitor->VerifyFound();
18657 }
18658
18659 {
18660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18661 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18662 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18663 m_errorMonitor->VerifyFound();
18664 }
18665
18666 {
18667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18668 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18669 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18670 m_errorMonitor->VerifyFound();
18671 }
18672
18673 {
18674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18675 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18676 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18677 m_errorMonitor->VerifyFound();
18678 }
18679
18680 {
18681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18682 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18683 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18684 m_errorMonitor->VerifyFound();
18685 }
18686
18687 {
18688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18689 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18690 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18691 m_errorMonitor->VerifyFound();
18692 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018693
18694 {
18695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18696 VkRect2D scissor = {{-1, 0}, {16, 16}};
18697 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18698 m_errorMonitor->VerifyFound();
18699 }
18700
18701 {
18702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18703 VkRect2D scissor = {{0, -2}, {16, 16}};
18704 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18705 m_errorMonitor->VerifyFound();
18706 }
18707
18708 {
18709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18710 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18711 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18712 m_errorMonitor->VerifyFound();
18713 }
18714
18715 {
18716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18717 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18718 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18719 m_errorMonitor->VerifyFound();
18720 }
18721
Tony Barbour552f6c02016-12-21 14:34:07 -070018722 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018723}
18724
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018725// This is a positive test. No failures are expected.
18726TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18727 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18728 VkResult err;
18729
18730 ASSERT_NO_FATAL_FAILURE(InitState());
18731 m_errorMonitor->ExpectSuccess();
18732 VkDescriptorPoolSize ds_type_count = {};
18733 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18734 ds_type_count.descriptorCount = 2;
18735
18736 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18737 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18738 ds_pool_ci.pNext = NULL;
18739 ds_pool_ci.maxSets = 1;
18740 ds_pool_ci.poolSizeCount = 1;
18741 ds_pool_ci.pPoolSizes = &ds_type_count;
18742
18743 VkDescriptorPool ds_pool;
18744 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18745 ASSERT_VK_SUCCESS(err);
18746
18747 // Create layout with two uniform buffer descriptors w/ empty binding between them
18748 static const uint32_t NUM_BINDINGS = 3;
18749 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18750 dsl_binding[0].binding = 0;
18751 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18752 dsl_binding[0].descriptorCount = 1;
18753 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18754 dsl_binding[0].pImmutableSamplers = NULL;
18755 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018756 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018757 dsl_binding[2].binding = 2;
18758 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18759 dsl_binding[2].descriptorCount = 1;
18760 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18761 dsl_binding[2].pImmutableSamplers = NULL;
18762
18763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18765 ds_layout_ci.pNext = NULL;
18766 ds_layout_ci.bindingCount = NUM_BINDINGS;
18767 ds_layout_ci.pBindings = dsl_binding;
18768 VkDescriptorSetLayout ds_layout;
18769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18770 ASSERT_VK_SUCCESS(err);
18771
18772 VkDescriptorSet descriptor_set = {};
18773 VkDescriptorSetAllocateInfo alloc_info = {};
18774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18775 alloc_info.descriptorSetCount = 1;
18776 alloc_info.descriptorPool = ds_pool;
18777 alloc_info.pSetLayouts = &ds_layout;
18778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18779 ASSERT_VK_SUCCESS(err);
18780
18781 // Create a buffer to be used for update
18782 VkBufferCreateInfo buff_ci = {};
18783 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18784 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18785 buff_ci.size = 256;
18786 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18787 VkBuffer buffer;
18788 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18789 ASSERT_VK_SUCCESS(err);
18790 // Have to bind memory to buffer before descriptor update
18791 VkMemoryAllocateInfo mem_alloc = {};
18792 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18793 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018794 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018795 mem_alloc.memoryTypeIndex = 0;
18796
18797 VkMemoryRequirements mem_reqs;
18798 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18799 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18800 if (!pass) {
18801 vkDestroyBuffer(m_device->device(), buffer, NULL);
18802 return;
18803 }
18804
18805 VkDeviceMemory mem;
18806 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18807 ASSERT_VK_SUCCESS(err);
18808 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18809 ASSERT_VK_SUCCESS(err);
18810
18811 // Only update the descriptor at binding 2
18812 VkDescriptorBufferInfo buff_info = {};
18813 buff_info.buffer = buffer;
18814 buff_info.offset = 0;
18815 buff_info.range = VK_WHOLE_SIZE;
18816 VkWriteDescriptorSet descriptor_write = {};
18817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18818 descriptor_write.dstBinding = 2;
18819 descriptor_write.descriptorCount = 1;
18820 descriptor_write.pTexelBufferView = nullptr;
18821 descriptor_write.pBufferInfo = &buff_info;
18822 descriptor_write.pImageInfo = nullptr;
18823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18824 descriptor_write.dstSet = descriptor_set;
18825
18826 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18827
18828 m_errorMonitor->VerifyNotFound();
18829 // Cleanup
18830 vkFreeMemory(m_device->device(), mem, NULL);
18831 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18832 vkDestroyBuffer(m_device->device(), buffer, NULL);
18833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18834}
18835
18836// This is a positive test. No failures are expected.
18837TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18838 VkResult err;
18839 bool pass;
18840
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018841 TEST_DESCRIPTION(
18842 "Create a buffer, allocate memory, bind memory, destroy "
18843 "the buffer, create an image, and bind the same memory to "
18844 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018845
18846 m_errorMonitor->ExpectSuccess();
18847
18848 ASSERT_NO_FATAL_FAILURE(InitState());
18849
18850 VkBuffer buffer;
18851 VkImage image;
18852 VkDeviceMemory mem;
18853 VkMemoryRequirements mem_reqs;
18854
18855 VkBufferCreateInfo buf_info = {};
18856 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18857 buf_info.pNext = NULL;
18858 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18859 buf_info.size = 256;
18860 buf_info.queueFamilyIndexCount = 0;
18861 buf_info.pQueueFamilyIndices = NULL;
18862 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18863 buf_info.flags = 0;
18864 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18865 ASSERT_VK_SUCCESS(err);
18866
18867 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18868
18869 VkMemoryAllocateInfo alloc_info = {};
18870 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18871 alloc_info.pNext = NULL;
18872 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018873
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018874 // Ensure memory is big enough for both bindings
18875 alloc_info.allocationSize = 0x10000;
18876
18877 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18878 if (!pass) {
18879 vkDestroyBuffer(m_device->device(), buffer, NULL);
18880 return;
18881 }
18882
18883 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18884 ASSERT_VK_SUCCESS(err);
18885
18886 uint8_t *pData;
18887 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18888 ASSERT_VK_SUCCESS(err);
18889
18890 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18891
18892 vkUnmapMemory(m_device->device(), mem);
18893
18894 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18895 ASSERT_VK_SUCCESS(err);
18896
18897 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18898 // memory. In fact, it was never used by the GPU.
18899 // Just be be sure, wait for idle.
18900 vkDestroyBuffer(m_device->device(), buffer, NULL);
18901 vkDeviceWaitIdle(m_device->device());
18902
Tobin Ehlis6a005702016-12-28 15:25:56 -070018903 // Use optimal as some platforms report linear support but then fail image creation
18904 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18905 VkImageFormatProperties image_format_properties;
18906 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18907 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18908 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018909 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018910 vkFreeMemory(m_device->device(), mem, NULL);
18911 return;
18912 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018913 VkImageCreateInfo image_create_info = {};
18914 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18915 image_create_info.pNext = NULL;
18916 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18917 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18918 image_create_info.extent.width = 64;
18919 image_create_info.extent.height = 64;
18920 image_create_info.extent.depth = 1;
18921 image_create_info.mipLevels = 1;
18922 image_create_info.arrayLayers = 1;
18923 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018924 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018925 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18926 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18927 image_create_info.queueFamilyIndexCount = 0;
18928 image_create_info.pQueueFamilyIndices = NULL;
18929 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18930 image_create_info.flags = 0;
18931
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018932 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018933 * to be textures or it will be the staging image if they are not.
18934 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018935 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18936 ASSERT_VK_SUCCESS(err);
18937
18938 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18939
Tobin Ehlis6a005702016-12-28 15:25:56 -070018940 VkMemoryAllocateInfo mem_alloc = {};
18941 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18942 mem_alloc.pNext = NULL;
18943 mem_alloc.allocationSize = 0;
18944 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018945 mem_alloc.allocationSize = mem_reqs.size;
18946
18947 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18948 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018949 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018950 vkDestroyImage(m_device->device(), image, NULL);
18951 return;
18952 }
18953
18954 // VALIDATION FAILURE:
18955 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18956 ASSERT_VK_SUCCESS(err);
18957
18958 m_errorMonitor->VerifyNotFound();
18959
18960 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018961 vkDestroyImage(m_device->device(), image, NULL);
18962}
18963
Tony Barbourab713912017-02-02 14:17:35 -070018964// This is a positive test. No failures are expected.
18965TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18966 VkResult err;
18967
18968 TEST_DESCRIPTION(
18969 "Call all applicable destroy and free routines with NULL"
18970 "handles, expecting no validation errors");
18971
18972 m_errorMonitor->ExpectSuccess();
18973
18974 ASSERT_NO_FATAL_FAILURE(InitState());
18975 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18976 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18977 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18978 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18979 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18980 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18981 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18982 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18983 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18984 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18985 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18986 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18987 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18988 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18989 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18990 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18991 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18992 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18993 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18994 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18995
18996 VkCommandPool command_pool;
18997 VkCommandPoolCreateInfo pool_create_info{};
18998 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18999 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19000 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19001 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19002 VkCommandBuffer command_buffers[3] = {};
19003 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19004 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19005 command_buffer_allocate_info.commandPool = command_pool;
19006 command_buffer_allocate_info.commandBufferCount = 1;
19007 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19008 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
19009 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
19010 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19011
19012 VkDescriptorPoolSize ds_type_count = {};
19013 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19014 ds_type_count.descriptorCount = 1;
19015
19016 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19017 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19018 ds_pool_ci.pNext = NULL;
19019 ds_pool_ci.maxSets = 1;
19020 ds_pool_ci.poolSizeCount = 1;
19021 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
19022 ds_pool_ci.pPoolSizes = &ds_type_count;
19023
19024 VkDescriptorPool ds_pool;
19025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19026 ASSERT_VK_SUCCESS(err);
19027
19028 VkDescriptorSetLayoutBinding dsl_binding = {};
19029 dsl_binding.binding = 2;
19030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19031 dsl_binding.descriptorCount = 1;
19032 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19033 dsl_binding.pImmutableSamplers = NULL;
19034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19036 ds_layout_ci.pNext = NULL;
19037 ds_layout_ci.bindingCount = 1;
19038 ds_layout_ci.pBindings = &dsl_binding;
19039 VkDescriptorSetLayout ds_layout;
19040 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19041 ASSERT_VK_SUCCESS(err);
19042
19043 VkDescriptorSet descriptor_sets[3] = {};
19044 VkDescriptorSetAllocateInfo alloc_info = {};
19045 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19046 alloc_info.descriptorSetCount = 1;
19047 alloc_info.descriptorPool = ds_pool;
19048 alloc_info.pSetLayouts = &ds_layout;
19049 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
19050 ASSERT_VK_SUCCESS(err);
19051 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
19052 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19053 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19054
19055 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
19056
19057 m_errorMonitor->VerifyNotFound();
19058}
19059
Tony Barbour626994c2017-02-08 15:29:37 -070019060TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070019061 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070019062
19063 m_errorMonitor->ExpectSuccess();
19064
19065 ASSERT_NO_FATAL_FAILURE(InitState());
19066 VkCommandBuffer cmd_bufs[4];
19067 VkCommandBufferAllocateInfo alloc_info;
19068 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19069 alloc_info.pNext = NULL;
19070 alloc_info.commandBufferCount = 4;
19071 alloc_info.commandPool = m_commandPool;
19072 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19073 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
19074 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -070019075 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
19076 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
19077 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070019078 ASSERT_TRUE(image.initialized());
19079 VkCommandBufferBeginInfo cb_binfo;
19080 cb_binfo.pNext = NULL;
19081 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19082 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
19083 cb_binfo.flags = 0;
19084 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
19085 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
19086 VkImageMemoryBarrier img_barrier = {};
19087 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19088 img_barrier.pNext = NULL;
19089 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19090 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19091 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19092 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
19093 img_barrier.image = image.handle();
19094 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19095 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19096 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19097 img_barrier.subresourceRange.baseArrayLayer = 0;
19098 img_barrier.subresourceRange.baseMipLevel = 0;
19099 img_barrier.subresourceRange.layerCount = 1;
19100 img_barrier.subresourceRange.levelCount = 1;
19101 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19102 &img_barrier);
19103 vkEndCommandBuffer(cmd_bufs[0]);
19104 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
19105 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
19106 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19107 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19108 &img_barrier);
19109 vkEndCommandBuffer(cmd_bufs[1]);
19110 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
19111 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19112 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19113 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19114 &img_barrier);
19115 vkEndCommandBuffer(cmd_bufs[2]);
19116 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19117 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19118 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19119 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19120 &img_barrier);
19121 vkEndCommandBuffer(cmd_bufs[3]);
19122
19123 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19124 VkSemaphore semaphore1, semaphore2;
19125 VkSemaphoreCreateInfo semaphore_create_info{};
19126 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19127 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19128 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19129 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19130 VkSubmitInfo submit_info[3];
19131 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19132 submit_info[0].pNext = nullptr;
19133 submit_info[0].commandBufferCount = 1;
19134 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19135 submit_info[0].signalSemaphoreCount = 1;
19136 submit_info[0].pSignalSemaphores = &semaphore1;
19137 submit_info[0].waitSemaphoreCount = 0;
19138 submit_info[0].pWaitDstStageMask = nullptr;
19139 submit_info[0].pWaitDstStageMask = flags;
19140 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19141 submit_info[1].pNext = nullptr;
19142 submit_info[1].commandBufferCount = 1;
19143 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19144 submit_info[1].waitSemaphoreCount = 1;
19145 submit_info[1].pWaitSemaphores = &semaphore1;
19146 submit_info[1].signalSemaphoreCount = 1;
19147 submit_info[1].pSignalSemaphores = &semaphore2;
19148 submit_info[1].pWaitDstStageMask = flags;
19149 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19150 submit_info[2].pNext = nullptr;
19151 submit_info[2].commandBufferCount = 2;
19152 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19153 submit_info[2].waitSemaphoreCount = 1;
19154 submit_info[2].pWaitSemaphores = &semaphore2;
19155 submit_info[2].signalSemaphoreCount = 0;
19156 submit_info[2].pSignalSemaphores = nullptr;
19157 submit_info[2].pWaitDstStageMask = flags;
19158 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19159 vkQueueWaitIdle(m_device->m_queue);
19160
19161 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19162 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19163 m_errorMonitor->VerifyNotFound();
19164}
19165
Tobin Ehlis953e8392016-11-17 10:54:13 -070019166TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19167 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19168 // We previously had a bug where dynamic offset of inactive bindings was still being used
19169 VkResult err;
19170 m_errorMonitor->ExpectSuccess();
19171
19172 ASSERT_NO_FATAL_FAILURE(InitState());
19173 ASSERT_NO_FATAL_FAILURE(InitViewport());
19174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19175
19176 VkDescriptorPoolSize ds_type_count = {};
19177 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19178 ds_type_count.descriptorCount = 3;
19179
19180 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19181 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19182 ds_pool_ci.pNext = NULL;
19183 ds_pool_ci.maxSets = 1;
19184 ds_pool_ci.poolSizeCount = 1;
19185 ds_pool_ci.pPoolSizes = &ds_type_count;
19186
19187 VkDescriptorPool ds_pool;
19188 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19189 ASSERT_VK_SUCCESS(err);
19190
19191 const uint32_t BINDING_COUNT = 3;
19192 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019193 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019194 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19195 dsl_binding[0].descriptorCount = 1;
19196 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19197 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019198 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019199 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19200 dsl_binding[1].descriptorCount = 1;
19201 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19202 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019203 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019204 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19205 dsl_binding[2].descriptorCount = 1;
19206 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19207 dsl_binding[2].pImmutableSamplers = NULL;
19208
19209 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19210 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19211 ds_layout_ci.pNext = NULL;
19212 ds_layout_ci.bindingCount = BINDING_COUNT;
19213 ds_layout_ci.pBindings = dsl_binding;
19214 VkDescriptorSetLayout ds_layout;
19215 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19216 ASSERT_VK_SUCCESS(err);
19217
19218 VkDescriptorSet descriptor_set;
19219 VkDescriptorSetAllocateInfo alloc_info = {};
19220 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19221 alloc_info.descriptorSetCount = 1;
19222 alloc_info.descriptorPool = ds_pool;
19223 alloc_info.pSetLayouts = &ds_layout;
19224 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19225 ASSERT_VK_SUCCESS(err);
19226
19227 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19228 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19229 pipeline_layout_ci.pNext = NULL;
19230 pipeline_layout_ci.setLayoutCount = 1;
19231 pipeline_layout_ci.pSetLayouts = &ds_layout;
19232
19233 VkPipelineLayout pipeline_layout;
19234 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19235 ASSERT_VK_SUCCESS(err);
19236
19237 // Create two buffers to update the descriptors with
19238 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19239 uint32_t qfi = 0;
19240 VkBufferCreateInfo buffCI = {};
19241 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19242 buffCI.size = 2048;
19243 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19244 buffCI.queueFamilyIndexCount = 1;
19245 buffCI.pQueueFamilyIndices = &qfi;
19246
19247 VkBuffer dyub1;
19248 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19249 ASSERT_VK_SUCCESS(err);
19250 // buffer2
19251 buffCI.size = 1024;
19252 VkBuffer dyub2;
19253 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19254 ASSERT_VK_SUCCESS(err);
19255 // Allocate memory and bind to buffers
19256 VkMemoryAllocateInfo mem_alloc[2] = {};
19257 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19258 mem_alloc[0].pNext = NULL;
19259 mem_alloc[0].memoryTypeIndex = 0;
19260 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19261 mem_alloc[1].pNext = NULL;
19262 mem_alloc[1].memoryTypeIndex = 0;
19263
19264 VkMemoryRequirements mem_reqs1;
19265 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19266 VkMemoryRequirements mem_reqs2;
19267 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19268 mem_alloc[0].allocationSize = mem_reqs1.size;
19269 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19270 mem_alloc[1].allocationSize = mem_reqs2.size;
19271 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19272 if (!pass) {
19273 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19274 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19275 return;
19276 }
19277
19278 VkDeviceMemory mem1;
19279 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19280 ASSERT_VK_SUCCESS(err);
19281 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19282 ASSERT_VK_SUCCESS(err);
19283 VkDeviceMemory mem2;
19284 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19285 ASSERT_VK_SUCCESS(err);
19286 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19287 ASSERT_VK_SUCCESS(err);
19288 // Update descriptors
19289 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19290 buff_info[0].buffer = dyub1;
19291 buff_info[0].offset = 0;
19292 buff_info[0].range = 256;
19293 buff_info[1].buffer = dyub1;
19294 buff_info[1].offset = 256;
19295 buff_info[1].range = 512;
19296 buff_info[2].buffer = dyub2;
19297 buff_info[2].offset = 0;
19298 buff_info[2].range = 512;
19299
19300 VkWriteDescriptorSet descriptor_write;
19301 memset(&descriptor_write, 0, sizeof(descriptor_write));
19302 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19303 descriptor_write.dstSet = descriptor_set;
19304 descriptor_write.dstBinding = 0;
19305 descriptor_write.descriptorCount = BINDING_COUNT;
19306 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19307 descriptor_write.pBufferInfo = buff_info;
19308
19309 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19310
Tony Barbour552f6c02016-12-21 14:34:07 -070019311 m_commandBuffer->BeginCommandBuffer();
19312 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019313
19314 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019315 char const *vsSource =
19316 "#version 450\n"
19317 "\n"
19318 "out gl_PerVertex { \n"
19319 " vec4 gl_Position;\n"
19320 "};\n"
19321 "void main(){\n"
19322 " gl_Position = vec4(1);\n"
19323 "}\n";
19324 char const *fsSource =
19325 "#version 450\n"
19326 "\n"
19327 "layout(location=0) out vec4 x;\n"
19328 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19329 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19330 "void main(){\n"
19331 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19332 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19335 VkPipelineObj pipe(m_device);
19336 pipe.SetViewport(m_viewports);
19337 pipe.SetScissor(m_scissors);
19338 pipe.AddShader(&vs);
19339 pipe.AddShader(&fs);
19340 pipe.AddColorAttachment();
19341 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19342
19343 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19344 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19345 // we used to have a bug in this case.
19346 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19347 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19348 &descriptor_set, BINDING_COUNT, dyn_off);
19349 Draw(1, 0, 0, 0);
19350 m_errorMonitor->VerifyNotFound();
19351
19352 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19353 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19354 vkFreeMemory(m_device->device(), mem1, NULL);
19355 vkFreeMemory(m_device->device(), mem2, NULL);
19356
19357 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19359 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19360}
19361
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019363 TEST_DESCRIPTION(
19364 "Ensure that validations handling of non-coherent memory "
19365 "mapping while using VK_WHOLE_SIZE does not cause access "
19366 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019367 VkResult err;
19368 uint8_t *pData;
19369 ASSERT_NO_FATAL_FAILURE(InitState());
19370
19371 VkDeviceMemory mem;
19372 VkMemoryRequirements mem_reqs;
19373 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019374 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019375 VkMemoryAllocateInfo alloc_info = {};
19376 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19377 alloc_info.pNext = NULL;
19378 alloc_info.memoryTypeIndex = 0;
19379
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019380 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019381 alloc_info.allocationSize = allocation_size;
19382
19383 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19384 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 -070019385 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019386 if (!pass) {
19387 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019388 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19389 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019390 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019391 pass = m_device->phy().set_memory_type(
19392 mem_reqs.memoryTypeBits, &alloc_info,
19393 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19394 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019395 if (!pass) {
19396 return;
19397 }
19398 }
19399 }
19400
19401 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19402 ASSERT_VK_SUCCESS(err);
19403
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019404 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019405 m_errorMonitor->ExpectSuccess();
19406 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19407 ASSERT_VK_SUCCESS(err);
19408 VkMappedMemoryRange mmr = {};
19409 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19410 mmr.memory = mem;
19411 mmr.offset = 0;
19412 mmr.size = VK_WHOLE_SIZE;
19413 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19414 ASSERT_VK_SUCCESS(err);
19415 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19416 ASSERT_VK_SUCCESS(err);
19417 m_errorMonitor->VerifyNotFound();
19418 vkUnmapMemory(m_device->device(), mem);
19419
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019420 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019421 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019422 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019423 ASSERT_VK_SUCCESS(err);
19424 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19425 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019426 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019427 mmr.size = VK_WHOLE_SIZE;
19428 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19429 ASSERT_VK_SUCCESS(err);
19430 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19431 ASSERT_VK_SUCCESS(err);
19432 m_errorMonitor->VerifyNotFound();
19433 vkUnmapMemory(m_device->device(), mem);
19434
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019435 // Map with offset and size
19436 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019437 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019438 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019439 ASSERT_VK_SUCCESS(err);
19440 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19441 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019442 mmr.offset = 4 * atom_size;
19443 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019444 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19445 ASSERT_VK_SUCCESS(err);
19446 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19447 ASSERT_VK_SUCCESS(err);
19448 m_errorMonitor->VerifyNotFound();
19449 vkUnmapMemory(m_device->device(), mem);
19450
19451 // Map without offset and flush WHOLE_SIZE with two separate offsets
19452 m_errorMonitor->ExpectSuccess();
19453 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19454 ASSERT_VK_SUCCESS(err);
19455 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19456 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019457 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019458 mmr.size = VK_WHOLE_SIZE;
19459 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19460 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019461 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019462 mmr.size = VK_WHOLE_SIZE;
19463 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19464 ASSERT_VK_SUCCESS(err);
19465 m_errorMonitor->VerifyNotFound();
19466 vkUnmapMemory(m_device->device(), mem);
19467
19468 vkFreeMemory(m_device->device(), mem, NULL);
19469}
19470
19471// This is a positive test. We used to expect error in this case but spec now allows it
19472TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19473 m_errorMonitor->ExpectSuccess();
19474 vk_testing::Fence testFence;
19475 VkFenceCreateInfo fenceInfo = {};
19476 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19477 fenceInfo.pNext = NULL;
19478
19479 ASSERT_NO_FATAL_FAILURE(InitState());
19480 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019481 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019482 VkResult result = vkResetFences(m_device->device(), 1, fences);
19483 ASSERT_VK_SUCCESS(result);
19484
19485 m_errorMonitor->VerifyNotFound();
19486}
19487
19488TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19489 m_errorMonitor->ExpectSuccess();
19490
19491 ASSERT_NO_FATAL_FAILURE(InitState());
19492 VkResult err;
19493
19494 // Record (empty!) command buffer that can be submitted multiple times
19495 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019496 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19497 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019498 m_commandBuffer->BeginCommandBuffer(&cbbi);
19499 m_commandBuffer->EndCommandBuffer();
19500
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019501 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019502 VkFence fence;
19503 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19504 ASSERT_VK_SUCCESS(err);
19505
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019506 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019507 VkSemaphore s1, s2;
19508 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19509 ASSERT_VK_SUCCESS(err);
19510 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19511 ASSERT_VK_SUCCESS(err);
19512
19513 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019514 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019515 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19516 ASSERT_VK_SUCCESS(err);
19517
19518 // Submit CB again, signaling s2.
19519 si.pSignalSemaphores = &s2;
19520 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19521 ASSERT_VK_SUCCESS(err);
19522
19523 // Wait for fence.
19524 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19525 ASSERT_VK_SUCCESS(err);
19526
19527 // CB is still in flight from second submission, but semaphore s1 is no
19528 // longer in flight. delete it.
19529 vkDestroySemaphore(m_device->device(), s1, nullptr);
19530
19531 m_errorMonitor->VerifyNotFound();
19532
19533 // Force device idle and clean up remaining objects
19534 vkDeviceWaitIdle(m_device->device());
19535 vkDestroySemaphore(m_device->device(), s2, nullptr);
19536 vkDestroyFence(m_device->device(), fence, nullptr);
19537}
19538
19539TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19540 m_errorMonitor->ExpectSuccess();
19541
19542 ASSERT_NO_FATAL_FAILURE(InitState());
19543 VkResult err;
19544
19545 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019546 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019547 VkFence f1;
19548 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19549 ASSERT_VK_SUCCESS(err);
19550
19551 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019552 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019553 VkFence f2;
19554 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19555 ASSERT_VK_SUCCESS(err);
19556
19557 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019558 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019559 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19560
19561 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019562 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019563 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19564
19565 // Should have both retired!
19566 vkDestroyFence(m_device->device(), f1, nullptr);
19567 vkDestroyFence(m_device->device(), f2, nullptr);
19568
19569 m_errorMonitor->VerifyNotFound();
19570}
19571
19572TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019573 TEST_DESCRIPTION(
19574 "Verify that creating an image view from an image with valid usage "
19575 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019576
19577 ASSERT_NO_FATAL_FAILURE(InitState());
19578
19579 m_errorMonitor->ExpectSuccess();
19580 // Verify that we can create a view with usage INPUT_ATTACHMENT
19581 VkImageObj image(m_device);
19582 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19583 ASSERT_TRUE(image.initialized());
19584 VkImageView imageView;
19585 VkImageViewCreateInfo ivci = {};
19586 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19587 ivci.image = image.handle();
19588 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19589 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19590 ivci.subresourceRange.layerCount = 1;
19591 ivci.subresourceRange.baseMipLevel = 0;
19592 ivci.subresourceRange.levelCount = 1;
19593 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19594
19595 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19596 m_errorMonitor->VerifyNotFound();
19597 vkDestroyImageView(m_device->device(), imageView, NULL);
19598}
19599
19600// This is a positive test. No failures are expected.
19601TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019602 TEST_DESCRIPTION(
19603 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19604 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019605
19606 ASSERT_NO_FATAL_FAILURE(InitState());
19607
19608 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019609 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019610
19611 m_errorMonitor->ExpectSuccess();
19612
19613 VkImage image;
19614 VkImageCreateInfo image_create_info = {};
19615 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19616 image_create_info.pNext = NULL;
19617 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19618 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19619 image_create_info.extent.width = 64;
19620 image_create_info.extent.height = 64;
19621 image_create_info.extent.depth = 1;
19622 image_create_info.mipLevels = 1;
19623 image_create_info.arrayLayers = 1;
19624 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19625 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19626 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19627 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19628 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19629 ASSERT_VK_SUCCESS(err);
19630
19631 VkMemoryRequirements memory_reqs;
19632 VkDeviceMemory memory_one, memory_two;
19633 bool pass;
19634 VkMemoryAllocateInfo memory_info = {};
19635 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19636 memory_info.pNext = NULL;
19637 memory_info.allocationSize = 0;
19638 memory_info.memoryTypeIndex = 0;
19639 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19640 // Find an image big enough to allow sparse mapping of 2 memory regions
19641 // Increase the image size until it is at least twice the
19642 // size of the required alignment, to ensure we can bind both
19643 // allocated memory blocks to the image on aligned offsets.
19644 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19645 vkDestroyImage(m_device->device(), image, nullptr);
19646 image_create_info.extent.width *= 2;
19647 image_create_info.extent.height *= 2;
19648 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19649 ASSERT_VK_SUCCESS(err);
19650 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19651 }
19652 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19653 // at the end of the first
19654 memory_info.allocationSize = memory_reqs.alignment;
19655 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19656 ASSERT_TRUE(pass);
19657 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19658 ASSERT_VK_SUCCESS(err);
19659 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19660 ASSERT_VK_SUCCESS(err);
19661 VkSparseMemoryBind binds[2];
19662 binds[0].flags = 0;
19663 binds[0].memory = memory_one;
19664 binds[0].memoryOffset = 0;
19665 binds[0].resourceOffset = 0;
19666 binds[0].size = memory_info.allocationSize;
19667 binds[1].flags = 0;
19668 binds[1].memory = memory_two;
19669 binds[1].memoryOffset = 0;
19670 binds[1].resourceOffset = memory_info.allocationSize;
19671 binds[1].size = memory_info.allocationSize;
19672
19673 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19674 opaqueBindInfo.image = image;
19675 opaqueBindInfo.bindCount = 2;
19676 opaqueBindInfo.pBinds = binds;
19677
19678 VkFence fence = VK_NULL_HANDLE;
19679 VkBindSparseInfo bindSparseInfo = {};
19680 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19681 bindSparseInfo.imageOpaqueBindCount = 1;
19682 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19683
19684 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19685 vkQueueWaitIdle(m_device->m_queue);
19686 vkDestroyImage(m_device->device(), image, NULL);
19687 vkFreeMemory(m_device->device(), memory_one, NULL);
19688 vkFreeMemory(m_device->device(), memory_two, NULL);
19689 m_errorMonitor->VerifyNotFound();
19690}
19691
19692TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019693 TEST_DESCRIPTION(
19694 "Ensure that CmdBeginRenderPass with an attachment's "
19695 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19696 "the command buffer has prior knowledge of that "
19697 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019698
19699 m_errorMonitor->ExpectSuccess();
19700
19701 ASSERT_NO_FATAL_FAILURE(InitState());
19702
19703 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019704 VkAttachmentDescription attachment = {0,
19705 VK_FORMAT_R8G8B8A8_UNORM,
19706 VK_SAMPLE_COUNT_1_BIT,
19707 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19708 VK_ATTACHMENT_STORE_OP_STORE,
19709 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19710 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19711 VK_IMAGE_LAYOUT_UNDEFINED,
19712 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019713
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019714 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019715
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019716 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019717
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019718 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019719
19720 VkRenderPass rp;
19721 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19722 ASSERT_VK_SUCCESS(err);
19723
19724 // A compatible framebuffer.
19725 VkImageObj image(m_device);
19726 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19727 ASSERT_TRUE(image.initialized());
19728
19729 VkImageViewCreateInfo ivci = {
19730 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19731 nullptr,
19732 0,
19733 image.handle(),
19734 VK_IMAGE_VIEW_TYPE_2D,
19735 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019736 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19737 VK_COMPONENT_SWIZZLE_IDENTITY},
19738 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019739 };
19740 VkImageView view;
19741 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19742 ASSERT_VK_SUCCESS(err);
19743
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019744 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019745 VkFramebuffer fb;
19746 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19747 ASSERT_VK_SUCCESS(err);
19748
19749 // Record a single command buffer which uses this renderpass twice. The
19750 // bug is triggered at the beginning of the second renderpass, when the
19751 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019752 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 -070019753 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019754 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19755 vkCmdEndRenderPass(m_commandBuffer->handle());
19756 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19757
19758 m_errorMonitor->VerifyNotFound();
19759
19760 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019761 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019762
19763 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19764 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19765 vkDestroyImageView(m_device->device(), view, nullptr);
19766}
19767
19768TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019769 TEST_DESCRIPTION(
19770 "This test should pass. Create a Framebuffer and "
19771 "command buffer, bind them together, then destroy "
19772 "command pool and framebuffer and verify there are no "
19773 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019774
19775 m_errorMonitor->ExpectSuccess();
19776
19777 ASSERT_NO_FATAL_FAILURE(InitState());
19778
19779 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019780 VkAttachmentDescription attachment = {0,
19781 VK_FORMAT_R8G8B8A8_UNORM,
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_UNDEFINED,
19788 VK_IMAGE_LAYOUT_COLOR_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_COLOR_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, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019793
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019794 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019795
19796 VkRenderPass rp;
19797 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19798 ASSERT_VK_SUCCESS(err);
19799
19800 // A compatible framebuffer.
19801 VkImageObj image(m_device);
19802 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19803 ASSERT_TRUE(image.initialized());
19804
19805 VkImageViewCreateInfo ivci = {
19806 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19807 nullptr,
19808 0,
19809 image.handle(),
19810 VK_IMAGE_VIEW_TYPE_2D,
19811 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019812 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19813 VK_COMPONENT_SWIZZLE_IDENTITY},
19814 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019815 };
19816 VkImageView view;
19817 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19818 ASSERT_VK_SUCCESS(err);
19819
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019820 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019821 VkFramebuffer fb;
19822 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19823 ASSERT_VK_SUCCESS(err);
19824
19825 // Explicitly create a command buffer to bind the FB to so that we can then
19826 // destroy the command pool in order to implicitly free command buffer
19827 VkCommandPool command_pool;
19828 VkCommandPoolCreateInfo pool_create_info{};
19829 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19830 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19831 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19832 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19833
19834 VkCommandBuffer command_buffer;
19835 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19836 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19837 command_buffer_allocate_info.commandPool = command_pool;
19838 command_buffer_allocate_info.commandBufferCount = 1;
19839 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19840 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19841
19842 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019843 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 -060019844 VkCommandBufferBeginInfo begin_info{};
19845 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19846 vkBeginCommandBuffer(command_buffer, &begin_info);
19847
19848 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19849 vkCmdEndRenderPass(command_buffer);
19850 vkEndCommandBuffer(command_buffer);
19851 vkDestroyImageView(m_device->device(), view, nullptr);
19852 // Destroy command pool to implicitly free command buffer
19853 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19854 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19855 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19856 m_errorMonitor->VerifyNotFound();
19857}
19858
19859TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019860 TEST_DESCRIPTION(
19861 "Ensure that CmdBeginRenderPass applies the layout "
19862 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019863
19864 m_errorMonitor->ExpectSuccess();
19865
19866 ASSERT_NO_FATAL_FAILURE(InitState());
19867
19868 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019869 VkAttachmentDescription attachment = {0,
19870 VK_FORMAT_R8G8B8A8_UNORM,
19871 VK_SAMPLE_COUNT_1_BIT,
19872 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19873 VK_ATTACHMENT_STORE_OP_STORE,
19874 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19875 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19876 VK_IMAGE_LAYOUT_UNDEFINED,
19877 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019878
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019879 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019880
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019881 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019882
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019883 VkSubpassDependency dep = {0,
19884 0,
19885 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19886 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19887 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19888 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19889 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019890
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019891 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019892
19893 VkResult err;
19894 VkRenderPass rp;
19895 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19896 ASSERT_VK_SUCCESS(err);
19897
19898 // A compatible framebuffer.
19899 VkImageObj image(m_device);
19900 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19901 ASSERT_TRUE(image.initialized());
19902
19903 VkImageViewCreateInfo ivci = {
19904 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19905 nullptr,
19906 0,
19907 image.handle(),
19908 VK_IMAGE_VIEW_TYPE_2D,
19909 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019910 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19911 VK_COMPONENT_SWIZZLE_IDENTITY},
19912 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019913 };
19914 VkImageView view;
19915 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19916 ASSERT_VK_SUCCESS(err);
19917
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019918 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019919 VkFramebuffer fb;
19920 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19921 ASSERT_VK_SUCCESS(err);
19922
19923 // Record a single command buffer which issues a pipeline barrier w/
19924 // image memory barrier for the attachment. This detects the previously
19925 // missing tracking of the subpass layout by throwing a validation error
19926 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019927 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 -070019928 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019929 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19930
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019931 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19932 nullptr,
19933 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19934 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19935 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19936 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19937 VK_QUEUE_FAMILY_IGNORED,
19938 VK_QUEUE_FAMILY_IGNORED,
19939 image.handle(),
19940 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019941 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019942 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19943 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019944
19945 vkCmdEndRenderPass(m_commandBuffer->handle());
19946 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019947 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019948
19949 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19950 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19951 vkDestroyImageView(m_device->device(), view, nullptr);
19952}
19953
19954TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019955 TEST_DESCRIPTION(
19956 "Validate that when an imageView of a depth/stencil image "
19957 "is used as a depth/stencil framebuffer attachment, the "
19958 "aspectMask is ignored and both depth and stencil image "
19959 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019960
19961 VkFormatProperties format_properties;
19962 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19963 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19964 return;
19965 }
19966
19967 m_errorMonitor->ExpectSuccess();
19968
19969 ASSERT_NO_FATAL_FAILURE(InitState());
19970
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019971 VkAttachmentDescription attachment = {0,
19972 VK_FORMAT_D32_SFLOAT_S8_UINT,
19973 VK_SAMPLE_COUNT_1_BIT,
19974 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19975 VK_ATTACHMENT_STORE_OP_STORE,
19976 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19977 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19978 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19979 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019980
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019981 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019982
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019983 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019984
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019985 VkSubpassDependency dep = {0,
19986 0,
19987 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19988 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19989 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19990 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19991 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019992
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019993 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019994
19995 VkResult err;
19996 VkRenderPass rp;
19997 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19998 ASSERT_VK_SUCCESS(err);
19999
20000 VkImageObj image(m_device);
20001 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020002 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020003 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020004 ASSERT_TRUE(image.initialized());
20005 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
20006
20007 VkImageViewCreateInfo ivci = {
20008 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
20009 nullptr,
20010 0,
20011 image.handle(),
20012 VK_IMAGE_VIEW_TYPE_2D,
20013 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020014 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
20015 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020016 };
20017 VkImageView view;
20018 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
20019 ASSERT_VK_SUCCESS(err);
20020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020021 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020022 VkFramebuffer fb;
20023 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20024 ASSERT_VK_SUCCESS(err);
20025
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020026 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 -070020027 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020028 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20029
20030 VkImageMemoryBarrier imb = {};
20031 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20032 imb.pNext = nullptr;
20033 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20034 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20035 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20036 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
20037 imb.srcQueueFamilyIndex = 0;
20038 imb.dstQueueFamilyIndex = 0;
20039 imb.image = image.handle();
20040 imb.subresourceRange.aspectMask = 0x6;
20041 imb.subresourceRange.baseMipLevel = 0;
20042 imb.subresourceRange.levelCount = 0x1;
20043 imb.subresourceRange.baseArrayLayer = 0;
20044 imb.subresourceRange.layerCount = 0x1;
20045
20046 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020047 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
20048 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020049
20050 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070020051 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020052 QueueCommandBuffer(false);
20053 m_errorMonitor->VerifyNotFound();
20054
20055 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20056 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20057 vkDestroyImageView(m_device->device(), view, nullptr);
20058}
20059
20060TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020061 TEST_DESCRIPTION(
20062 "Ensure that layout transitions work correctly without "
20063 "errors, when an attachment reference is "
20064 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020065
20066 m_errorMonitor->ExpectSuccess();
20067
20068 ASSERT_NO_FATAL_FAILURE(InitState());
20069
20070 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020071 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020072
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020073 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020074
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020075 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020076
20077 VkRenderPass rp;
20078 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20079 ASSERT_VK_SUCCESS(err);
20080
20081 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020082 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020083 VkFramebuffer fb;
20084 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20085 ASSERT_VK_SUCCESS(err);
20086
20087 // Record a command buffer which just begins and ends the renderpass. The
20088 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020089 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 -070020090 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020091 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20092 vkCmdEndRenderPass(m_commandBuffer->handle());
20093 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070020094 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020095
20096 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20097 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20098}
20099
20100// This is a positive test. No errors are expected.
20101TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020102 TEST_DESCRIPTION(
20103 "Create a stencil-only attachment with a LOAD_OP set to "
20104 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020105 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070020106 ASSERT_NO_FATAL_FAILURE(InitState());
20107 auto depth_format = find_depth_stencil_format(m_device);
20108 if (!depth_format) {
20109 printf(" No Depth + Stencil format found. Skipped.\n");
20110 return;
20111 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020112 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020113 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020114 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20115 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020116 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20117 return;
20118 }
20119
Tony Barbourf887b162017-03-09 10:06:46 -070020120 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020121 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020122 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020123 VkAttachmentDescription att = {};
20124 VkAttachmentReference ref = {};
20125 att.format = depth_stencil_fmt;
20126 att.samples = VK_SAMPLE_COUNT_1_BIT;
20127 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20128 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20129 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20130 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20131 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20132 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20133
20134 VkClearValue clear;
20135 clear.depthStencil.depth = 1.0;
20136 clear.depthStencil.stencil = 0;
20137 ref.attachment = 0;
20138 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20139
20140 VkSubpassDescription subpass = {};
20141 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20142 subpass.flags = 0;
20143 subpass.inputAttachmentCount = 0;
20144 subpass.pInputAttachments = NULL;
20145 subpass.colorAttachmentCount = 0;
20146 subpass.pColorAttachments = NULL;
20147 subpass.pResolveAttachments = NULL;
20148 subpass.pDepthStencilAttachment = &ref;
20149 subpass.preserveAttachmentCount = 0;
20150 subpass.pPreserveAttachments = NULL;
20151
20152 VkRenderPass rp;
20153 VkRenderPassCreateInfo rp_info = {};
20154 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20155 rp_info.attachmentCount = 1;
20156 rp_info.pAttachments = &att;
20157 rp_info.subpassCount = 1;
20158 rp_info.pSubpasses = &subpass;
20159 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20160 ASSERT_VK_SUCCESS(result);
20161
20162 VkImageView *depthView = m_depthStencil->BindInfo();
20163 VkFramebufferCreateInfo fb_info = {};
20164 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20165 fb_info.pNext = NULL;
20166 fb_info.renderPass = rp;
20167 fb_info.attachmentCount = 1;
20168 fb_info.pAttachments = depthView;
20169 fb_info.width = 100;
20170 fb_info.height = 100;
20171 fb_info.layers = 1;
20172 VkFramebuffer fb;
20173 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20174 ASSERT_VK_SUCCESS(result);
20175
20176 VkRenderPassBeginInfo rpbinfo = {};
20177 rpbinfo.clearValueCount = 1;
20178 rpbinfo.pClearValues = &clear;
20179 rpbinfo.pNext = NULL;
20180 rpbinfo.renderPass = rp;
20181 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20182 rpbinfo.renderArea.extent.width = 100;
20183 rpbinfo.renderArea.extent.height = 100;
20184 rpbinfo.renderArea.offset.x = 0;
20185 rpbinfo.renderArea.offset.y = 0;
20186 rpbinfo.framebuffer = fb;
20187
20188 VkFence fence = {};
20189 VkFenceCreateInfo fence_ci = {};
20190 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20191 fence_ci.pNext = nullptr;
20192 fence_ci.flags = 0;
20193 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20194 ASSERT_VK_SUCCESS(result);
20195
20196 m_commandBuffer->BeginCommandBuffer();
20197 m_commandBuffer->BeginRenderPass(rpbinfo);
20198 m_commandBuffer->EndRenderPass();
20199 m_commandBuffer->EndCommandBuffer();
20200 m_commandBuffer->QueueCommandBuffer(fence);
20201
20202 VkImageObj destImage(m_device);
20203 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 -070020204 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020205 VkImageMemoryBarrier barrier = {};
20206 VkImageSubresourceRange range;
20207 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20208 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20209 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20210 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20211 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20212 barrier.image = m_depthStencil->handle();
20213 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20214 range.baseMipLevel = 0;
20215 range.levelCount = 1;
20216 range.baseArrayLayer = 0;
20217 range.layerCount = 1;
20218 barrier.subresourceRange = range;
20219 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20220 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20221 cmdbuf.BeginCommandBuffer();
20222 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 -070020223 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020224 barrier.srcAccessMask = 0;
20225 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20226 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20227 barrier.image = destImage.handle();
20228 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20229 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 -070020230 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020231 VkImageCopy cregion;
20232 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20233 cregion.srcSubresource.mipLevel = 0;
20234 cregion.srcSubresource.baseArrayLayer = 0;
20235 cregion.srcSubresource.layerCount = 1;
20236 cregion.srcOffset.x = 0;
20237 cregion.srcOffset.y = 0;
20238 cregion.srcOffset.z = 0;
20239 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20240 cregion.dstSubresource.mipLevel = 0;
20241 cregion.dstSubresource.baseArrayLayer = 0;
20242 cregion.dstSubresource.layerCount = 1;
20243 cregion.dstOffset.x = 0;
20244 cregion.dstOffset.y = 0;
20245 cregion.dstOffset.z = 0;
20246 cregion.extent.width = 100;
20247 cregion.extent.height = 100;
20248 cregion.extent.depth = 1;
20249 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020250 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020251 cmdbuf.EndCommandBuffer();
20252
20253 VkSubmitInfo submit_info;
20254 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20255 submit_info.pNext = NULL;
20256 submit_info.waitSemaphoreCount = 0;
20257 submit_info.pWaitSemaphores = NULL;
20258 submit_info.pWaitDstStageMask = NULL;
20259 submit_info.commandBufferCount = 1;
20260 submit_info.pCommandBuffers = &cmdbuf.handle();
20261 submit_info.signalSemaphoreCount = 0;
20262 submit_info.pSignalSemaphores = NULL;
20263
20264 m_errorMonitor->ExpectSuccess();
20265 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20266 m_errorMonitor->VerifyNotFound();
20267
20268 vkQueueWaitIdle(m_device->m_queue);
20269 vkDestroyFence(m_device->device(), fence, nullptr);
20270 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20271 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20272}
20273
20274// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070020275TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
20276 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
20277
20278 m_errorMonitor->ExpectSuccess();
20279
20280 ASSERT_NO_FATAL_FAILURE(InitState());
20281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20282
20283 VkImageMemoryBarrier img_barrier = {};
20284 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20285 img_barrier.pNext = NULL;
20286 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20287 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20288 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20289 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20290 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20291 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20292 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20293 img_barrier.subresourceRange.baseArrayLayer = 0;
20294 img_barrier.subresourceRange.baseMipLevel = 0;
20295 img_barrier.subresourceRange.layerCount = 1;
20296 img_barrier.subresourceRange.levelCount = 1;
20297
20298 {
20299 VkImageObj img_color(m_device);
20300 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20301 ASSERT_TRUE(img_color.initialized());
20302
20303 VkImageObj img_ds1(m_device);
20304 img_ds1.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20305 ASSERT_TRUE(img_ds1.initialized());
20306
20307 VkImageObj img_ds2(m_device);
20308 img_ds2.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20309 ASSERT_TRUE(img_ds2.initialized());
20310
20311 VkImageObj img_xfer_src(m_device);
20312 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
20313 ASSERT_TRUE(img_xfer_src.initialized());
20314
20315 VkImageObj img_xfer_dst(m_device);
20316 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
20317 ASSERT_TRUE(img_xfer_dst.initialized());
20318
20319 VkImageObj img_sampled(m_device);
20320 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
20321 ASSERT_TRUE(img_sampled.initialized());
20322
20323 VkImageObj img_input(m_device);
20324 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20325 ASSERT_TRUE(img_input.initialized());
20326
20327 const struct {
20328 VkImageObj &image_obj;
20329 VkImageLayout old_layout;
20330 VkImageLayout new_layout;
20331 } buffer_layouts[] = {
20332 // clang-format off
20333 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20334 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20335 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20336 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20337 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20338 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20339 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20340 // clang-format on
20341 };
20342 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
20343
20344 m_commandBuffer->BeginCommandBuffer();
20345 for (uint32_t i = 0; i < layout_count; ++i) {
20346 img_barrier.image = buffer_layouts[i].image_obj.handle();
20347 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
20348 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
20349 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
20350 : VK_IMAGE_ASPECT_COLOR_BIT;
20351
20352 img_barrier.oldLayout = buffer_layouts[i].old_layout;
20353 img_barrier.newLayout = buffer_layouts[i].new_layout;
20354 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20355 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20356
20357 img_barrier.oldLayout = buffer_layouts[i].new_layout;
20358 img_barrier.newLayout = buffer_layouts[i].old_layout;
20359 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20360 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20361 }
20362 m_commandBuffer->EndCommandBuffer();
20363
20364 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20365 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20366 }
20367 m_errorMonitor->VerifyNotFound();
20368}
20369
20370// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020371TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20372 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20373
20374 m_errorMonitor->ExpectSuccess();
20375 ASSERT_NO_FATAL_FAILURE(InitState());
20376
20377 VkEvent event;
20378 VkEventCreateInfo event_create_info{};
20379 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20380 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20381
20382 VkCommandPool command_pool;
20383 VkCommandPoolCreateInfo pool_create_info{};
20384 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20385 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20386 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20387 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20388
20389 VkCommandBuffer command_buffer;
20390 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20391 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20392 command_buffer_allocate_info.commandPool = command_pool;
20393 command_buffer_allocate_info.commandBufferCount = 1;
20394 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20395 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20396
20397 VkQueue queue = VK_NULL_HANDLE;
20398 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20399
20400 {
20401 VkCommandBufferBeginInfo begin_info{};
20402 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20403 vkBeginCommandBuffer(command_buffer, &begin_info);
20404
20405 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 -070020406 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020407 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20408 vkEndCommandBuffer(command_buffer);
20409 }
20410 {
20411 VkSubmitInfo submit_info{};
20412 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20413 submit_info.commandBufferCount = 1;
20414 submit_info.pCommandBuffers = &command_buffer;
20415 submit_info.signalSemaphoreCount = 0;
20416 submit_info.pSignalSemaphores = nullptr;
20417 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20418 }
20419 { vkSetEvent(m_device->device(), event); }
20420
20421 vkQueueWaitIdle(queue);
20422
20423 vkDestroyEvent(m_device->device(), event, nullptr);
20424 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20425 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20426
20427 m_errorMonitor->VerifyNotFound();
20428}
20429// This is a positive test. No errors should be generated.
20430TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20431 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20432
20433 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020434 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020435
20436 m_errorMonitor->ExpectSuccess();
20437
20438 VkQueryPool query_pool;
20439 VkQueryPoolCreateInfo query_pool_create_info{};
20440 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20441 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20442 query_pool_create_info.queryCount = 1;
20443 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20444
20445 VkCommandPool command_pool;
20446 VkCommandPoolCreateInfo pool_create_info{};
20447 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20448 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20449 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20450 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20451
20452 VkCommandBuffer command_buffer;
20453 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20454 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20455 command_buffer_allocate_info.commandPool = command_pool;
20456 command_buffer_allocate_info.commandBufferCount = 1;
20457 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20458 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20459
20460 VkCommandBuffer secondary_command_buffer;
20461 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20462 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20463
20464 VkQueue queue = VK_NULL_HANDLE;
20465 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20466
20467 uint32_t qfi = 0;
20468 VkBufferCreateInfo buff_create_info = {};
20469 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20470 buff_create_info.size = 1024;
20471 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20472 buff_create_info.queueFamilyIndexCount = 1;
20473 buff_create_info.pQueueFamilyIndices = &qfi;
20474
20475 VkResult err;
20476 VkBuffer buffer;
20477 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20478 ASSERT_VK_SUCCESS(err);
20479 VkMemoryAllocateInfo mem_alloc = {};
20480 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20481 mem_alloc.pNext = NULL;
20482 mem_alloc.allocationSize = 1024;
20483 mem_alloc.memoryTypeIndex = 0;
20484
20485 VkMemoryRequirements memReqs;
20486 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20487 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20488 if (!pass) {
20489 vkDestroyBuffer(m_device->device(), buffer, NULL);
20490 return;
20491 }
20492
20493 VkDeviceMemory mem;
20494 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20495 ASSERT_VK_SUCCESS(err);
20496 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20497 ASSERT_VK_SUCCESS(err);
20498
20499 VkCommandBufferInheritanceInfo hinfo = {};
20500 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20501 hinfo.renderPass = VK_NULL_HANDLE;
20502 hinfo.subpass = 0;
20503 hinfo.framebuffer = VK_NULL_HANDLE;
20504 hinfo.occlusionQueryEnable = VK_FALSE;
20505 hinfo.queryFlags = 0;
20506 hinfo.pipelineStatistics = 0;
20507
20508 {
20509 VkCommandBufferBeginInfo begin_info{};
20510 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20511 begin_info.pInheritanceInfo = &hinfo;
20512 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20513
20514 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20515 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20516
20517 vkEndCommandBuffer(secondary_command_buffer);
20518
20519 begin_info.pInheritanceInfo = nullptr;
20520 vkBeginCommandBuffer(command_buffer, &begin_info);
20521
20522 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20523 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20524
20525 vkEndCommandBuffer(command_buffer);
20526 }
20527 {
20528 VkSubmitInfo submit_info{};
20529 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20530 submit_info.commandBufferCount = 1;
20531 submit_info.pCommandBuffers = &command_buffer;
20532 submit_info.signalSemaphoreCount = 0;
20533 submit_info.pSignalSemaphores = nullptr;
20534 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20535 }
20536
20537 vkQueueWaitIdle(queue);
20538
20539 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20540 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20541 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20542 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20543 vkDestroyBuffer(m_device->device(), buffer, NULL);
20544 vkFreeMemory(m_device->device(), mem, NULL);
20545
20546 m_errorMonitor->VerifyNotFound();
20547}
20548
20549// This is a positive test. No errors should be generated.
20550TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20551 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20552
20553 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020554 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020555
20556 m_errorMonitor->ExpectSuccess();
20557
20558 VkQueryPool query_pool;
20559 VkQueryPoolCreateInfo query_pool_create_info{};
20560 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20561 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20562 query_pool_create_info.queryCount = 1;
20563 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20564
20565 VkCommandPool command_pool;
20566 VkCommandPoolCreateInfo pool_create_info{};
20567 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20568 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20569 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20570 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20571
20572 VkCommandBuffer command_buffer[2];
20573 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20574 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20575 command_buffer_allocate_info.commandPool = command_pool;
20576 command_buffer_allocate_info.commandBufferCount = 2;
20577 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20578 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20579
20580 VkQueue queue = VK_NULL_HANDLE;
20581 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20582
20583 uint32_t qfi = 0;
20584 VkBufferCreateInfo buff_create_info = {};
20585 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20586 buff_create_info.size = 1024;
20587 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20588 buff_create_info.queueFamilyIndexCount = 1;
20589 buff_create_info.pQueueFamilyIndices = &qfi;
20590
20591 VkResult err;
20592 VkBuffer buffer;
20593 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20594 ASSERT_VK_SUCCESS(err);
20595 VkMemoryAllocateInfo mem_alloc = {};
20596 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20597 mem_alloc.pNext = NULL;
20598 mem_alloc.allocationSize = 1024;
20599 mem_alloc.memoryTypeIndex = 0;
20600
20601 VkMemoryRequirements memReqs;
20602 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20603 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20604 if (!pass) {
20605 vkDestroyBuffer(m_device->device(), buffer, NULL);
20606 return;
20607 }
20608
20609 VkDeviceMemory mem;
20610 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20611 ASSERT_VK_SUCCESS(err);
20612 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20613 ASSERT_VK_SUCCESS(err);
20614
20615 {
20616 VkCommandBufferBeginInfo begin_info{};
20617 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20618 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20619
20620 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20621 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20622
20623 vkEndCommandBuffer(command_buffer[0]);
20624
20625 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20626
20627 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20628
20629 vkEndCommandBuffer(command_buffer[1]);
20630 }
20631 {
20632 VkSubmitInfo submit_info{};
20633 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20634 submit_info.commandBufferCount = 2;
20635 submit_info.pCommandBuffers = command_buffer;
20636 submit_info.signalSemaphoreCount = 0;
20637 submit_info.pSignalSemaphores = nullptr;
20638 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20639 }
20640
20641 vkQueueWaitIdle(queue);
20642
20643 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20644 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20645 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20646 vkDestroyBuffer(m_device->device(), buffer, NULL);
20647 vkFreeMemory(m_device->device(), mem, NULL);
20648
20649 m_errorMonitor->VerifyNotFound();
20650}
20651
Tony Barbourc46924f2016-11-04 11:49:52 -060020652TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020653 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20654
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020655 ASSERT_NO_FATAL_FAILURE(InitState());
20656 VkEvent event;
20657 VkEventCreateInfo event_create_info{};
20658 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20659 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20660
20661 VkCommandPool command_pool;
20662 VkCommandPoolCreateInfo pool_create_info{};
20663 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20664 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20665 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20666 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20667
20668 VkCommandBuffer command_buffer;
20669 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20670 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20671 command_buffer_allocate_info.commandPool = command_pool;
20672 command_buffer_allocate_info.commandBufferCount = 1;
20673 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20674 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20675
20676 VkQueue queue = VK_NULL_HANDLE;
20677 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20678
20679 {
20680 VkCommandBufferBeginInfo begin_info{};
20681 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20682 vkBeginCommandBuffer(command_buffer, &begin_info);
20683
20684 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020685 vkEndCommandBuffer(command_buffer);
20686 }
20687 {
20688 VkSubmitInfo submit_info{};
20689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20690 submit_info.commandBufferCount = 1;
20691 submit_info.pCommandBuffers = &command_buffer;
20692 submit_info.signalSemaphoreCount = 0;
20693 submit_info.pSignalSemaphores = nullptr;
20694 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20695 }
20696 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20698 "that is already in use by a "
20699 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020700 vkSetEvent(m_device->device(), event);
20701 m_errorMonitor->VerifyFound();
20702 }
20703
20704 vkQueueWaitIdle(queue);
20705
20706 vkDestroyEvent(m_device->device(), event, nullptr);
20707 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20708 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20709}
20710
20711// This is a positive test. No errors should be generated.
20712TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020713 TEST_DESCRIPTION(
20714 "Two command buffers with two separate fences are each "
20715 "run through a Submit & WaitForFences cycle 3 times. This "
20716 "previously revealed a bug so running this positive test "
20717 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020718 m_errorMonitor->ExpectSuccess();
20719
20720 ASSERT_NO_FATAL_FAILURE(InitState());
20721 VkQueue queue = VK_NULL_HANDLE;
20722 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20723
20724 static const uint32_t NUM_OBJECTS = 2;
20725 static const uint32_t NUM_FRAMES = 3;
20726 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20727 VkFence fences[NUM_OBJECTS] = {};
20728
20729 VkCommandPool cmd_pool;
20730 VkCommandPoolCreateInfo cmd_pool_ci = {};
20731 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20732 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20733 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20734 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20735 ASSERT_VK_SUCCESS(err);
20736
20737 VkCommandBufferAllocateInfo cmd_buf_info = {};
20738 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20739 cmd_buf_info.commandPool = cmd_pool;
20740 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20741 cmd_buf_info.commandBufferCount = 1;
20742
20743 VkFenceCreateInfo fence_ci = {};
20744 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20745 fence_ci.pNext = nullptr;
20746 fence_ci.flags = 0;
20747
20748 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20749 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20750 ASSERT_VK_SUCCESS(err);
20751 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20752 ASSERT_VK_SUCCESS(err);
20753 }
20754
20755 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20756 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20757 // Create empty cmd buffer
20758 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20759 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20760
20761 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20762 ASSERT_VK_SUCCESS(err);
20763 err = vkEndCommandBuffer(cmd_buffers[obj]);
20764 ASSERT_VK_SUCCESS(err);
20765
20766 VkSubmitInfo submit_info = {};
20767 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20768 submit_info.commandBufferCount = 1;
20769 submit_info.pCommandBuffers = &cmd_buffers[obj];
20770 // Submit cmd buffer and wait for fence
20771 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20772 ASSERT_VK_SUCCESS(err);
20773 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20774 ASSERT_VK_SUCCESS(err);
20775 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20776 ASSERT_VK_SUCCESS(err);
20777 }
20778 }
20779 m_errorMonitor->VerifyNotFound();
20780 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20781 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20782 vkDestroyFence(m_device->device(), fences[i], nullptr);
20783 }
20784}
20785// This is a positive test. No errors should be generated.
20786TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020787 TEST_DESCRIPTION(
20788 "Two command buffers, each in a separate QueueSubmit call "
20789 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020790
20791 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020792 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020793
20794 m_errorMonitor->ExpectSuccess();
20795
20796 VkSemaphore semaphore;
20797 VkSemaphoreCreateInfo semaphore_create_info{};
20798 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20799 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20800
20801 VkCommandPool command_pool;
20802 VkCommandPoolCreateInfo pool_create_info{};
20803 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20804 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20805 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20806 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20807
20808 VkCommandBuffer command_buffer[2];
20809 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20810 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20811 command_buffer_allocate_info.commandPool = command_pool;
20812 command_buffer_allocate_info.commandBufferCount = 2;
20813 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20814 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20815
20816 VkQueue queue = VK_NULL_HANDLE;
20817 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20818
20819 {
20820 VkCommandBufferBeginInfo begin_info{};
20821 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20822 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20823
20824 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 -070020825 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020826
20827 VkViewport viewport{};
20828 viewport.maxDepth = 1.0f;
20829 viewport.minDepth = 0.0f;
20830 viewport.width = 512;
20831 viewport.height = 512;
20832 viewport.x = 0;
20833 viewport.y = 0;
20834 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20835 vkEndCommandBuffer(command_buffer[0]);
20836 }
20837 {
20838 VkCommandBufferBeginInfo begin_info{};
20839 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20840 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20841
20842 VkViewport viewport{};
20843 viewport.maxDepth = 1.0f;
20844 viewport.minDepth = 0.0f;
20845 viewport.width = 512;
20846 viewport.height = 512;
20847 viewport.x = 0;
20848 viewport.y = 0;
20849 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20850 vkEndCommandBuffer(command_buffer[1]);
20851 }
20852 {
20853 VkSubmitInfo submit_info{};
20854 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20855 submit_info.commandBufferCount = 1;
20856 submit_info.pCommandBuffers = &command_buffer[0];
20857 submit_info.signalSemaphoreCount = 1;
20858 submit_info.pSignalSemaphores = &semaphore;
20859 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20860 }
20861 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020862 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020863 VkSubmitInfo submit_info{};
20864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20865 submit_info.commandBufferCount = 1;
20866 submit_info.pCommandBuffers = &command_buffer[1];
20867 submit_info.waitSemaphoreCount = 1;
20868 submit_info.pWaitSemaphores = &semaphore;
20869 submit_info.pWaitDstStageMask = flags;
20870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20871 }
20872
20873 vkQueueWaitIdle(m_device->m_queue);
20874
20875 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20876 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20877 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20878
20879 m_errorMonitor->VerifyNotFound();
20880}
20881
20882// This is a positive test. No errors should be generated.
20883TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020884 TEST_DESCRIPTION(
20885 "Two command buffers, each in a separate QueueSubmit call "
20886 "submitted on separate queues, the second having a fence"
20887 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020888
20889 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020890 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020891
20892 m_errorMonitor->ExpectSuccess();
20893
20894 VkFence fence;
20895 VkFenceCreateInfo fence_create_info{};
20896 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20897 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20898
20899 VkSemaphore semaphore;
20900 VkSemaphoreCreateInfo semaphore_create_info{};
20901 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20902 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20903
20904 VkCommandPool command_pool;
20905 VkCommandPoolCreateInfo pool_create_info{};
20906 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20907 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20908 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20909 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20910
20911 VkCommandBuffer command_buffer[2];
20912 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20913 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20914 command_buffer_allocate_info.commandPool = command_pool;
20915 command_buffer_allocate_info.commandBufferCount = 2;
20916 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20917 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20918
20919 VkQueue queue = VK_NULL_HANDLE;
20920 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20921
20922 {
20923 VkCommandBufferBeginInfo begin_info{};
20924 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20925 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20926
20927 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 -070020928 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020929
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[0], 0, 1, &viewport);
20938 vkEndCommandBuffer(command_buffer[0]);
20939 }
20940 {
20941 VkCommandBufferBeginInfo begin_info{};
20942 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20943 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20944
20945 VkViewport viewport{};
20946 viewport.maxDepth = 1.0f;
20947 viewport.minDepth = 0.0f;
20948 viewport.width = 512;
20949 viewport.height = 512;
20950 viewport.x = 0;
20951 viewport.y = 0;
20952 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20953 vkEndCommandBuffer(command_buffer[1]);
20954 }
20955 {
20956 VkSubmitInfo submit_info{};
20957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20958 submit_info.commandBufferCount = 1;
20959 submit_info.pCommandBuffers = &command_buffer[0];
20960 submit_info.signalSemaphoreCount = 1;
20961 submit_info.pSignalSemaphores = &semaphore;
20962 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20963 }
20964 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020965 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020966 VkSubmitInfo submit_info{};
20967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20968 submit_info.commandBufferCount = 1;
20969 submit_info.pCommandBuffers = &command_buffer[1];
20970 submit_info.waitSemaphoreCount = 1;
20971 submit_info.pWaitSemaphores = &semaphore;
20972 submit_info.pWaitDstStageMask = flags;
20973 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20974 }
20975
20976 vkQueueWaitIdle(m_device->m_queue);
20977
20978 vkDestroyFence(m_device->device(), fence, nullptr);
20979 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20980 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20981 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20982
20983 m_errorMonitor->VerifyNotFound();
20984}
20985
20986// This is a positive test. No errors should be generated.
20987TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020988 TEST_DESCRIPTION(
20989 "Two command buffers, each in a separate QueueSubmit call "
20990 "submitted on separate queues, the second having a fence"
20991 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020992
20993 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020994 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020995
20996 m_errorMonitor->ExpectSuccess();
20997
20998 VkFence fence;
20999 VkFenceCreateInfo fence_create_info{};
21000 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21001 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21002
21003 VkSemaphore semaphore;
21004 VkSemaphoreCreateInfo semaphore_create_info{};
21005 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21006 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21007
21008 VkCommandPool command_pool;
21009 VkCommandPoolCreateInfo pool_create_info{};
21010 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21011 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21012 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21013 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21014
21015 VkCommandBuffer command_buffer[2];
21016 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21017 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21018 command_buffer_allocate_info.commandPool = command_pool;
21019 command_buffer_allocate_info.commandBufferCount = 2;
21020 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21021 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21022
21023 VkQueue queue = VK_NULL_HANDLE;
21024 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21025
21026 {
21027 VkCommandBufferBeginInfo begin_info{};
21028 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21029 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21030
21031 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 -070021032 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021033
21034 VkViewport viewport{};
21035 viewport.maxDepth = 1.0f;
21036 viewport.minDepth = 0.0f;
21037 viewport.width = 512;
21038 viewport.height = 512;
21039 viewport.x = 0;
21040 viewport.y = 0;
21041 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21042 vkEndCommandBuffer(command_buffer[0]);
21043 }
21044 {
21045 VkCommandBufferBeginInfo begin_info{};
21046 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21047 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21048
21049 VkViewport viewport{};
21050 viewport.maxDepth = 1.0f;
21051 viewport.minDepth = 0.0f;
21052 viewport.width = 512;
21053 viewport.height = 512;
21054 viewport.x = 0;
21055 viewport.y = 0;
21056 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21057 vkEndCommandBuffer(command_buffer[1]);
21058 }
21059 {
21060 VkSubmitInfo submit_info{};
21061 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21062 submit_info.commandBufferCount = 1;
21063 submit_info.pCommandBuffers = &command_buffer[0];
21064 submit_info.signalSemaphoreCount = 1;
21065 submit_info.pSignalSemaphores = &semaphore;
21066 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21067 }
21068 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021069 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021070 VkSubmitInfo submit_info{};
21071 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21072 submit_info.commandBufferCount = 1;
21073 submit_info.pCommandBuffers = &command_buffer[1];
21074 submit_info.waitSemaphoreCount = 1;
21075 submit_info.pWaitSemaphores = &semaphore;
21076 submit_info.pWaitDstStageMask = flags;
21077 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21078 }
21079
21080 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21081 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21082
21083 vkDestroyFence(m_device->device(), fence, nullptr);
21084 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21085 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21086 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21087
21088 m_errorMonitor->VerifyNotFound();
21089}
21090
21091TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021092 ASSERT_NO_FATAL_FAILURE(InitState());
21093 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021094 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021095 return;
21096 }
21097
21098 VkResult err;
21099
21100 m_errorMonitor->ExpectSuccess();
21101
21102 VkQueue q0 = m_device->m_queue;
21103 VkQueue q1 = nullptr;
21104 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
21105 ASSERT_NE(q1, nullptr);
21106
21107 // An (empty) command buffer. We must have work in the first submission --
21108 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021109 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021110 VkCommandPool pool;
21111 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
21112 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021113 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
21114 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021115 VkCommandBuffer cb;
21116 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
21117 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021118 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021119 err = vkBeginCommandBuffer(cb, &cbbi);
21120 ASSERT_VK_SUCCESS(err);
21121 err = vkEndCommandBuffer(cb);
21122 ASSERT_VK_SUCCESS(err);
21123
21124 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021125 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021126 VkSemaphore s;
21127 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
21128 ASSERT_VK_SUCCESS(err);
21129
21130 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021131 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021132
21133 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
21134 ASSERT_VK_SUCCESS(err);
21135
21136 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021137 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021138 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021139
21140 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
21141 ASSERT_VK_SUCCESS(err);
21142
21143 // Wait for q0 idle
21144 err = vkQueueWaitIdle(q0);
21145 ASSERT_VK_SUCCESS(err);
21146
21147 // Command buffer should have been completed (it was on q0); reset the pool.
21148 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
21149
21150 m_errorMonitor->VerifyNotFound();
21151
21152 // Force device completely idle and clean up resources
21153 vkDeviceWaitIdle(m_device->device());
21154 vkDestroyCommandPool(m_device->device(), pool, nullptr);
21155 vkDestroySemaphore(m_device->device(), s, nullptr);
21156}
21157
21158// This is a positive test. No errors should be generated.
21159TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021160 TEST_DESCRIPTION(
21161 "Two command buffers, each in a separate QueueSubmit call "
21162 "submitted on separate queues, the second having a fence, "
21163 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021164
21165 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021166 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021167
21168 m_errorMonitor->ExpectSuccess();
21169
21170 ASSERT_NO_FATAL_FAILURE(InitState());
21171 VkFence fence;
21172 VkFenceCreateInfo fence_create_info{};
21173 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21174 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21175
21176 VkSemaphore semaphore;
21177 VkSemaphoreCreateInfo semaphore_create_info{};
21178 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21179 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21180
21181 VkCommandPool command_pool;
21182 VkCommandPoolCreateInfo pool_create_info{};
21183 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21184 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21185 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21186 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21187
21188 VkCommandBuffer command_buffer[2];
21189 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21190 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21191 command_buffer_allocate_info.commandPool = command_pool;
21192 command_buffer_allocate_info.commandBufferCount = 2;
21193 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21194 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21195
21196 VkQueue queue = VK_NULL_HANDLE;
21197 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21198
21199 {
21200 VkCommandBufferBeginInfo begin_info{};
21201 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21202 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21203
21204 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 -070021205 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021206
21207 VkViewport viewport{};
21208 viewport.maxDepth = 1.0f;
21209 viewport.minDepth = 0.0f;
21210 viewport.width = 512;
21211 viewport.height = 512;
21212 viewport.x = 0;
21213 viewport.y = 0;
21214 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21215 vkEndCommandBuffer(command_buffer[0]);
21216 }
21217 {
21218 VkCommandBufferBeginInfo begin_info{};
21219 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21220 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21221
21222 VkViewport viewport{};
21223 viewport.maxDepth = 1.0f;
21224 viewport.minDepth = 0.0f;
21225 viewport.width = 512;
21226 viewport.height = 512;
21227 viewport.x = 0;
21228 viewport.y = 0;
21229 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21230 vkEndCommandBuffer(command_buffer[1]);
21231 }
21232 {
21233 VkSubmitInfo submit_info{};
21234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21235 submit_info.commandBufferCount = 1;
21236 submit_info.pCommandBuffers = &command_buffer[0];
21237 submit_info.signalSemaphoreCount = 1;
21238 submit_info.pSignalSemaphores = &semaphore;
21239 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21240 }
21241 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021242 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021243 VkSubmitInfo submit_info{};
21244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21245 submit_info.commandBufferCount = 1;
21246 submit_info.pCommandBuffers = &command_buffer[1];
21247 submit_info.waitSemaphoreCount = 1;
21248 submit_info.pWaitSemaphores = &semaphore;
21249 submit_info.pWaitDstStageMask = flags;
21250 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21251 }
21252
21253 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21254
21255 vkDestroyFence(m_device->device(), fence, nullptr);
21256 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21257 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21258 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21259
21260 m_errorMonitor->VerifyNotFound();
21261}
21262
21263// This is a positive test. No errors should be generated.
21264TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021265 TEST_DESCRIPTION(
21266 "Two command buffers, each in a separate QueueSubmit call "
21267 "on the same queue, sharing a signal/wait semaphore, the "
21268 "second having a fence, "
21269 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021270
21271 m_errorMonitor->ExpectSuccess();
21272
21273 ASSERT_NO_FATAL_FAILURE(InitState());
21274 VkFence fence;
21275 VkFenceCreateInfo fence_create_info{};
21276 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21277 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21278
21279 VkSemaphore semaphore;
21280 VkSemaphoreCreateInfo semaphore_create_info{};
21281 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21282 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21283
21284 VkCommandPool command_pool;
21285 VkCommandPoolCreateInfo pool_create_info{};
21286 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21287 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21288 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21290
21291 VkCommandBuffer command_buffer[2];
21292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21294 command_buffer_allocate_info.commandPool = command_pool;
21295 command_buffer_allocate_info.commandBufferCount = 2;
21296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21298
21299 {
21300 VkCommandBufferBeginInfo begin_info{};
21301 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21302 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21303
21304 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 -070021305 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021306
21307 VkViewport viewport{};
21308 viewport.maxDepth = 1.0f;
21309 viewport.minDepth = 0.0f;
21310 viewport.width = 512;
21311 viewport.height = 512;
21312 viewport.x = 0;
21313 viewport.y = 0;
21314 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21315 vkEndCommandBuffer(command_buffer[0]);
21316 }
21317 {
21318 VkCommandBufferBeginInfo begin_info{};
21319 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21320 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21321
21322 VkViewport viewport{};
21323 viewport.maxDepth = 1.0f;
21324 viewport.minDepth = 0.0f;
21325 viewport.width = 512;
21326 viewport.height = 512;
21327 viewport.x = 0;
21328 viewport.y = 0;
21329 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21330 vkEndCommandBuffer(command_buffer[1]);
21331 }
21332 {
21333 VkSubmitInfo submit_info{};
21334 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21335 submit_info.commandBufferCount = 1;
21336 submit_info.pCommandBuffers = &command_buffer[0];
21337 submit_info.signalSemaphoreCount = 1;
21338 submit_info.pSignalSemaphores = &semaphore;
21339 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21340 }
21341 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021342 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021343 VkSubmitInfo submit_info{};
21344 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21345 submit_info.commandBufferCount = 1;
21346 submit_info.pCommandBuffers = &command_buffer[1];
21347 submit_info.waitSemaphoreCount = 1;
21348 submit_info.pWaitSemaphores = &semaphore;
21349 submit_info.pWaitDstStageMask = flags;
21350 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21351 }
21352
21353 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21354
21355 vkDestroyFence(m_device->device(), fence, nullptr);
21356 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21357 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21358 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21359
21360 m_errorMonitor->VerifyNotFound();
21361}
21362
21363// This is a positive test. No errors should be generated.
21364TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021365 TEST_DESCRIPTION(
21366 "Two command buffers, each in a separate QueueSubmit call "
21367 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21368 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021369
21370 m_errorMonitor->ExpectSuccess();
21371
21372 ASSERT_NO_FATAL_FAILURE(InitState());
21373 VkFence fence;
21374 VkFenceCreateInfo fence_create_info{};
21375 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21376 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21377
21378 VkCommandPool command_pool;
21379 VkCommandPoolCreateInfo pool_create_info{};
21380 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21381 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21382 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21383 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21384
21385 VkCommandBuffer command_buffer[2];
21386 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21387 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21388 command_buffer_allocate_info.commandPool = command_pool;
21389 command_buffer_allocate_info.commandBufferCount = 2;
21390 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21391 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21392
21393 {
21394 VkCommandBufferBeginInfo begin_info{};
21395 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21396 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21397
21398 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 -070021399 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021400
21401 VkViewport viewport{};
21402 viewport.maxDepth = 1.0f;
21403 viewport.minDepth = 0.0f;
21404 viewport.width = 512;
21405 viewport.height = 512;
21406 viewport.x = 0;
21407 viewport.y = 0;
21408 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21409 vkEndCommandBuffer(command_buffer[0]);
21410 }
21411 {
21412 VkCommandBufferBeginInfo begin_info{};
21413 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21414 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21415
21416 VkViewport viewport{};
21417 viewport.maxDepth = 1.0f;
21418 viewport.minDepth = 0.0f;
21419 viewport.width = 512;
21420 viewport.height = 512;
21421 viewport.x = 0;
21422 viewport.y = 0;
21423 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21424 vkEndCommandBuffer(command_buffer[1]);
21425 }
21426 {
21427 VkSubmitInfo submit_info{};
21428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21429 submit_info.commandBufferCount = 1;
21430 submit_info.pCommandBuffers = &command_buffer[0];
21431 submit_info.signalSemaphoreCount = 0;
21432 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21433 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21434 }
21435 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021436 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021437 VkSubmitInfo submit_info{};
21438 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21439 submit_info.commandBufferCount = 1;
21440 submit_info.pCommandBuffers = &command_buffer[1];
21441 submit_info.waitSemaphoreCount = 0;
21442 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21443 submit_info.pWaitDstStageMask = flags;
21444 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21445 }
21446
21447 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21448
21449 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21450 ASSERT_VK_SUCCESS(err);
21451
21452 vkDestroyFence(m_device->device(), fence, nullptr);
21453 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21454 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21455
21456 m_errorMonitor->VerifyNotFound();
21457}
21458
21459// This is a positive test. No errors should be generated.
21460TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021461 TEST_DESCRIPTION(
21462 "Two command buffers, each in a separate QueueSubmit call "
21463 "on the same queue, the second having a fence, followed "
21464 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021465
21466 m_errorMonitor->ExpectSuccess();
21467
21468 ASSERT_NO_FATAL_FAILURE(InitState());
21469 VkFence fence;
21470 VkFenceCreateInfo fence_create_info{};
21471 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21472 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21473
21474 VkCommandPool command_pool;
21475 VkCommandPoolCreateInfo pool_create_info{};
21476 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21477 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21478 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21479 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21480
21481 VkCommandBuffer command_buffer[2];
21482 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21483 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21484 command_buffer_allocate_info.commandPool = command_pool;
21485 command_buffer_allocate_info.commandBufferCount = 2;
21486 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21487 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21488
21489 {
21490 VkCommandBufferBeginInfo begin_info{};
21491 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21492 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21493
21494 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 -070021495 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021496
21497 VkViewport viewport{};
21498 viewport.maxDepth = 1.0f;
21499 viewport.minDepth = 0.0f;
21500 viewport.width = 512;
21501 viewport.height = 512;
21502 viewport.x = 0;
21503 viewport.y = 0;
21504 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21505 vkEndCommandBuffer(command_buffer[0]);
21506 }
21507 {
21508 VkCommandBufferBeginInfo begin_info{};
21509 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21510 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21511
21512 VkViewport viewport{};
21513 viewport.maxDepth = 1.0f;
21514 viewport.minDepth = 0.0f;
21515 viewport.width = 512;
21516 viewport.height = 512;
21517 viewport.x = 0;
21518 viewport.y = 0;
21519 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21520 vkEndCommandBuffer(command_buffer[1]);
21521 }
21522 {
21523 VkSubmitInfo submit_info{};
21524 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21525 submit_info.commandBufferCount = 1;
21526 submit_info.pCommandBuffers = &command_buffer[0];
21527 submit_info.signalSemaphoreCount = 0;
21528 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21530 }
21531 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021532 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021533 VkSubmitInfo submit_info{};
21534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21535 submit_info.commandBufferCount = 1;
21536 submit_info.pCommandBuffers = &command_buffer[1];
21537 submit_info.waitSemaphoreCount = 0;
21538 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21539 submit_info.pWaitDstStageMask = flags;
21540 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21541 }
21542
21543 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21544
21545 vkDestroyFence(m_device->device(), fence, nullptr);
21546 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21547 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21548
21549 m_errorMonitor->VerifyNotFound();
21550}
21551
21552// This is a positive test. No errors should be generated.
21553TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021554 TEST_DESCRIPTION(
21555 "Two command buffers each in a separate SubmitInfo sent in a single "
21556 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021557 ASSERT_NO_FATAL_FAILURE(InitState());
21558
21559 m_errorMonitor->ExpectSuccess();
21560
21561 VkFence fence;
21562 VkFenceCreateInfo fence_create_info{};
21563 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21564 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21565
21566 VkSemaphore semaphore;
21567 VkSemaphoreCreateInfo semaphore_create_info{};
21568 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21569 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21570
21571 VkCommandPool command_pool;
21572 VkCommandPoolCreateInfo pool_create_info{};
21573 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21574 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21575 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21576 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21577
21578 VkCommandBuffer command_buffer[2];
21579 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21580 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21581 command_buffer_allocate_info.commandPool = command_pool;
21582 command_buffer_allocate_info.commandBufferCount = 2;
21583 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21584 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21585
21586 {
21587 VkCommandBufferBeginInfo begin_info{};
21588 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21589 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21590
21591 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 -070021592 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021593
21594 VkViewport viewport{};
21595 viewport.maxDepth = 1.0f;
21596 viewport.minDepth = 0.0f;
21597 viewport.width = 512;
21598 viewport.height = 512;
21599 viewport.x = 0;
21600 viewport.y = 0;
21601 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21602 vkEndCommandBuffer(command_buffer[0]);
21603 }
21604 {
21605 VkCommandBufferBeginInfo begin_info{};
21606 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21607 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21608
21609 VkViewport viewport{};
21610 viewport.maxDepth = 1.0f;
21611 viewport.minDepth = 0.0f;
21612 viewport.width = 512;
21613 viewport.height = 512;
21614 viewport.x = 0;
21615 viewport.y = 0;
21616 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21617 vkEndCommandBuffer(command_buffer[1]);
21618 }
21619 {
21620 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021621 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021622
21623 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21624 submit_info[0].pNext = NULL;
21625 submit_info[0].commandBufferCount = 1;
21626 submit_info[0].pCommandBuffers = &command_buffer[0];
21627 submit_info[0].signalSemaphoreCount = 1;
21628 submit_info[0].pSignalSemaphores = &semaphore;
21629 submit_info[0].waitSemaphoreCount = 0;
21630 submit_info[0].pWaitSemaphores = NULL;
21631 submit_info[0].pWaitDstStageMask = 0;
21632
21633 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21634 submit_info[1].pNext = NULL;
21635 submit_info[1].commandBufferCount = 1;
21636 submit_info[1].pCommandBuffers = &command_buffer[1];
21637 submit_info[1].waitSemaphoreCount = 1;
21638 submit_info[1].pWaitSemaphores = &semaphore;
21639 submit_info[1].pWaitDstStageMask = flags;
21640 submit_info[1].signalSemaphoreCount = 0;
21641 submit_info[1].pSignalSemaphores = NULL;
21642 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21643 }
21644
21645 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21646
21647 vkDestroyFence(m_device->device(), fence, nullptr);
21648 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21649 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21650 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21651
21652 m_errorMonitor->VerifyNotFound();
21653}
21654
21655TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21656 m_errorMonitor->ExpectSuccess();
21657
21658 ASSERT_NO_FATAL_FAILURE(InitState());
21659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21660
Tony Barbour552f6c02016-12-21 14:34:07 -070021661 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021662
21663 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21664 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21665 m_errorMonitor->VerifyNotFound();
21666 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21667 m_errorMonitor->VerifyNotFound();
21668 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21669 m_errorMonitor->VerifyNotFound();
21670
21671 m_commandBuffer->EndCommandBuffer();
21672 m_errorMonitor->VerifyNotFound();
21673}
21674
21675TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021676 TEST_DESCRIPTION(
21677 "Positive test where we create a renderpass with an "
21678 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21679 "has a valid layout, and a second subpass then uses a "
21680 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021681 m_errorMonitor->ExpectSuccess();
21682 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021683 auto depth_format = find_depth_stencil_format(m_device);
21684 if (!depth_format) {
21685 printf(" No Depth + Stencil format found. Skipped.\n");
21686 return;
21687 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021688
21689 VkAttachmentReference attach[2] = {};
21690 attach[0].attachment = 0;
21691 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21692 attach[1].attachment = 0;
21693 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21694 VkSubpassDescription subpasses[2] = {};
21695 // First subpass clears DS attach on load
21696 subpasses[0].pDepthStencilAttachment = &attach[0];
21697 // 2nd subpass reads in DS as input attachment
21698 subpasses[1].inputAttachmentCount = 1;
21699 subpasses[1].pInputAttachments = &attach[1];
21700 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021701 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021702 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21703 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21704 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21705 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21706 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21707 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21708 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21709 VkRenderPassCreateInfo rpci = {};
21710 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21711 rpci.attachmentCount = 1;
21712 rpci.pAttachments = &attach_desc;
21713 rpci.subpassCount = 2;
21714 rpci.pSubpasses = subpasses;
21715
21716 // Now create RenderPass and verify no errors
21717 VkRenderPass rp;
21718 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21719 m_errorMonitor->VerifyNotFound();
21720
21721 vkDestroyRenderPass(m_device->device(), rp, NULL);
21722}
21723
Tobin Ehlis01103de2017-02-16 13:22:47 -070021724TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21725 TEST_DESCRIPTION(
21726 "Create a render pass with depth-stencil attachment where layout transition "
21727 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21728 "transition has correctly occurred at queue submit time with no validation errors.");
21729
Tony Barbourf887b162017-03-09 10:06:46 -070021730 ASSERT_NO_FATAL_FAILURE(InitState());
21731 auto depth_format = find_depth_stencil_format(m_device);
21732 if (!depth_format) {
21733 printf(" No Depth + Stencil format found. Skipped.\n");
21734 return;
21735 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021736 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021737 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021738 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21739 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021740 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021741 return;
21742 }
21743
21744 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21746
21747 // A renderpass with one depth/stencil attachment.
21748 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021749 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021750 VK_SAMPLE_COUNT_1_BIT,
21751 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21752 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21753 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21754 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21755 VK_IMAGE_LAYOUT_UNDEFINED,
21756 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21757
21758 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21759
21760 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21761
21762 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21763
21764 VkRenderPass rp;
21765 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21766 ASSERT_VK_SUCCESS(err);
21767 // A compatible ds image.
21768 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021769 image.init(32, 32, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis01103de2017-02-16 13:22:47 -070021770 ASSERT_TRUE(image.initialized());
21771
21772 VkImageViewCreateInfo ivci = {
21773 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21774 nullptr,
21775 0,
21776 image.handle(),
21777 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021778 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021779 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21780 VK_COMPONENT_SWIZZLE_IDENTITY},
21781 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21782 };
21783 VkImageView view;
21784 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21785 ASSERT_VK_SUCCESS(err);
21786
21787 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21788 VkFramebuffer fb;
21789 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21790 ASSERT_VK_SUCCESS(err);
21791
21792 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21793 m_commandBuffer->BeginCommandBuffer();
21794 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21795 vkCmdEndRenderPass(m_commandBuffer->handle());
21796 m_commandBuffer->EndCommandBuffer();
21797 QueueCommandBuffer(false);
21798 m_errorMonitor->VerifyNotFound();
21799
21800 // Cleanup
21801 vkDestroyImageView(m_device->device(), view, NULL);
21802 vkDestroyRenderPass(m_device->device(), rp, NULL);
21803 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21804}
21805
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021806TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021807 TEST_DESCRIPTION(
21808 "Test that pipeline validation accepts matrices passed "
21809 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021810 m_errorMonitor->ExpectSuccess();
21811
21812 ASSERT_NO_FATAL_FAILURE(InitState());
21813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21814
21815 VkVertexInputBindingDescription input_binding;
21816 memset(&input_binding, 0, sizeof(input_binding));
21817
21818 VkVertexInputAttributeDescription input_attribs[2];
21819 memset(input_attribs, 0, sizeof(input_attribs));
21820
21821 for (int i = 0; i < 2; i++) {
21822 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21823 input_attribs[i].location = i;
21824 }
21825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021826 char const *vsSource =
21827 "#version 450\n"
21828 "\n"
21829 "layout(location=0) in mat2x4 x;\n"
21830 "out gl_PerVertex {\n"
21831 " vec4 gl_Position;\n"
21832 "};\n"
21833 "void main(){\n"
21834 " gl_Position = x[0] + x[1];\n"
21835 "}\n";
21836 char const *fsSource =
21837 "#version 450\n"
21838 "\n"
21839 "layout(location=0) out vec4 color;\n"
21840 "void main(){\n"
21841 " color = vec4(1);\n"
21842 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021843
21844 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21845 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21846
21847 VkPipelineObj pipe(m_device);
21848 pipe.AddColorAttachment();
21849 pipe.AddShader(&vs);
21850 pipe.AddShader(&fs);
21851
21852 pipe.AddVertexInputBindings(&input_binding, 1);
21853 pipe.AddVertexInputAttribs(input_attribs, 2);
21854
21855 VkDescriptorSetObj descriptorSet(m_device);
21856 descriptorSet.AppendDummy();
21857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21858
21859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21860
21861 /* expect success */
21862 m_errorMonitor->VerifyNotFound();
21863}
21864
21865TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21866 m_errorMonitor->ExpectSuccess();
21867
21868 ASSERT_NO_FATAL_FAILURE(InitState());
21869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21870
21871 VkVertexInputBindingDescription input_binding;
21872 memset(&input_binding, 0, sizeof(input_binding));
21873
21874 VkVertexInputAttributeDescription input_attribs[2];
21875 memset(input_attribs, 0, sizeof(input_attribs));
21876
21877 for (int i = 0; i < 2; i++) {
21878 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21879 input_attribs[i].location = i;
21880 }
21881
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021882 char const *vsSource =
21883 "#version 450\n"
21884 "\n"
21885 "layout(location=0) in vec4 x[2];\n"
21886 "out gl_PerVertex {\n"
21887 " vec4 gl_Position;\n"
21888 "};\n"
21889 "void main(){\n"
21890 " gl_Position = x[0] + x[1];\n"
21891 "}\n";
21892 char const *fsSource =
21893 "#version 450\n"
21894 "\n"
21895 "layout(location=0) out vec4 color;\n"
21896 "void main(){\n"
21897 " color = vec4(1);\n"
21898 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021899
21900 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21901 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21902
21903 VkPipelineObj pipe(m_device);
21904 pipe.AddColorAttachment();
21905 pipe.AddShader(&vs);
21906 pipe.AddShader(&fs);
21907
21908 pipe.AddVertexInputBindings(&input_binding, 1);
21909 pipe.AddVertexInputAttribs(input_attribs, 2);
21910
21911 VkDescriptorSetObj descriptorSet(m_device);
21912 descriptorSet.AppendDummy();
21913 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21914
21915 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21916
21917 m_errorMonitor->VerifyNotFound();
21918}
21919
21920TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021921 TEST_DESCRIPTION(
21922 "Test that pipeline validation accepts consuming a vertex attribute "
21923 "through multiple vertex shader inputs, each consuming a different "
21924 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021925 m_errorMonitor->ExpectSuccess();
21926
21927 ASSERT_NO_FATAL_FAILURE(InitState());
21928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21929
21930 VkVertexInputBindingDescription input_binding;
21931 memset(&input_binding, 0, sizeof(input_binding));
21932
21933 VkVertexInputAttributeDescription input_attribs[3];
21934 memset(input_attribs, 0, sizeof(input_attribs));
21935
21936 for (int i = 0; i < 3; i++) {
21937 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21938 input_attribs[i].location = i;
21939 }
21940
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021941 char const *vsSource =
21942 "#version 450\n"
21943 "\n"
21944 "layout(location=0) in vec4 x;\n"
21945 "layout(location=1) in vec3 y1;\n"
21946 "layout(location=1, component=3) in float y2;\n"
21947 "layout(location=2) in vec4 z;\n"
21948 "out gl_PerVertex {\n"
21949 " vec4 gl_Position;\n"
21950 "};\n"
21951 "void main(){\n"
21952 " gl_Position = x + vec4(y1, y2) + z;\n"
21953 "}\n";
21954 char const *fsSource =
21955 "#version 450\n"
21956 "\n"
21957 "layout(location=0) out vec4 color;\n"
21958 "void main(){\n"
21959 " color = vec4(1);\n"
21960 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021961
21962 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21963 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21964
21965 VkPipelineObj pipe(m_device);
21966 pipe.AddColorAttachment();
21967 pipe.AddShader(&vs);
21968 pipe.AddShader(&fs);
21969
21970 pipe.AddVertexInputBindings(&input_binding, 1);
21971 pipe.AddVertexInputAttribs(input_attribs, 3);
21972
21973 VkDescriptorSetObj descriptorSet(m_device);
21974 descriptorSet.AppendDummy();
21975 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21976
21977 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21978
21979 m_errorMonitor->VerifyNotFound();
21980}
21981
21982TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21983 m_errorMonitor->ExpectSuccess();
21984
21985 ASSERT_NO_FATAL_FAILURE(InitState());
21986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21987
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021988 char const *vsSource =
21989 "#version 450\n"
21990 "out gl_PerVertex {\n"
21991 " vec4 gl_Position;\n"
21992 "};\n"
21993 "void main(){\n"
21994 " gl_Position = vec4(0);\n"
21995 "}\n";
21996 char const *fsSource =
21997 "#version 450\n"
21998 "\n"
21999 "layout(location=0) out vec4 color;\n"
22000 "void main(){\n"
22001 " color = vec4(1);\n"
22002 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022003
22004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22006
22007 VkPipelineObj pipe(m_device);
22008 pipe.AddColorAttachment();
22009 pipe.AddShader(&vs);
22010 pipe.AddShader(&fs);
22011
22012 VkDescriptorSetObj descriptorSet(m_device);
22013 descriptorSet.AppendDummy();
22014 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22015
22016 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22017
22018 m_errorMonitor->VerifyNotFound();
22019}
22020
22021TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022022 TEST_DESCRIPTION(
22023 "Test that pipeline validation accepts the relaxed type matching rules "
22024 "set out in 14.1.3: fundamental type must match, and producer side must "
22025 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022026 m_errorMonitor->ExpectSuccess();
22027
22028 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
22029
22030 ASSERT_NO_FATAL_FAILURE(InitState());
22031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22032
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022033 char const *vsSource =
22034 "#version 450\n"
22035 "out gl_PerVertex {\n"
22036 " vec4 gl_Position;\n"
22037 "};\n"
22038 "layout(location=0) out vec3 x;\n"
22039 "layout(location=1) out ivec3 y;\n"
22040 "layout(location=2) out vec3 z;\n"
22041 "void main(){\n"
22042 " gl_Position = vec4(0);\n"
22043 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
22044 "}\n";
22045 char const *fsSource =
22046 "#version 450\n"
22047 "\n"
22048 "layout(location=0) out vec4 color;\n"
22049 "layout(location=0) in float x;\n"
22050 "layout(location=1) flat in int y;\n"
22051 "layout(location=2) in vec2 z;\n"
22052 "void main(){\n"
22053 " color = vec4(1 + x + y + z.x);\n"
22054 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022055
22056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22058
22059 VkPipelineObj pipe(m_device);
22060 pipe.AddColorAttachment();
22061 pipe.AddShader(&vs);
22062 pipe.AddShader(&fs);
22063
22064 VkDescriptorSetObj descriptorSet(m_device);
22065 descriptorSet.AppendDummy();
22066 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22067
22068 VkResult err = VK_SUCCESS;
22069 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22070 ASSERT_VK_SUCCESS(err);
22071
22072 m_errorMonitor->VerifyNotFound();
22073}
22074
22075TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022076 TEST_DESCRIPTION(
22077 "Test that pipeline validation accepts per-vertex variables "
22078 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022079 m_errorMonitor->ExpectSuccess();
22080
22081 ASSERT_NO_FATAL_FAILURE(InitState());
22082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22083
22084 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022085 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022086 return;
22087 }
22088
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022089 char const *vsSource =
22090 "#version 450\n"
22091 "void main(){}\n";
22092 char const *tcsSource =
22093 "#version 450\n"
22094 "layout(location=0) out int x[];\n"
22095 "layout(vertices=3) out;\n"
22096 "void main(){\n"
22097 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
22098 " gl_TessLevelInner[0] = 1;\n"
22099 " x[gl_InvocationID] = gl_InvocationID;\n"
22100 "}\n";
22101 char const *tesSource =
22102 "#version 450\n"
22103 "layout(triangles, equal_spacing, cw) in;\n"
22104 "layout(location=0) in int x[];\n"
22105 "out gl_PerVertex { vec4 gl_Position; };\n"
22106 "void main(){\n"
22107 " gl_Position.xyz = gl_TessCoord;\n"
22108 " gl_Position.w = x[0] + x[1] + x[2];\n"
22109 "}\n";
22110 char const *fsSource =
22111 "#version 450\n"
22112 "layout(location=0) out vec4 color;\n"
22113 "void main(){\n"
22114 " color = vec4(1);\n"
22115 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022116
22117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22118 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
22119 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
22120 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22121
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022122 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
22123 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022124
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022125 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022126
22127 VkPipelineObj pipe(m_device);
22128 pipe.SetInputAssembly(&iasci);
22129 pipe.SetTessellation(&tsci);
22130 pipe.AddColorAttachment();
22131 pipe.AddShader(&vs);
22132 pipe.AddShader(&tcs);
22133 pipe.AddShader(&tes);
22134 pipe.AddShader(&fs);
22135
22136 VkDescriptorSetObj descriptorSet(m_device);
22137 descriptorSet.AppendDummy();
22138 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22139
22140 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22141
22142 m_errorMonitor->VerifyNotFound();
22143}
22144
22145TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022146 TEST_DESCRIPTION(
22147 "Test that pipeline validation accepts a user-defined "
22148 "interface block passed into the geometry shader. This "
22149 "is interesting because the 'extra' array level is not "
22150 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022151 m_errorMonitor->ExpectSuccess();
22152
22153 ASSERT_NO_FATAL_FAILURE(InitState());
22154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22155
22156 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022157 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022158 return;
22159 }
22160
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022161 char const *vsSource =
22162 "#version 450\n"
22163 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
22164 "void main(){\n"
22165 " vs_out.x = vec4(1);\n"
22166 "}\n";
22167 char const *gsSource =
22168 "#version 450\n"
22169 "layout(triangles) in;\n"
22170 "layout(triangle_strip, max_vertices=3) out;\n"
22171 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
22172 "out gl_PerVertex { vec4 gl_Position; };\n"
22173 "void main() {\n"
22174 " gl_Position = gs_in[0].x;\n"
22175 " EmitVertex();\n"
22176 "}\n";
22177 char const *fsSource =
22178 "#version 450\n"
22179 "layout(location=0) out vec4 color;\n"
22180 "void main(){\n"
22181 " color = vec4(1);\n"
22182 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022183
22184 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22185 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
22186 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22187
22188 VkPipelineObj pipe(m_device);
22189 pipe.AddColorAttachment();
22190 pipe.AddShader(&vs);
22191 pipe.AddShader(&gs);
22192 pipe.AddShader(&fs);
22193
22194 VkDescriptorSetObj descriptorSet(m_device);
22195 descriptorSet.AppendDummy();
22196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22197
22198 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22199
22200 m_errorMonitor->VerifyNotFound();
22201}
22202
22203TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022204 TEST_DESCRIPTION(
22205 "Test that pipeline validation accepts basic use of 64bit vertex "
22206 "attributes. This is interesting because they consume multiple "
22207 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022208 m_errorMonitor->ExpectSuccess();
22209
22210 ASSERT_NO_FATAL_FAILURE(InitState());
22211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22212
22213 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022214 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022215 return;
22216 }
22217
22218 VkVertexInputBindingDescription input_bindings[1];
22219 memset(input_bindings, 0, sizeof(input_bindings));
22220
22221 VkVertexInputAttributeDescription input_attribs[4];
22222 memset(input_attribs, 0, sizeof(input_attribs));
22223 input_attribs[0].location = 0;
22224 input_attribs[0].offset = 0;
22225 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22226 input_attribs[1].location = 2;
22227 input_attribs[1].offset = 32;
22228 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22229 input_attribs[2].location = 4;
22230 input_attribs[2].offset = 64;
22231 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22232 input_attribs[3].location = 6;
22233 input_attribs[3].offset = 96;
22234 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22235
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022236 char const *vsSource =
22237 "#version 450\n"
22238 "\n"
22239 "layout(location=0) in dmat4 x;\n"
22240 "out gl_PerVertex {\n"
22241 " vec4 gl_Position;\n"
22242 "};\n"
22243 "void main(){\n"
22244 " gl_Position = vec4(x[0][0]);\n"
22245 "}\n";
22246 char const *fsSource =
22247 "#version 450\n"
22248 "\n"
22249 "layout(location=0) out vec4 color;\n"
22250 "void main(){\n"
22251 " color = vec4(1);\n"
22252 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022253
22254 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22255 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22256
22257 VkPipelineObj pipe(m_device);
22258 pipe.AddColorAttachment();
22259 pipe.AddShader(&vs);
22260 pipe.AddShader(&fs);
22261
22262 pipe.AddVertexInputBindings(input_bindings, 1);
22263 pipe.AddVertexInputAttribs(input_attribs, 4);
22264
22265 VkDescriptorSetObj descriptorSet(m_device);
22266 descriptorSet.AppendDummy();
22267 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22268
22269 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22270
22271 m_errorMonitor->VerifyNotFound();
22272}
22273
22274TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22275 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22276 m_errorMonitor->ExpectSuccess();
22277
22278 ASSERT_NO_FATAL_FAILURE(InitState());
22279
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022280 char const *vsSource =
22281 "#version 450\n"
22282 "\n"
22283 "out gl_PerVertex {\n"
22284 " vec4 gl_Position;\n"
22285 "};\n"
22286 "void main(){\n"
22287 " gl_Position = vec4(1);\n"
22288 "}\n";
22289 char const *fsSource =
22290 "#version 450\n"
22291 "\n"
22292 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22293 "layout(location=0) out vec4 color;\n"
22294 "void main() {\n"
22295 " color = subpassLoad(x);\n"
22296 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022297
22298 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22299 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22300
22301 VkPipelineObj pipe(m_device);
22302 pipe.AddShader(&vs);
22303 pipe.AddShader(&fs);
22304 pipe.AddColorAttachment();
22305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22306
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022307 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22308 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022309 VkDescriptorSetLayout dsl;
22310 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22311 ASSERT_VK_SUCCESS(err);
22312
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022313 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022314 VkPipelineLayout pl;
22315 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22316 ASSERT_VK_SUCCESS(err);
22317
22318 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022319 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22320 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22321 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22322 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22323 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 -060022324 };
22325 VkAttachmentReference color = {
22326 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22327 };
22328 VkAttachmentReference input = {
22329 1, VK_IMAGE_LAYOUT_GENERAL,
22330 };
22331
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022332 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022333
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022334 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022335 VkRenderPass rp;
22336 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22337 ASSERT_VK_SUCCESS(err);
22338
22339 // should be OK. would go wrong here if it's going to...
22340 pipe.CreateVKPipeline(pl, rp);
22341
22342 m_errorMonitor->VerifyNotFound();
22343
22344 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22345 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22346 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22347}
22348
22349TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022350 TEST_DESCRIPTION(
22351 "Test that pipeline validation accepts a compute pipeline which declares a "
22352 "descriptor-backed resource which is not provided, but the shader does not "
22353 "statically use it. This is interesting because it requires compute pipelines "
22354 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022355 m_errorMonitor->ExpectSuccess();
22356
22357 ASSERT_NO_FATAL_FAILURE(InitState());
22358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022359 char const *csSource =
22360 "#version 450\n"
22361 "\n"
22362 "layout(local_size_x=1) in;\n"
22363 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22364 "void main(){\n"
22365 " // x is not used.\n"
22366 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022367
22368 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22369
22370 VkDescriptorSetObj descriptorSet(m_device);
22371 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22372
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022373 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22374 nullptr,
22375 0,
22376 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22377 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22378 descriptorSet.GetPipelineLayout(),
22379 VK_NULL_HANDLE,
22380 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022381
22382 VkPipeline pipe;
22383 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22384
22385 m_errorMonitor->VerifyNotFound();
22386
22387 if (err == VK_SUCCESS) {
22388 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22389 }
22390}
22391
22392TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022393 TEST_DESCRIPTION(
22394 "Test that pipeline validation accepts a shader consuming only the "
22395 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022396 m_errorMonitor->ExpectSuccess();
22397
22398 ASSERT_NO_FATAL_FAILURE(InitState());
22399
22400 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022401 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22402 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22403 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022404 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022405 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022406 VkDescriptorSetLayout dsl;
22407 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22408 ASSERT_VK_SUCCESS(err);
22409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022410 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022411 VkPipelineLayout pl;
22412 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22413 ASSERT_VK_SUCCESS(err);
22414
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022415 char const *csSource =
22416 "#version 450\n"
22417 "\n"
22418 "layout(local_size_x=1) in;\n"
22419 "layout(set=0, binding=0) uniform sampler s;\n"
22420 "layout(set=0, binding=1) uniform texture2D t;\n"
22421 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22422 "void main() {\n"
22423 " x = texture(sampler2D(t, s), vec2(0));\n"
22424 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022425 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22426
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022427 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22428 nullptr,
22429 0,
22430 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22431 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22432 pl,
22433 VK_NULL_HANDLE,
22434 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022435
22436 VkPipeline pipe;
22437 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22438
22439 m_errorMonitor->VerifyNotFound();
22440
22441 if (err == VK_SUCCESS) {
22442 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22443 }
22444
22445 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22446 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22447}
22448
22449TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022450 TEST_DESCRIPTION(
22451 "Test that pipeline validation accepts a shader consuming only the "
22452 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022453 m_errorMonitor->ExpectSuccess();
22454
22455 ASSERT_NO_FATAL_FAILURE(InitState());
22456
22457 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022458 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22459 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22460 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022461 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022462 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022463 VkDescriptorSetLayout dsl;
22464 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22465 ASSERT_VK_SUCCESS(err);
22466
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022467 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022468 VkPipelineLayout pl;
22469 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22470 ASSERT_VK_SUCCESS(err);
22471
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022472 char const *csSource =
22473 "#version 450\n"
22474 "\n"
22475 "layout(local_size_x=1) in;\n"
22476 "layout(set=0, binding=0) uniform texture2D t;\n"
22477 "layout(set=0, binding=1) uniform sampler s;\n"
22478 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22479 "void main() {\n"
22480 " x = texture(sampler2D(t, s), vec2(0));\n"
22481 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022482 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22483
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022484 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22485 nullptr,
22486 0,
22487 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22488 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22489 pl,
22490 VK_NULL_HANDLE,
22491 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022492
22493 VkPipeline pipe;
22494 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22495
22496 m_errorMonitor->VerifyNotFound();
22497
22498 if (err == VK_SUCCESS) {
22499 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22500 }
22501
22502 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22503 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22504}
22505
22506TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022507 TEST_DESCRIPTION(
22508 "Test that pipeline validation accepts a shader consuming "
22509 "both the sampler and the image of a combined image+sampler "
22510 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022511 m_errorMonitor->ExpectSuccess();
22512
22513 ASSERT_NO_FATAL_FAILURE(InitState());
22514
22515 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022516 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22517 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022518 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022519 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022520 VkDescriptorSetLayout dsl;
22521 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22522 ASSERT_VK_SUCCESS(err);
22523
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022524 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022525 VkPipelineLayout pl;
22526 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22527 ASSERT_VK_SUCCESS(err);
22528
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022529 char const *csSource =
22530 "#version 450\n"
22531 "\n"
22532 "layout(local_size_x=1) in;\n"
22533 "layout(set=0, binding=0) uniform texture2D t;\n"
22534 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22535 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22536 "void main() {\n"
22537 " x = texture(sampler2D(t, s), vec2(0));\n"
22538 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022539 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22540
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022541 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22542 nullptr,
22543 0,
22544 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22545 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22546 pl,
22547 VK_NULL_HANDLE,
22548 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022549
22550 VkPipeline pipe;
22551 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22552
22553 m_errorMonitor->VerifyNotFound();
22554
22555 if (err == VK_SUCCESS) {
22556 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22557 }
22558
22559 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22560 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22561}
22562
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060022563// This test class enables the Maintenance1 extension for related validation tests
22564TEST_F(VkMaintenance1LayerTest, Maintenance1Tests) {
22565 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
22566
22567 // Ensure that extension is available and enabled.
22568 uint32_t extension_count = 0;
22569 bool supports_maintenance1_extension = false;
22570 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22571 ASSERT_VK_SUCCESS(err);
22572 if (extension_count > 0) {
22573 std::vector<VkExtensionProperties> available_extensions(extension_count);
22574
22575 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22576 ASSERT_VK_SUCCESS(err);
22577 for (const auto &extension_props : available_extensions) {
22578 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
22579 supports_maintenance1_extension = true;
22580 }
22581 }
22582 }
22583
22584 // Proceed if extension is supported by hardware
22585 if (!supports_maintenance1_extension) {
22586 printf(" Maintenance1 Extension not supported, skipping tests\n");
22587 return;
22588 }
22589 ASSERT_NO_FATAL_FAILURE(InitState());
22590
22591 m_errorMonitor->ExpectSuccess();
22592
22593 VkCommandBuffer cmd_buf;
22594 VkCommandBufferAllocateInfo alloc_info;
22595 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22596 alloc_info.pNext = NULL;
22597 alloc_info.commandBufferCount = 1;
22598 alloc_info.commandPool = m_commandPool;
22599 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22600 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
22601
22602 VkCommandBufferBeginInfo cb_binfo;
22603 cb_binfo.pNext = NULL;
22604 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22605 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
22606 cb_binfo.flags = 0;
22607 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
22608 // Set Negative height, should give error if Maintenance 1 is not enabled
22609 VkViewport viewport = {0, 0, 16, -16, 0, 1};
22610 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
22611 vkEndCommandBuffer(cmd_buf);
22612
22613 m_errorMonitor->VerifyNotFound();
22614}
22615
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022616TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22617 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22618
22619 ASSERT_NO_FATAL_FAILURE(InitState());
22620
22621 // Positive test to check parameter_validation and unique_objects support
22622 // for NV_dedicated_allocation
22623 uint32_t extension_count = 0;
22624 bool supports_nv_dedicated_allocation = false;
22625 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22626 ASSERT_VK_SUCCESS(err);
22627
22628 if (extension_count > 0) {
22629 std::vector<VkExtensionProperties> available_extensions(extension_count);
22630
22631 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22632 ASSERT_VK_SUCCESS(err);
22633
22634 for (const auto &extension_props : available_extensions) {
22635 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22636 supports_nv_dedicated_allocation = true;
22637 }
22638 }
22639 }
22640
22641 if (supports_nv_dedicated_allocation) {
22642 m_errorMonitor->ExpectSuccess();
22643
22644 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22645 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22646 dedicated_buffer_create_info.pNext = nullptr;
22647 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22648
22649 uint32_t queue_family_index = 0;
22650 VkBufferCreateInfo buffer_create_info = {};
22651 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22652 buffer_create_info.pNext = &dedicated_buffer_create_info;
22653 buffer_create_info.size = 1024;
22654 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22655 buffer_create_info.queueFamilyIndexCount = 1;
22656 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22657
22658 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022659 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022660 ASSERT_VK_SUCCESS(err);
22661
22662 VkMemoryRequirements memory_reqs;
22663 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22664
22665 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22666 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22667 dedicated_memory_info.pNext = nullptr;
22668 dedicated_memory_info.buffer = buffer;
22669 dedicated_memory_info.image = VK_NULL_HANDLE;
22670
22671 VkMemoryAllocateInfo memory_info = {};
22672 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22673 memory_info.pNext = &dedicated_memory_info;
22674 memory_info.allocationSize = memory_reqs.size;
22675
22676 bool pass;
22677 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22678 ASSERT_TRUE(pass);
22679
22680 VkDeviceMemory buffer_memory;
22681 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22682 ASSERT_VK_SUCCESS(err);
22683
22684 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22685 ASSERT_VK_SUCCESS(err);
22686
22687 vkDestroyBuffer(m_device->device(), buffer, NULL);
22688 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22689
22690 m_errorMonitor->VerifyNotFound();
22691 }
22692}
22693
22694TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22695 VkResult err;
22696
22697 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22698
22699 ASSERT_NO_FATAL_FAILURE(InitState());
22700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22701
22702 std::vector<const char *> device_extension_names;
22703 auto features = m_device->phy().features();
22704 // Artificially disable support for non-solid fill modes
22705 features.fillModeNonSolid = false;
22706 // The sacrificial device object
22707 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22708
22709 VkRenderpassObj render_pass(&test_device);
22710
22711 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22712 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22713 pipeline_layout_ci.setLayoutCount = 0;
22714 pipeline_layout_ci.pSetLayouts = NULL;
22715
22716 VkPipelineLayout pipeline_layout;
22717 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22718 ASSERT_VK_SUCCESS(err);
22719
22720 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22721 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22722 rs_ci.pNext = nullptr;
22723 rs_ci.lineWidth = 1.0f;
22724 rs_ci.rasterizerDiscardEnable = true;
22725
22726 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22727 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22728
22729 // Set polygonMode=FILL. No error is expected
22730 m_errorMonitor->ExpectSuccess();
22731 {
22732 VkPipelineObj pipe(&test_device);
22733 pipe.AddShader(&vs);
22734 pipe.AddShader(&fs);
22735 pipe.AddColorAttachment();
22736 // Set polygonMode to a good value
22737 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22738 pipe.SetRasterization(&rs_ci);
22739 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22740 }
22741 m_errorMonitor->VerifyNotFound();
22742
22743 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22744}
22745
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022746#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022747TEST_F(VkPositiveLayerTest, LongFenceChain)
22748{
22749 m_errorMonitor->ExpectSuccess();
22750
22751 ASSERT_NO_FATAL_FAILURE(InitState());
22752 VkResult err;
22753
22754 std::vector<VkFence> fences;
22755
22756 const int chainLength = 32768;
22757
22758 for (int i = 0; i < chainLength; i++) {
22759 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22760 VkFence fence;
22761 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22762 ASSERT_VK_SUCCESS(err);
22763
22764 fences.push_back(fence);
22765
22766 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22767 0, nullptr, 0, nullptr };
22768 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22769 ASSERT_VK_SUCCESS(err);
22770
22771 }
22772
22773 // BOOM, stack overflow.
22774 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22775
22776 for (auto fence : fences)
22777 vkDestroyFence(m_device->device(), fence, nullptr);
22778
22779 m_errorMonitor->VerifyNotFound();
22780}
22781#endif
22782
Cody Northrop1242dfd2016-07-13 17:24:59 -060022783#if defined(ANDROID) && defined(VALIDATION_APK)
22784static bool initialized = false;
22785static bool active = false;
22786
22787// Convert Intents to argv
22788// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022789std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022790 std::vector<std::string> args;
22791 JavaVM &vm = *app.activity->vm;
22792 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022793 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022794
22795 JNIEnv &env = *p_env;
22796 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022797 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022798 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022799 jmethodID get_string_extra_method =
22800 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022801 jvalue get_string_extra_args;
22802 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022803 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022804
22805 std::string args_str;
22806 if (extra_str) {
22807 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22808 args_str = extra_utf;
22809 env.ReleaseStringUTFChars(extra_str, extra_utf);
22810 env.DeleteLocalRef(extra_str);
22811 }
22812
22813 env.DeleteLocalRef(get_string_extra_args.l);
22814 env.DeleteLocalRef(intent);
22815 vm.DetachCurrentThread();
22816
22817 // split args_str
22818 std::stringstream ss(args_str);
22819 std::string arg;
22820 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022821 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022822 }
22823
22824 return args;
22825}
22826
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022827static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022829static void processCommand(struct android_app *app, int32_t cmd) {
22830 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022831 case APP_CMD_INIT_WINDOW: {
22832 if (app->window) {
22833 initialized = true;
22834 }
22835 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022836 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022837 case APP_CMD_GAINED_FOCUS: {
22838 active = true;
22839 break;
22840 }
22841 case APP_CMD_LOST_FOCUS: {
22842 active = false;
22843 break;
22844 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022845 }
22846}
22847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022848void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022849 app_dummy();
22850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022851 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022852
22853 int vulkanSupport = InitVulkan();
22854 if (vulkanSupport == 0) {
22855 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22856 return;
22857 }
22858
22859 app->onAppCmd = processCommand;
22860 app->onInputEvent = processInput;
22861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022862 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022863 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022864 struct android_poll_source *source;
22865 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022866 if (source) {
22867 source->process(app, source);
22868 }
22869
22870 if (app->destroyRequested != 0) {
22871 VkTestFramework::Finish();
22872 return;
22873 }
22874 }
22875
22876 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022877 // Use the following key to send arguments to gtest, i.e.
22878 // --es args "--gtest_filter=-VkLayerTest.foo"
22879 const char key[] = "args";
22880 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022882 std::string filter = "";
22883 if (args.size() > 0) {
22884 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22885 filter += args[0];
22886 } else {
22887 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22888 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022890 int argc = 2;
22891 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22892 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022894 // Route output to files until we can override the gtest output
22895 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22896 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022897
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022898 ::testing::InitGoogleTest(&argc, argv);
22899 VkTestFramework::InitArgs(&argc, argv);
22900 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022902 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022904 if (result != 0) {
22905 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22906 } else {
22907 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22908 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022910 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022911
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022912 fclose(stdout);
22913 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022915 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022916 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022917 }
22918 }
22919}
22920#endif
22921
Tony Barbour300a6082015-04-07 13:44:53 -060022922int main(int argc, char **argv) {
22923 int result;
22924
Cody Northrop8e54a402016-03-08 22:25:52 -070022925#ifdef ANDROID
22926 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022927 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022928#endif
22929
Tony Barbour300a6082015-04-07 13:44:53 -060022930 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022931 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022932
22933 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22934
22935 result = RUN_ALL_TESTS();
22936
Tony Barbour6918cd52015-04-09 12:58:51 -060022937 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022938 return result;
22939}