blob: b2dafbfa4ee3efb359ebd90018b3de6740cca0a7 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 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>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
37#include "vkrenderframework.h"
Tobin Ehlise2eeffa2016-09-21 17:32:26 -060038#include <unordered_set>
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Tony Barbour300a6082015-04-07 13:44:53 -060040
Mark Lobodzinski3780e142015-05-14 15:08:13 -050041#define GLM_FORCE_RADIANS
42#include "glm/glm.hpp"
43#include <glm/gtc/matrix_transform.hpp>
44
Dustin Gravesffa90fa2016-05-06 11:20:38 -060045#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060046#define MEM_TRACKER_TESTS 1
47#define OBJ_TRACKER_TESTS 1
48#define DRAW_STATE_TESTS 1
49#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120050#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060051#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060052#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060053
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054//--------------------------------------------------------------------------------------
55// Mesh and VertexFormat Data
56//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070057struct Vertex {
58 float posX, posY, posZ, posW; // Position data
59 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050060};
61
Karl Schultz6addd812016-02-02 17:17:23 -070062#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050063
64typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070065 BsoFailNone = 0x00000000,
66 BsoFailLineWidth = 0x00000001,
67 BsoFailDepthBias = 0x00000002,
68 BsoFailViewport = 0x00000004,
69 BsoFailScissor = 0x00000008,
70 BsoFailBlend = 0x00000010,
71 BsoFailDepthBounds = 0x00000020,
72 BsoFailStencilReadMask = 0x00000040,
73 BsoFailStencilWriteMask = 0x00000080,
74 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060075 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060076 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050077} BsoFailSelect;
78
79struct vktriangle_vs_uniform {
80 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070081 float mvp[4][4];
82 float position[3][4];
83 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050084};
85
Mark Lobodzinskice751c62016-09-08 10:45:35 -060086static const char bindStateVertShaderText[] = "#version 450\n"
87 "vec2 vertices[3];\n"
88 "out gl_PerVertex {\n"
89 " vec4 gl_Position;\n"
90 "};\n"
91 "void main() {\n"
92 " vertices[0] = vec2(-1.0, -1.0);\n"
93 " vertices[1] = vec2( 1.0, -1.0);\n"
94 " vertices[2] = vec2( 0.0, 1.0);\n"
95 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
96 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060098static const char bindStateFragShaderText[] = "#version 450\n"
99 "\n"
100 "layout(location = 0) out vec4 uFragColor;\n"
101 "void main(){\n"
102 " uFragColor = vec4(0,1,0,1);\n"
103 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500104
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600105static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
106 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
107 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600108
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600109// ErrorMonitor Usage:
110//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600111// Call SetDesiredFailureMsg with: a string to be compared against all
112// encountered log messages, or a validation error enum identifying
113// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
114// will match all log messages. logMsg will return true for skipCall
115// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600116//
117// Call DesiredMsgFound to determine if the desired failure message
118// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600119class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700120 public:
121 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600122 test_platform_thread_create_mutex(&m_mutex);
123 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200124 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700125 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600127 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600128
Dustin Graves48458142016-04-29 16:11:55 -0600129 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
130
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600131 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700132 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600133 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600134 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600135 m_failure_message_strings.clear();
136 // If we are looking for a matching string, ignore any IDs
137 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600138 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600139 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700140 m_msgFound = VK_FALSE;
141 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600142 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600143 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600144
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600145 // ErrorMonitor will look for a message ID matching the specified one
146 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
147 // Also discard all collected messages to this point
148 test_platform_thread_lock_mutex(&m_mutex);
149 m_failure_message_strings.clear();
150 // If we are looking for IDs don't look for strings
151 m_desired_message_strings.clear();
152 m_otherMsgs.clear();
153 m_desired_message_ids.insert(msg_id);
154 m_msgFound = VK_FALSE;
155 m_msgFlags = msgFlags;
156 test_platform_thread_unlock_mutex(&m_mutex);
157 }
158
159 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600161 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600162 if (m_bailout != NULL) {
163 *m_bailout = true;
164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600166 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600167
168 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600169 if (desired_msg.length() == 0) {
170 // An empty desired_msg string "" indicates a positive test - not expecting an error.
171 // Return true to avoid calling layers/driver with this error.
172 // And don't erase the "" string, so it remains if another error is found.
173 result = VK_TRUE;
174 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600175 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600176 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600177 m_msgFound = VK_TRUE;
178 result = VK_TRUE;
179 // We only want one match for each expected error so remove from set here
180 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600181 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600182 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600183 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600184 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 for (auto desired_id : m_desired_message_ids) {
186 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
187 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
188 // Return true to avoid calling layers/driver with this error.
189 result = VK_TRUE;
190 } else if (desired_id == message_code) {
191 // Double-check that the string matches the error enum
192 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
193 found_expected = true;
194 result = VK_TRUE;
195 m_msgFound = VK_TRUE;
196 m_desired_message_ids.erase(desired_id);
197 break;
198 } else {
199 // Treat this message as a regular unexpected error, but print a warning jic
200 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
201 errorString.c_str(), desired_id, validation_error_map[desired_id]);
202 }
203 }
204 }
205
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600206 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200207 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600208 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600209 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600210 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600211 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600212 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213
Karl Schultz6addd812016-02-02 17:17:23 -0700214 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600216 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Karl Schultz6addd812016-02-02 17:17:23 -0700220 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223 vector<string> otherMsgs = GetOtherFailureMsgs();
224 cout << "Other error messages logged for this test were:" << endl;
225 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
226 cout << " " << *iter << endl;
227 }
228 }
229
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600230 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200231
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600232 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
233 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
234 m_msgFlags = message_flag_mask;
235 // Match ANY message matching specified type
236 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237 }
238
239 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600240 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200241 if (!DesiredMsgFound()) {
242 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600243 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600244 FAIL() << "Did not receive expected error '" << desired_msg << "'";
245 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200246 }
247 }
248
249 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200251 if (DesiredMsgFound()) {
252 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600253 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600254 FAIL() << "Expected to succeed but got error: " << msg;
255 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200256 }
257 }
258
Karl Schultz6addd812016-02-02 17:17:23 -0700259 private:
260 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600261 std::unordered_set<uint32_t>m_desired_message_ids;
262 std::unordered_set<string> m_desired_message_strings;
263 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700264 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600265 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700266 bool *m_bailout;
267 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600268};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500269
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600270static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
271 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
272 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600273 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
274 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600275 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600276 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600277 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600278}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500279
Karl Schultz6addd812016-02-02 17:17:23 -0700280class VkLayerTest : public VkRenderFramework {
281 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800282 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
283 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600284 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
285 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700286 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600287 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
288 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700289 }
Tony Barbour300a6082015-04-07 13:44:53 -0600290
Tony Barbourfe3351b2015-07-28 10:17:20 -0600291 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600292 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800293 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600294 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
295 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700296 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600297 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700298 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600299 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700300 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
302 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
303 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700304 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
305 }
306 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
307 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
308 }
309
310 protected:
311 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600312 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600313
314 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600315 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600316 std::vector<const char *> instance_extension_names;
317 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600318
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700319 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600320 /*
321 * Since CreateDbgMsgCallback is an instance level extension call
322 * any extension / layer that utilizes that feature also needs
323 * to be enabled at create instance time.
324 */
Karl Schultz6addd812016-02-02 17:17:23 -0700325 // Use Threading layer first to protect others from
326 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700327 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600328 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800329 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700330 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800331 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600332 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600334
Ian Elliott2c1daf52016-05-12 09:41:46 -0600335 if (m_enableWSI) {
336 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
337 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
338#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
339#if defined(VK_USE_PLATFORM_ANDROID_KHR)
340 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
341#endif // VK_USE_PLATFORM_ANDROID_KHR
342#if defined(VK_USE_PLATFORM_MIR_KHR)
343 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
344#endif // VK_USE_PLATFORM_MIR_KHR
345#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
346 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_WAYLAND_KHR
348#if defined(VK_USE_PLATFORM_WIN32_KHR)
349 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_WIN32_KHR
351#endif // NEED_TO_TEST_THIS_ON_PLATFORM
352#if defined(VK_USE_PLATFORM_XCB_KHR)
353 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
354#elif defined(VK_USE_PLATFORM_XLIB_KHR)
355 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_XLIB_KHR
357 }
358
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600359 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600360 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 this->app_info.pApplicationName = "layer_tests";
362 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600363 this->app_info.pEngineName = "unittest";
364 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600365 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600366
Tony Barbour15524c32015-04-29 17:34:29 -0600367 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600369 }
370
371 virtual void TearDown() {
372 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600373 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600374 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600376
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600377 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600378};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500379
Karl Schultz6addd812016-02-02 17:17:23 -0700380VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600381 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600382
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800383 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600384
385 /*
386 * For render test all drawing happens in a single render pass
387 * on a single command buffer.
388 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200389 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800390 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600391 }
392
393 return result;
394}
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600398
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200399 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800400 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200401 }
Tony Barbour300a6082015-04-07 13:44:53 -0600402
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800403 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600404
405 return result;
406}
407
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600408void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500409 // Create identity matrix
410 int i;
411 struct vktriangle_vs_uniform data;
412
413 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700414 glm::mat4 View = glm::mat4(1.0f);
415 glm::mat4 Model = glm::mat4(1.0f);
416 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700418 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500419
420 memcpy(&data.mvp, &MVP[0][0], matrixSize);
421
Karl Schultz6addd812016-02-02 17:17:23 -0700422 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600423 {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 -0500424 };
425
Karl Schultz6addd812016-02-02 17:17:23 -0700426 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427 data.position[i][0] = tri_data[i].posX;
428 data.position[i][1] = tri_data[i].posY;
429 data.position[i][2] = tri_data[i].posZ;
430 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700431 data.color[i][0] = tri_data[i].r;
432 data.color[i][1] = tri_data[i].g;
433 data.color[i][2] = tri_data[i].b;
434 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435 }
436
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500437 ASSERT_NO_FATAL_FAILURE(InitViewport());
438
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200439 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
440 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500444
445 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800446 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447 pipelineobj.AddShader(&vs);
448 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 if (failMask & BsoFailLineWidth) {
450 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600451 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600452 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600453 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
454 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailDepthBias) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600461 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600462 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600463 }
Karl Schultz6addd812016-02-02 17:17:23 -0700464 // Viewport and scissors must stay in synch or other errors will occur than
465 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600466 if (failMask & BsoFailViewport) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
468 }
469 if (failMask & BsoFailScissor) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
471 }
472 if (failMask & BsoFailBlend) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineColorBlendAttachmentState att_state = {};
475 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
476 att_state.blendEnable = VK_TRUE;
477 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600478 }
479 if (failMask & BsoFailDepthBounds) {
480 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
481 }
482 if (failMask & BsoFailStencilReadMask) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
484 }
485 if (failMask & BsoFailStencilWriteMask) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
487 }
488 if (failMask & BsoFailStencilReference) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
490 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500491
492 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600493 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500494
495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600496 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
Tony Barbourfe3351b2015-07-28 10:17:20 -0600498 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500499
500 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600501 if (failMask & BsoFailIndexBuffer) {
502 // Use DrawIndexed w/o an index buffer bound
503 DrawIndexed(3, 1, 0, 0, 0);
504 } else {
505 Draw(3, 1, 0, 0);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
Mark Muellerd4914412016-06-13 17:52:06 -0600508 if (failMask & BsoFailCmdClearAttachments) {
509 VkClearAttachment color_attachment = {};
510 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
511 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
512 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
513
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600514 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600515 }
516
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500517 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600518 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500519
Tony Barbourfe3351b2015-07-28 10:17:20 -0600520 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500521}
522
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600523void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
524 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600526 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600528 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500529 }
530
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800531 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700532 // Make sure depthWriteEnable is set so that Depth fail test will work
533 // correctly
534 // Make sure stencilTestEnable is set so that Stencil fail test will work
535 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600536 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800537 stencil.failOp = VK_STENCIL_OP_KEEP;
538 stencil.passOp = VK_STENCIL_OP_KEEP;
539 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
540 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600541
542 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
543 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600544 ds_ci.pNext = NULL;
545 ds_ci.depthTestEnable = VK_FALSE;
546 ds_ci.depthWriteEnable = VK_TRUE;
547 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
548 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600549 if (failMask & BsoFailDepthBounds) {
550 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600551 ds_ci.maxDepthBounds = 0.0f;
552 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600553 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600554 ds_ci.stencilTestEnable = VK_TRUE;
555 ds_ci.front = stencil;
556 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600557
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600558 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600559 pipelineobj.SetViewport(m_viewports);
560 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800561 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600562 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600563 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800564 commandBuffer->BindPipeline(pipelineobj);
565 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566}
567
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600568class VkPositiveLayerTest : public VkLayerTest {
569 public:
570 protected:
571};
572
Ian Elliott2c1daf52016-05-12 09:41:46 -0600573class VkWsiEnabledLayerTest : public VkLayerTest {
574 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600575 protected:
576 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600577};
578
Mark Muellerdfe37552016-07-07 14:47:42 -0600579class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600580 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600581 enum eTestEnFlags {
582 eDoubleDelete,
583 eInvalidDeviceOffset,
584 eInvalidMemoryOffset,
585 eBindNullBuffer,
586 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600587 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600588 };
589
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600591
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600592 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
593 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 return true;
595 }
596 VkDeviceSize offset_limit = 0;
597 if (eInvalidMemoryOffset == aTestFlag) {
598 VkBuffer vulkanBuffer;
599 VkBufferCreateInfo buffer_create_info = {};
600 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
601 buffer_create_info.size = 32;
602 buffer_create_info.usage = aBufferUsage;
603
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600604 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600605 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
609 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
611 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600612 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600615 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600616 }
617 if (eOffsetAlignment < offset_limit) {
618 return true;
619 }
620 return false;
621 }
622
623 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
625 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600626
627 if (eBindNullBuffer == aTestFlag) {
628 VulkanMemory = 0;
629 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
630 } else {
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(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600637
638 CreateCurrent = true;
639
640 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600642
643 VkMemoryAllocateInfo memory_allocate_info = {};
644 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
645 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600646 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
647 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648 if (!pass) {
649 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
650 return;
651 }
652
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600653 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 AllocateCurrent = true;
655 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
657 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658 BoundCurrent = true;
659
660 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
661 }
662 }
663
664 ~VkBufferTest() {
665 if (CreateCurrent) {
666 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
667 }
668 if (AllocateCurrent) {
669 if (InvalidDeleteEn) {
670 union {
671 VkDeviceMemory device_memory;
672 unsigned long long index_access;
673 } bad_index;
674
675 bad_index.device_memory = VulkanMemory;
676 bad_index.index_access++;
677
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600678 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600679 }
680 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
681 }
682 }
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600685
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600687
688 void TestDoubleDestroy() {
689 // Destroy the buffer but leave the flag set, which will cause
690 // the buffer to be destroyed again in the destructor.
691 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
692 }
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 bool AllocateCurrent;
696 bool BoundCurrent;
697 bool CreateCurrent;
698 bool InvalidDeleteEn;
699
700 VkBuffer VulkanBuffer;
701 VkDevice VulkanDevice;
702 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600703};
704
705class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600706 public:
707 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600708 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600709 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600710 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600711 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
712 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600713 BindIdGenerator++; // NB: This can wrap w/misuse
714
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
716 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
719 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
720 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
721 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
722 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
724 unsigned i = 0;
725 do {
726 VertexInputAttributeDescription[i].binding = BindId;
727 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600728 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
729 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600730 i++;
731 } while (AttributeCount < i);
732
733 i = 0;
734 do {
735 VertexInputBindingDescription[i].binding = BindId;
736 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600738 i++;
739 } while (BindingCount < i);
740 }
741
742 ~VkVerticesObj() {
743 if (VertexInputAttributeDescription) {
744 delete[] VertexInputAttributeDescription;
745 }
746 if (VertexInputBindingDescription) {
747 delete[] VertexInputBindingDescription;
748 }
749 }
750
751 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600752 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
753 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600754 return true;
755 }
756
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600758 VkDeviceSize *offsetList;
759 unsigned offsetCount;
760
761 if (aOffsetCount) {
762 offsetList = aOffsetList;
763 offsetCount = aOffsetCount;
764 } else {
765 offsetList = new VkDeviceSize[1]();
766 offsetCount = 1;
767 }
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600770 BoundCurrent = true;
771
772 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600773 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600774 }
775 }
776
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600777 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600778 static uint32_t BindIdGenerator;
779
780 bool BoundCurrent;
781 unsigned AttributeCount;
782 unsigned BindingCount;
783 uint32_t BindId;
784
785 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
786 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
787 VkVertexInputBindingDescription *VertexInputBindingDescription;
788 VkConstantBufferObj VulkanMemoryBuffer;
789};
790
791uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500792// ********************************************************************************************************************
793// ********************************************************************************************************************
794// ********************************************************************************************************************
795// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600796#if PARAMETER_VALIDATION_TESTS
797TEST_F(VkLayerTest, RequiredParameter) {
798 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
799 "pointer, array, and array count parameters");
800
801 ASSERT_NO_FATAL_FAILURE(InitState());
802
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600804 // Specify NULL for a pointer to a handle
805 // Expected to trigger an error with
806 // parameter_validation::validate_required_pointer
807 vkGetPhysicalDeviceFeatures(gpu(), NULL);
808 m_errorMonitor->VerifyFound();
809
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
811 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600812 // Specify NULL for pointer to array count
813 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600814 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815 m_errorMonitor->VerifyFound();
816
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify 0 for a required array count
819 // Expected to trigger an error with parameter_validation::validate_array
820 VkViewport view_port = {};
821 m_commandBuffer->SetViewport(0, 0, &view_port);
822 m_errorMonitor->VerifyFound();
823
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825 // Specify NULL for a required array
826 // Expected to trigger an error with parameter_validation::validate_array
827 m_commandBuffer->SetViewport(0, 1, NULL);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify VK_NULL_HANDLE for a required handle
832 // Expected to trigger an error with
833 // parameter_validation::validate_required_handle
834 vkUnmapMemory(device(), VK_NULL_HANDLE);
835 m_errorMonitor->VerifyFound();
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
838 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839 // Specify VK_NULL_HANDLE for a required handle array entry
840 // Expected to trigger an error with
841 // parameter_validation::validate_required_handle_array
842 VkFence fence = VK_NULL_HANDLE;
843 vkResetFences(device(), 1, &fence);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a required struct pointer
848 // Expected to trigger an error with
849 // parameter_validation::validate_struct_type
850 VkDeviceMemory memory = VK_NULL_HANDLE;
851 vkAllocateMemory(device(), NULL, NULL, &memory);
852 m_errorMonitor->VerifyFound();
853
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify 0 for a required VkFlags parameter
856 // Expected to trigger an error with parameter_validation::validate_flags
857 m_commandBuffer->SetStencilReference(0, 0);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 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 -0600861 // Specify 0 for a required VkFlags array entry
862 // Expected to trigger an error with
863 // parameter_validation::validate_flags_array
864 VkSemaphore semaphore = VK_NULL_HANDLE;
865 VkPipelineStageFlags stageFlags = 0;
866 VkSubmitInfo submitInfo = {};
867 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
868 submitInfo.waitSemaphoreCount = 1;
869 submitInfo.pWaitSemaphores = &semaphore;
870 submitInfo.pWaitDstStageMask = &stageFlags;
871 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
872 m_errorMonitor->VerifyFound();
873}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600874
Dustin Gravesfce74c02016-05-10 11:42:58 -0600875TEST_F(VkLayerTest, ReservedParameter) {
876 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
877
878 ASSERT_NO_FATAL_FAILURE(InitState());
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881 // Specify 0 for a reserved VkFlags parameter
882 // Expected to trigger an error with
883 // parameter_validation::validate_reserved_flags
884 VkEvent event_handle = VK_NULL_HANDLE;
885 VkEventCreateInfo event_info = {};
886 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
887 event_info.flags = 1;
888 vkCreateEvent(device(), &event_info, NULL, &event_handle);
889 m_errorMonitor->VerifyFound();
890}
891
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600892TEST_F(VkLayerTest, InvalidStructSType) {
893 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
894 "structure's sType field");
895
896 ASSERT_NO_FATAL_FAILURE(InitState());
897
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600899 // Zero struct memory, effectively setting sType to
900 // VK_STRUCTURE_TYPE_APPLICATION_INFO
901 // Expected to trigger an error with
902 // parameter_validation::validate_struct_type
903 VkMemoryAllocateInfo alloc_info = {};
904 VkDeviceMemory memory = VK_NULL_HANDLE;
905 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
906 m_errorMonitor->VerifyFound();
907
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600909 // Zero struct memory, effectively setting sType to
910 // VK_STRUCTURE_TYPE_APPLICATION_INFO
911 // Expected to trigger an error with
912 // parameter_validation::validate_struct_type_array
913 VkSubmitInfo submit_info = {};
914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
917
918TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600919 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600924 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600925 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600926 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600927 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600928 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600929 // Zero-initialization will provide the correct sType
930 VkApplicationInfo app_info = {};
931 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
932 event_alloc_info.pNext = &app_info;
933 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
934 m_errorMonitor->VerifyFound();
935
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
937 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
939 // a function that has allowed pNext structure types and specify
940 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600941 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600942 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600943 VkMemoryAllocateInfo memory_alloc_info = {};
944 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
945 memory_alloc_info.pNext = &app_info;
946 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600947 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948}
Dustin Graves5d33d532016-05-09 16:21:12 -0600949
950TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600951 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600952
953 ASSERT_NO_FATAL_FAILURE(InitState());
954
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
956 "range of the core VkFormat "
957 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958 // Specify an invalid VkFormat value
959 // Expected to trigger an error with
960 // parameter_validation::validate_ranged_enum
961 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600962 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600963 m_errorMonitor->VerifyFound();
964
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600965 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 -0600966 // Specify an invalid VkFlags bitmask value
967 // Expected to trigger an error with parameter_validation::validate_flags
968 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600969 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
970 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600971 m_errorMonitor->VerifyFound();
972
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600973 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 -0600974 // Specify an invalid VkFlags array entry
975 // Expected to trigger an error with
976 // parameter_validation::validate_flags_array
977 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 VkSubmitInfo submit_info = {};
980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
981 submit_info.waitSemaphoreCount = 1;
982 submit_info.pWaitSemaphores = &semaphore;
983 submit_info.pWaitDstStageMask = &stage_flags;
984 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
985 m_errorMonitor->VerifyFound();
986
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600988 // Specify an invalid VkBool32 value
989 // Expected to trigger a warning with
990 // parameter_validation::validate_bool32
991 VkSampler sampler = VK_NULL_HANDLE;
992 VkSamplerCreateInfo sampler_info = {};
993 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
994 sampler_info.pNext = NULL;
995 sampler_info.magFilter = VK_FILTER_NEAREST;
996 sampler_info.minFilter = VK_FILTER_NEAREST;
997 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
998 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
999 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1000 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1001 sampler_info.mipLodBias = 1.0;
1002 sampler_info.maxAnisotropy = 1;
1003 sampler_info.compareEnable = VK_FALSE;
1004 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1005 sampler_info.minLod = 1.0;
1006 sampler_info.maxLod = 1.0;
1007 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1008 sampler_info.unnormalizedCoordinates = VK_FALSE;
1009 // Not VK_TRUE or VK_FALSE
1010 sampler_info.anisotropyEnable = 3;
1011 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1012 m_errorMonitor->VerifyFound();
1013}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001014
1015TEST_F(VkLayerTest, FailedReturnValue) {
1016 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1017
1018 ASSERT_NO_FATAL_FAILURE(InitState());
1019
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001020 // Find an unsupported image format
1021 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1022 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1023 VkFormat format = static_cast<VkFormat>(f);
1024 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001025 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 unsupported = format;
1027 break;
1028 }
1029 }
1030
1031 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1033 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001034 // Specify an unsupported VkFormat value to generate a
1035 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1036 // Expected to trigger a warning from
1037 // parameter_validation::validate_result
1038 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001039 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1040 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1042 m_errorMonitor->VerifyFound();
1043 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001044}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001045
1046TEST_F(VkLayerTest, UpdateBufferAlignment) {
1047 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001048 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001049
1050 ASSERT_NO_FATAL_FAILURE(InitState());
1051
1052 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1053 vk_testing::Buffer buffer;
1054 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1055
1056 BeginCommandBuffer();
1057 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001059 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1060 m_errorMonitor->VerifyFound();
1061
1062 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001064 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1065 m_errorMonitor->VerifyFound();
1066
1067 // Introduce failure by using dataSize that is < 0
1068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is > 65536
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 EndCommandBuffer();
1080}
1081
1082TEST_F(VkLayerTest, FillBufferAlignment) {
1083 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1084
1085 ASSERT_NO_FATAL_FAILURE(InitState());
1086
1087 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1088 vk_testing::Buffer buffer;
1089 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1090
1091 BeginCommandBuffer();
1092
1093 // 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->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using size 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->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1101 m_errorMonitor->VerifyFound();
1102
1103 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001105 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1106 m_errorMonitor->VerifyFound();
1107
1108 EndCommandBuffer();
1109}
Dustin Graves40f35822016-06-23 11:12:53 -06001110
Cortd889ff92016-07-27 09:51:27 -07001111TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1112 VkResult err;
1113
1114 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001116
1117 ASSERT_NO_FATAL_FAILURE(InitState());
1118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1119
1120 std::vector<const char *> device_extension_names;
1121 auto features = m_device->phy().features();
1122 // Artificially disable support for non-solid fill modes
1123 features.fillModeNonSolid = false;
1124 // The sacrificial device object
1125 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1126
1127 VkRenderpassObj render_pass(&test_device);
1128
1129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1131 pipeline_layout_ci.setLayoutCount = 0;
1132 pipeline_layout_ci.pSetLayouts = NULL;
1133
1134 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001136 ASSERT_VK_SUCCESS(err);
1137
1138 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1139 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1140 rs_ci.pNext = nullptr;
1141 rs_ci.lineWidth = 1.0f;
1142 rs_ci.rasterizerDiscardEnable = true;
1143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1145 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001146
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001147 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1149 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001150 {
1151 VkPipelineObj pipe(&test_device);
1152 pipe.AddShader(&vs);
1153 pipe.AddShader(&fs);
1154 pipe.AddColorAttachment();
1155 // Introduce failure by setting unsupported polygon mode
1156 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1157 pipe.SetRasterization(&rs_ci);
1158 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1159 }
1160 m_errorMonitor->VerifyFound();
1161
1162 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1164 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001165 {
1166 VkPipelineObj pipe(&test_device);
1167 pipe.AddShader(&vs);
1168 pipe.AddShader(&fs);
1169 pipe.AddColorAttachment();
1170 // Introduce failure by setting unsupported polygon mode
1171 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1172 pipe.SetRasterization(&rs_ci);
1173 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1174 }
1175 m_errorMonitor->VerifyFound();
1176
Cortd889ff92016-07-27 09:51:27 -07001177 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1178}
1179
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001180#endif // PARAMETER_VALIDATION_TESTS
1181
Tobin Ehlis0788f522015-05-26 16:11:58 -06001182#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001183#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001184TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001185{
1186 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001187 VkFenceCreateInfo fenceInfo = {};
1188 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1189 fenceInfo.pNext = NULL;
1190 fenceInfo.flags = 0;
1191
Mike Weiblencce7ec72016-10-17 19:33:05 -06001192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001193
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001194 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001195
1196 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1197 vk_testing::Buffer buffer;
1198 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001199
Tony Barbourfe3351b2015-07-28 10:17:20 -06001200 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001201 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001202 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203
1204 testFence.init(*m_device, fenceInfo);
1205
1206 // Bypass framework since it does the waits automatically
1207 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001208 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001209 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1210 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001211 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001212 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001213 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001214 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001215 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001216 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001217 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001218
1219 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001220 ASSERT_VK_SUCCESS( err );
1221
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001223 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001224
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001225 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226}
1227
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001228TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001229{
1230 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231 VkFenceCreateInfo fenceInfo = {};
1232 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1233 fenceInfo.pNext = NULL;
1234 fenceInfo.flags = 0;
1235
Mike Weiblencce7ec72016-10-17 19:33:05 -06001236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001237
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238 ASSERT_NO_FATAL_FAILURE(InitState());
1239 ASSERT_NO_FATAL_FAILURE(InitViewport());
1240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1241
Tony Barbourfe3351b2015-07-28 10:17:20 -06001242 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001243 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001244 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245
1246 testFence.init(*m_device, fenceInfo);
1247
1248 // Bypass framework since it does the waits automatically
1249 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001250 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001251 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1252 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001253 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001254 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001255 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001256 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001258 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001259 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001260
1261 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001262 ASSERT_VK_SUCCESS( err );
1263
Jon Ashburnf19916e2016-01-11 13:12:43 -07001264 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001265 VkCommandBufferBeginInfo info = {};
1266 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1267 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001268 info.renderPass = VK_NULL_HANDLE;
1269 info.subpass = 0;
1270 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001271 info.occlusionQueryEnable = VK_FALSE;
1272 info.queryFlags = 0;
1273 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274
1275 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001278 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001279}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001280#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001281
Tobin Ehlisf11be982016-05-11 13:52:53 -06001282TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1283 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1284 "buffer and image to memory such that they will alias.");
1285 VkResult err;
1286 bool pass;
1287 ASSERT_NO_FATAL_FAILURE(InitState());
1288
Tobin Ehlis077ded32016-05-12 17:39:13 -06001289 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001291 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001292 VkDeviceMemory mem; // buffer will be bound first
1293 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001294 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001295
1296 VkBufferCreateInfo buf_info = {};
1297 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1298 buf_info.pNext = NULL;
1299 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1300 buf_info.size = 256;
1301 buf_info.queueFamilyIndexCount = 0;
1302 buf_info.pQueueFamilyIndices = NULL;
1303 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1304 buf_info.flags = 0;
1305 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1306 ASSERT_VK_SUCCESS(err);
1307
Tobin Ehlis077ded32016-05-12 17:39:13 -06001308 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001309
1310 VkImageCreateInfo image_create_info = {};
1311 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1312 image_create_info.pNext = NULL;
1313 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1314 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1315 image_create_info.extent.width = 64;
1316 image_create_info.extent.height = 64;
1317 image_create_info.extent.depth = 1;
1318 image_create_info.mipLevels = 1;
1319 image_create_info.arrayLayers = 1;
1320 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001321 // Image tiling must be optimal to trigger error when aliasing linear buffer
1322 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001323 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1325 image_create_info.queueFamilyIndexCount = 0;
1326 image_create_info.pQueueFamilyIndices = NULL;
1327 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1328 image_create_info.flags = 0;
1329
Tobin Ehlisf11be982016-05-11 13:52:53 -06001330 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001332 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1333 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334
Tobin Ehlis077ded32016-05-12 17:39:13 -06001335 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1336
1337 VkMemoryAllocateInfo alloc_info = {};
1338 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1339 alloc_info.pNext = NULL;
1340 alloc_info.memoryTypeIndex = 0;
1341 // Ensure memory is big enough for both bindings
1342 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001343 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1344 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001345 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001346 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001347 vkDestroyImage(m_device->device(), image, NULL);
1348 return;
1349 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001350 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1351 ASSERT_VK_SUCCESS(err);
1352 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1353 ASSERT_VK_SUCCESS(err);
1354
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001357 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1358 m_errorMonitor->VerifyFound();
1359
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001360 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001361 // aliasing buffer2
1362 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1363 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001364 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1365 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001367 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001369 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 m_errorMonitor->VerifyFound();
1371
1372 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001373 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001374 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001375 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 vkFreeMemory(m_device->device(), mem, NULL);
1377 vkFreeMemory(m_device->device(), mem_img, NULL);
1378}
1379
Tobin Ehlis35372522016-05-12 08:32:31 -06001380TEST_F(VkLayerTest, InvalidMemoryMapping) {
1381 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1382 VkResult err;
1383 bool pass;
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385
1386 VkBuffer buffer;
1387 VkDeviceMemory mem;
1388 VkMemoryRequirements mem_reqs;
1389
1390 VkBufferCreateInfo buf_info = {};
1391 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1392 buf_info.pNext = NULL;
1393 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1394 buf_info.size = 256;
1395 buf_info.queueFamilyIndexCount = 0;
1396 buf_info.pQueueFamilyIndices = NULL;
1397 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1398 buf_info.flags = 0;
1399 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1400 ASSERT_VK_SUCCESS(err);
1401
1402 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1403 VkMemoryAllocateInfo alloc_info = {};
1404 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1405 alloc_info.pNext = NULL;
1406 alloc_info.memoryTypeIndex = 0;
1407
1408 // Ensure memory is big enough for both bindings
1409 static const VkDeviceSize allocation_size = 0x10000;
1410 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001411 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 -06001412 if (!pass) {
1413 vkDestroyBuffer(m_device->device(), buffer, NULL);
1414 return;
1415 }
1416 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1417 ASSERT_VK_SUCCESS(err);
1418
1419 uint8_t *pData;
1420 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001421 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 -06001422 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1423 m_errorMonitor->VerifyFound();
1424 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001425 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001426 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1428 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1429 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 m_errorMonitor->VerifyFound();
1431
1432 // Unmap the memory to avoid re-map error
1433 vkUnmapMemory(m_device->device(), mem);
1434 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1437 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1441 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001442 m_errorMonitor->VerifyFound();
1443 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001445 vkUnmapMemory(m_device->device(), mem);
1446 m_errorMonitor->VerifyFound();
1447 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001449 ASSERT_VK_SUCCESS(err);
1450 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001451 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001452 mmr.memory = mem;
1453 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001455 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1456 m_errorMonitor->VerifyFound();
1457 // Now flush range that oversteps mapped range
1458 vkUnmapMemory(m_device->device(), mem);
1459 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1460 ASSERT_VK_SUCCESS(err);
1461 mmr.offset = 16;
1462 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
1466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001467 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1468 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001469 if (!pass) {
1470 vkFreeMemory(m_device->device(), mem, NULL);
1471 vkDestroyBuffer(m_device->device(), buffer, NULL);
1472 return;
1473 }
1474 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1475 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1476
1477 vkDestroyBuffer(m_device->device(), buffer, NULL);
1478 vkFreeMemory(m_device->device(), mem, NULL);
1479}
1480
Ian Elliott1c32c772016-04-28 14:47:13 -06001481TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1482 VkResult err;
1483 bool pass;
1484
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001485 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1486 // following declaration (which is temporarily being moved below):
1487 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001488 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1489 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1490 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001491 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001492 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001493 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001494
1495 ASSERT_NO_FATAL_FAILURE(InitState());
1496
Ian Elliott3f06ce52016-04-29 14:46:21 -06001497#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1498#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1499 // Use the functions from the VK_KHR_android_surface extension without
1500 // enabling that extension:
1501
1502 // Create a surface:
1503 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1505 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001506 pass = (err != VK_SUCCESS);
1507 ASSERT_TRUE(pass);
1508 m_errorMonitor->VerifyFound();
1509#endif // VK_USE_PLATFORM_ANDROID_KHR
1510
Ian Elliott3f06ce52016-04-29 14:46:21 -06001511#if defined(VK_USE_PLATFORM_MIR_KHR)
1512 // Use the functions from the VK_KHR_mir_surface extension without enabling
1513 // that extension:
1514
1515 // Create a surface:
1516 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001518 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1519 pass = (err != VK_SUCCESS);
1520 ASSERT_TRUE(pass);
1521 m_errorMonitor->VerifyFound();
1522
1523 // Tell whether an mir_connection supports presentation:
1524 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1526 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001527 m_errorMonitor->VerifyFound();
1528#endif // VK_USE_PLATFORM_MIR_KHR
1529
Ian Elliott3f06ce52016-04-29 14:46:21 -06001530#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1531 // Use the functions from the VK_KHR_wayland_surface extension without
1532 // enabling that extension:
1533
1534 // Create a surface:
1535 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1537 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001538 pass = (err != VK_SUCCESS);
1539 ASSERT_TRUE(pass);
1540 m_errorMonitor->VerifyFound();
1541
1542 // Tell whether an wayland_display supports presentation:
1543 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1545 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001546 m_errorMonitor->VerifyFound();
1547#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001548#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001551 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1552 // TO NON-LINUX PLATFORMS:
1553 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 // Use the functions from the VK_KHR_win32_surface extension without
1555 // enabling that extension:
1556
1557 // Create a surface:
1558 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1560 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001561 pass = (err != VK_SUCCESS);
1562 ASSERT_TRUE(pass);
1563 m_errorMonitor->VerifyFound();
1564
1565 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001567 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001568 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001569// Set this (for now, until all platforms are supported and tested):
1570#define NEED_TO_TEST_THIS_ON_PLATFORM
1571#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001572
Ian Elliott1c32c772016-04-28 14:47:13 -06001573#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1575 // TO NON-LINUX PLATFORMS:
1576 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001577 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1578 // that extension:
1579
1580 // Create a surface:
1581 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1584 pass = (err != VK_SUCCESS);
1585 ASSERT_TRUE(pass);
1586 m_errorMonitor->VerifyFound();
1587
1588 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001589 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001590 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1592 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001593 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001594// Set this (for now, until all platforms are supported and tested):
1595#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001596#endif // VK_USE_PLATFORM_XCB_KHR
1597
Ian Elliott12630812016-04-29 14:35:43 -06001598#if defined(VK_USE_PLATFORM_XLIB_KHR)
1599 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1600 // that extension:
1601
1602 // Create a surface:
1603 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001605 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1606 pass = (err != VK_SUCCESS);
1607 ASSERT_TRUE(pass);
1608 m_errorMonitor->VerifyFound();
1609
1610 // Tell whether an Xlib VisualID supports presentation:
1611 Display *dpy = NULL;
1612 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001614 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1615 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001616// Set this (for now, until all platforms are supported and tested):
1617#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001618#endif // VK_USE_PLATFORM_XLIB_KHR
1619
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620// Use the functions from the VK_KHR_surface extension without enabling
1621// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001622
Ian Elliott489eec02016-05-05 14:12:44 -06001623#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001624 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001626 vkDestroySurfaceKHR(instance(), surface, NULL);
1627 m_errorMonitor->VerifyFound();
1628
1629 // Check if surface supports presentation:
1630 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1633 pass = (err != VK_SUCCESS);
1634 ASSERT_TRUE(pass);
1635 m_errorMonitor->VerifyFound();
1636
1637 // Check surface capabilities:
1638 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1640 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001641 pass = (err != VK_SUCCESS);
1642 ASSERT_TRUE(pass);
1643 m_errorMonitor->VerifyFound();
1644
1645 // Check surface formats:
1646 uint32_t format_count = 0;
1647 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1649 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Check surface present modes:
1655 uint32_t present_mode_count = 0;
1656 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1658 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001659 pass = (err != VK_SUCCESS);
1660 ASSERT_TRUE(pass);
1661 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001662#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001663
Ian Elliott1c32c772016-04-28 14:47:13 -06001664 // Use the functions from the VK_KHR_swapchain extension without enabling
1665 // that extension:
1666
1667 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1670 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001672 pass = (err != VK_SUCCESS);
1673 ASSERT_TRUE(pass);
1674 m_errorMonitor->VerifyFound();
1675
1676 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1678 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 pass = (err != VK_SUCCESS);
1680 ASSERT_TRUE(pass);
1681 m_errorMonitor->VerifyFound();
1682
Chris Forbeseb7d5502016-09-13 18:19:21 +12001683 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1684 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1685 VkFence fence;
1686 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1687
Ian Elliott1c32c772016-04-28 14:47:13 -06001688 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001690 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001691 pass = (err != VK_SUCCESS);
1692 ASSERT_TRUE(pass);
1693 m_errorMonitor->VerifyFound();
1694
Chris Forbeseb7d5502016-09-13 18:19:21 +12001695 vkDestroyFence(m_device->device(), fence, nullptr);
1696
Ian Elliott1c32c772016-04-28 14:47:13 -06001697 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001698 //
1699 // NOTE: Currently can't test this because a real swapchain is needed (as
1700 // opposed to the fake one we created) in order for the layer to lookup the
1701 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001702
1703 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001705 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1706 m_errorMonitor->VerifyFound();
1707}
1708
Karl Schultz6addd812016-02-02 17:17:23 -07001709TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1710 VkResult err;
1711 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1714 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001715
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001716 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001717
1718 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001719 VkImage image;
1720 VkDeviceMemory mem;
1721 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001722
Karl Schultz6addd812016-02-02 17:17:23 -07001723 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1724 const int32_t tex_width = 32;
1725 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001726
Tony Barboureb254902015-07-15 12:50:33 -06001727 VkImageCreateInfo image_create_info = {};
1728 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001729 image_create_info.pNext = NULL;
1730 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1731 image_create_info.format = tex_format;
1732 image_create_info.extent.width = tex_width;
1733 image_create_info.extent.height = tex_height;
1734 image_create_info.extent.depth = 1;
1735 image_create_info.mipLevels = 1;
1736 image_create_info.arrayLayers = 1;
1737 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1738 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1739 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1740 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001741 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001742
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001743 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001744 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001745 mem_alloc.pNext = NULL;
1746 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001747
Chia-I Wuf7458c52015-10-26 21:10:41 +08001748 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001749 ASSERT_VK_SUCCESS(err);
1750
Karl Schultz6addd812016-02-02 17:17:23 -07001751 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001752
Mark Lobodzinski23065352015-05-29 09:32:35 -05001753 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001754
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001756 if (!pass) { // If we can't find any unmappable memory this test doesn't
1757 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001758 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001759 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001760 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001763 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001764 ASSERT_VK_SUCCESS(err);
1765
1766 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001767 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768 ASSERT_VK_SUCCESS(err);
1769
1770 // Map memory as if to initialize the image
1771 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001772 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001773
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001774 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001775
Chia-I Wuf7458c52015-10-26 21:10:41 +08001776 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001777 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001778}
1779
Karl Schultz6addd812016-02-02 17:17:23 -07001780TEST_F(VkLayerTest, RebindMemory) {
1781 VkResult err;
1782 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001785
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001786 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001787
1788 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001789 VkImage image;
1790 VkDeviceMemory mem1;
1791 VkDeviceMemory mem2;
1792 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001793
Karl Schultz6addd812016-02-02 17:17:23 -07001794 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1795 const int32_t tex_width = 32;
1796 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001797
Tony Barboureb254902015-07-15 12:50:33 -06001798 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001799 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1800 image_create_info.pNext = NULL;
1801 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1802 image_create_info.format = tex_format;
1803 image_create_info.extent.width = tex_width;
1804 image_create_info.extent.height = tex_height;
1805 image_create_info.extent.depth = 1;
1806 image_create_info.mipLevels = 1;
1807 image_create_info.arrayLayers = 1;
1808 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1809 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1810 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1811 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001812
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001813 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001814 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1815 mem_alloc.pNext = NULL;
1816 mem_alloc.allocationSize = 0;
1817 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001818
Karl Schultz6addd812016-02-02 17:17:23 -07001819 // Introduce failure, do NOT set memProps to
1820 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001821 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001823 ASSERT_VK_SUCCESS(err);
1824
Karl Schultz6addd812016-02-02 17:17:23 -07001825 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001826
1827 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001828 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001829 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830
1831 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001832 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001834 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001835 ASSERT_VK_SUCCESS(err);
1836
1837 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001838 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839 ASSERT_VK_SUCCESS(err);
1840
Karl Schultz6addd812016-02-02 17:17:23 -07001841 // Introduce validation failure, try to bind a different memory object to
1842 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001843 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001844
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001845 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001846
Chia-I Wuf7458c52015-10-26 21:10:41 +08001847 vkDestroyImage(m_device->device(), image, NULL);
1848 vkFreeMemory(m_device->device(), mem1, NULL);
1849 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001850}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001851
Karl Schultz6addd812016-02-02 17:17:23 -07001852TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001853 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1856 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001857
1858 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001859 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1860 fenceInfo.pNext = NULL;
1861 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001862
Tony Barbour300a6082015-04-07 13:44:53 -06001863 ASSERT_NO_FATAL_FAILURE(InitState());
1864 ASSERT_NO_FATAL_FAILURE(InitViewport());
1865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1866
Tony Barbourfe3351b2015-07-28 10:17:20 -06001867 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001869 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001870
1871 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001872
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001873 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001874 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1875 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001876 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001877 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001878 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001879 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001881 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001882 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001883
1884 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001885 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001887 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001888}
Chris Forbes4e44c912016-06-16 10:20:00 +12001889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890TEST_F(VkLayerTest, InvalidUsageBits) {
1891 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1892 "Initialize buffer with wrong usage then perform copy expecting errors "
1893 "from both the image and the buffer (2 calls)");
1894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001895
1896 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001897 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001898 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001899 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001900 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001901
Tony Barbourf92621a2016-05-02 14:28:12 -06001902 VkImageView dsv;
1903 VkImageViewCreateInfo dsvci = {};
1904 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1905 dsvci.image = image.handle();
1906 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1907 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1908 dsvci.subresourceRange.layerCount = 1;
1909 dsvci.subresourceRange.baseMipLevel = 0;
1910 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001911 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001912
Tony Barbourf92621a2016-05-02 14:28:12 -06001913 // Create a view with depth / stencil aspect for image with different usage
1914 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001915
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001916 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001917
1918 // Initialize buffer with TRANSFER_DST usage
1919 vk_testing::Buffer buffer;
1920 VkMemoryPropertyFlags reqs = 0;
1921 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1922 VkBufferImageCopy region = {};
1923 region.bufferRowLength = 128;
1924 region.bufferImageHeight = 128;
1925 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1926 region.imageSubresource.layerCount = 1;
1927 region.imageExtent.height = 16;
1928 region.imageExtent.width = 16;
1929 region.imageExtent.depth = 1;
1930
Tony Barbourf92621a2016-05-02 14:28:12 -06001931 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1932 // TRANSFER_DST
1933 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001934
Chris Forbesda581202016-10-06 18:25:26 +13001935 // two separate errors from this call:
1936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1938
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001939 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1940 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001941 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001942}
Tony Barbour75d79f02016-08-30 09:39:07 -06001943
Tony Barbour75d79f02016-08-30 09:39:07 -06001944
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001945#endif // MEM_TRACKER_TESTS
1946
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001947#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001948
1949TEST_F(VkLayerTest, LeakAnObject) {
1950 VkResult err;
1951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001953
1954 // Note that we have to create a new device since destroying the
1955 // framework's device causes Teardown() to fail and just calling Teardown
1956 // will destroy the errorMonitor.
1957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001959
1960 ASSERT_NO_FATAL_FAILURE(InitState());
1961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001962 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001963 std::vector<VkDeviceQueueCreateInfo> queue_info;
1964 queue_info.reserve(queue_props.size());
1965 std::vector<std::vector<float>> queue_priorities;
1966 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1967 VkDeviceQueueCreateInfo qi = {};
1968 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1969 qi.pNext = NULL;
1970 qi.queueFamilyIndex = i;
1971 qi.queueCount = queue_props[i].queueCount;
1972 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1973 qi.pQueuePriorities = queue_priorities[i].data();
1974 queue_info.push_back(qi);
1975 }
1976
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001977 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001978
1979 // The sacrificial device object
1980 VkDevice testDevice;
1981 VkDeviceCreateInfo device_create_info = {};
1982 auto features = m_device->phy().features();
1983 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1984 device_create_info.pNext = NULL;
1985 device_create_info.queueCreateInfoCount = queue_info.size();
1986 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001987 device_create_info.enabledLayerCount = 0;
1988 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001989 device_create_info.pEnabledFeatures = &features;
1990 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1991 ASSERT_VK_SUCCESS(err);
1992
1993 VkFence fence;
1994 VkFenceCreateInfo fence_create_info = {};
1995 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1996 fence_create_info.pNext = NULL;
1997 fence_create_info.flags = 0;
1998 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
1999 ASSERT_VK_SUCCESS(err);
2000
2001 // Induce failure by not calling vkDestroyFence
2002 vkDestroyDevice(testDevice, NULL);
2003 m_errorMonitor->VerifyFound();
2004}
2005
2006TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2007
2008 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2009 "attempt to delete them from another.");
2010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002012
Cody Northropc31a84f2016-08-22 10:41:47 -06002013 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002014 VkCommandPool command_pool_one;
2015 VkCommandPool command_pool_two;
2016
2017 VkCommandPoolCreateInfo pool_create_info{};
2018 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2019 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2020 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002024 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002025
2026 VkCommandBuffer command_buffer[9];
2027 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002028 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002029 command_buffer_allocate_info.commandPool = command_pool_one;
2030 command_buffer_allocate_info.commandBufferCount = 9;
2031 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002032 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035
2036 m_errorMonitor->VerifyFound();
2037
2038 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2039 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2040}
2041
2042TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2043 VkResult err;
2044
2045 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002046 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002049
2050 ASSERT_NO_FATAL_FAILURE(InitState());
2051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2052
2053 VkDescriptorPoolSize ds_type_count = {};
2054 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2055 ds_type_count.descriptorCount = 1;
2056
2057 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2058 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2059 ds_pool_ci.pNext = NULL;
2060 ds_pool_ci.flags = 0;
2061 ds_pool_ci.maxSets = 1;
2062 ds_pool_ci.poolSizeCount = 1;
2063 ds_pool_ci.pPoolSizes = &ds_type_count;
2064
2065 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002067 ASSERT_VK_SUCCESS(err);
2068
2069 // Create a second descriptor pool
2070 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002071 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002072 ASSERT_VK_SUCCESS(err);
2073
2074 VkDescriptorSetLayoutBinding dsl_binding = {};
2075 dsl_binding.binding = 0;
2076 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2077 dsl_binding.descriptorCount = 1;
2078 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2079 dsl_binding.pImmutableSamplers = NULL;
2080
2081 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2082 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2083 ds_layout_ci.pNext = NULL;
2084 ds_layout_ci.bindingCount = 1;
2085 ds_layout_ci.pBindings = &dsl_binding;
2086
2087 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089 ASSERT_VK_SUCCESS(err);
2090
2091 VkDescriptorSet descriptorSet;
2092 VkDescriptorSetAllocateInfo alloc_info = {};
2093 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2094 alloc_info.descriptorSetCount = 1;
2095 alloc_info.descriptorPool = ds_pool_one;
2096 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002097 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002098 ASSERT_VK_SUCCESS(err);
2099
2100 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2101
2102 m_errorMonitor->VerifyFound();
2103
2104 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2105 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2106 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2107}
2108
2109TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002111
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113
2114 ASSERT_NO_FATAL_FAILURE(InitState());
2115
2116 // Pass bogus handle into GetImageMemoryRequirements
2117 VkMemoryRequirements mem_reqs;
2118 uint64_t fakeImageHandle = 0xCADECADE;
2119 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2120
2121 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2122
2123 m_errorMonitor->VerifyFound();
2124}
2125
Karl Schultz6addd812016-02-02 17:17:23 -07002126TEST_F(VkLayerTest, PipelineNotBound) {
2127 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002129 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002132
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002133 ASSERT_NO_FATAL_FAILURE(InitState());
2134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002135
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002136 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002137 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2138 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002139
2140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2142 ds_pool_ci.pNext = NULL;
2143 ds_pool_ci.maxSets = 1;
2144 ds_pool_ci.poolSizeCount = 1;
2145 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002146
2147 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002149 ASSERT_VK_SUCCESS(err);
2150
2151 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002152 dsl_binding.binding = 0;
2153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2154 dsl_binding.descriptorCount = 1;
2155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2156 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002157
2158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2160 ds_layout_ci.pNext = NULL;
2161 ds_layout_ci.bindingCount = 1;
2162 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002163
2164 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002166 ASSERT_VK_SUCCESS(err);
2167
2168 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002169 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002171 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002172 alloc_info.descriptorPool = ds_pool;
2173 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002175 ASSERT_VK_SUCCESS(err);
2176
2177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2179 pipeline_layout_ci.pNext = NULL;
2180 pipeline_layout_ci.setLayoutCount = 1;
2181 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002182
2183 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185 ASSERT_VK_SUCCESS(err);
2186
Mark Youngad779052016-01-06 14:26:04 -07002187 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002188
2189 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002190 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002192 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002193
Chia-I Wuf7458c52015-10-26 21:10:41 +08002194 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2195 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2196 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002197}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002198
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002199TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2200 VkResult err;
2201
2202 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2203 "during bind[Buffer|Image]Memory time");
2204
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002205 ASSERT_NO_FATAL_FAILURE(InitState());
2206
2207 // Create an image, allocate memory, set a bad typeIndex and then try to
2208 // bind it
2209 VkImage image;
2210 VkDeviceMemory mem;
2211 VkMemoryRequirements mem_reqs;
2212 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2213 const int32_t tex_width = 32;
2214 const int32_t tex_height = 32;
2215
2216 VkImageCreateInfo image_create_info = {};
2217 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2218 image_create_info.pNext = NULL;
2219 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2220 image_create_info.format = tex_format;
2221 image_create_info.extent.width = tex_width;
2222 image_create_info.extent.height = tex_height;
2223 image_create_info.extent.depth = 1;
2224 image_create_info.mipLevels = 1;
2225 image_create_info.arrayLayers = 1;
2226 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2227 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2228 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2229 image_create_info.flags = 0;
2230
2231 VkMemoryAllocateInfo mem_alloc = {};
2232 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2233 mem_alloc.pNext = NULL;
2234 mem_alloc.allocationSize = 0;
2235 mem_alloc.memoryTypeIndex = 0;
2236
2237 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2238 ASSERT_VK_SUCCESS(err);
2239
2240 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2241 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002242
2243 // Introduce Failure, select invalid TypeIndex
2244 VkPhysicalDeviceMemoryProperties memory_info;
2245
2246 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2247 unsigned int i;
2248 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2249 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2250 mem_alloc.memoryTypeIndex = i;
2251 break;
2252 }
2253 }
2254 if (i >= memory_info.memoryTypeCount) {
2255 printf("No invalid memory type index could be found; skipped.\n");
2256 vkDestroyImage(m_device->device(), image, NULL);
2257 return;
2258 }
2259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002260 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 -06002261
2262 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2263 ASSERT_VK_SUCCESS(err);
2264
2265 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2266 (void)err;
2267
2268 m_errorMonitor->VerifyFound();
2269
2270 vkDestroyImage(m_device->device(), image, NULL);
2271 vkFreeMemory(m_device->device(), mem, NULL);
2272}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002273
Karl Schultz6addd812016-02-02 17:17:23 -07002274TEST_F(VkLayerTest, BindInvalidMemory) {
2275 VkResult err;
2276 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002279
Tobin Ehlisec598302015-09-15 15:02:17 -06002280 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002281
2282 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002283 VkImage image;
2284 VkDeviceMemory mem;
2285 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002286
Karl Schultz6addd812016-02-02 17:17:23 -07002287 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2288 const int32_t tex_width = 32;
2289 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002290
2291 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002292 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2293 image_create_info.pNext = NULL;
2294 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2295 image_create_info.format = tex_format;
2296 image_create_info.extent.width = tex_width;
2297 image_create_info.extent.height = tex_height;
2298 image_create_info.extent.depth = 1;
2299 image_create_info.mipLevels = 1;
2300 image_create_info.arrayLayers = 1;
2301 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2302 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2303 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2304 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002305
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002306 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002307 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2308 mem_alloc.pNext = NULL;
2309 mem_alloc.allocationSize = 0;
2310 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002311
Chia-I Wuf7458c52015-10-26 21:10:41 +08002312 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002313 ASSERT_VK_SUCCESS(err);
2314
Karl Schultz6addd812016-02-02 17:17:23 -07002315 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002316
2317 mem_alloc.allocationSize = mem_reqs.size;
2318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002319 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002320 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002321
2322 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002323 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002324 ASSERT_VK_SUCCESS(err);
2325
2326 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002327 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002328
2329 // Try to bind free memory that has been freed
2330 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2331 // This may very well return an error.
2332 (void)err;
2333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002335
Chia-I Wuf7458c52015-10-26 21:10:41 +08002336 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002337}
2338
Karl Schultz6addd812016-02-02 17:17:23 -07002339TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2340 VkResult err;
2341 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002342
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002344
Tobin Ehlisec598302015-09-15 15:02:17 -06002345 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002346
Karl Schultz6addd812016-02-02 17:17:23 -07002347 // Create an image object, allocate memory, destroy the object and then try
2348 // to bind it
2349 VkImage image;
2350 VkDeviceMemory mem;
2351 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002352
Karl Schultz6addd812016-02-02 17:17:23 -07002353 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2354 const int32_t tex_width = 32;
2355 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002356
2357 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002358 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2359 image_create_info.pNext = NULL;
2360 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2361 image_create_info.format = tex_format;
2362 image_create_info.extent.width = tex_width;
2363 image_create_info.extent.height = tex_height;
2364 image_create_info.extent.depth = 1;
2365 image_create_info.mipLevels = 1;
2366 image_create_info.arrayLayers = 1;
2367 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2368 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2369 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2370 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002371
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002372 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002373 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2374 mem_alloc.pNext = NULL;
2375 mem_alloc.allocationSize = 0;
2376 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Chia-I Wuf7458c52015-10-26 21:10:41 +08002378 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002379 ASSERT_VK_SUCCESS(err);
2380
Karl Schultz6addd812016-02-02 17:17:23 -07002381 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002382
2383 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002384 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002385 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
2387 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002388 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389 ASSERT_VK_SUCCESS(err);
2390
2391 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002392 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002393 ASSERT_VK_SUCCESS(err);
2394
2395 // Now Try to bind memory to this destroyed object
2396 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2397 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002398 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002399
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002400 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002401
Chia-I Wuf7458c52015-10-26 21:10:41 +08002402 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002403}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002404
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002405#endif // OBJ_TRACKER_TESTS
2406
Tobin Ehlis0788f522015-05-26 16:11:58 -06002407#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002408
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002409TEST_F(VkLayerTest, ImageSampleCounts) {
2410
2411 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2412 "validation errors.");
2413 ASSERT_NO_FATAL_FAILURE(InitState());
2414
2415 VkMemoryPropertyFlags reqs = 0;
2416 VkImageCreateInfo image_create_info = {};
2417 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2418 image_create_info.pNext = NULL;
2419 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2420 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2421 image_create_info.extent.width = 256;
2422 image_create_info.extent.height = 256;
2423 image_create_info.extent.depth = 1;
2424 image_create_info.mipLevels = 1;
2425 image_create_info.arrayLayers = 1;
2426 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2427 image_create_info.flags = 0;
2428
2429 VkImageBlit blit_region = {};
2430 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2431 blit_region.srcSubresource.baseArrayLayer = 0;
2432 blit_region.srcSubresource.layerCount = 1;
2433 blit_region.srcSubresource.mipLevel = 0;
2434 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2435 blit_region.dstSubresource.baseArrayLayer = 0;
2436 blit_region.dstSubresource.layerCount = 1;
2437 blit_region.dstSubresource.mipLevel = 0;
2438
2439 // Create two images, the source with sampleCount = 2, and attempt to blit
2440 // between them
2441 {
2442 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002443 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002444 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002445 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002446 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002447 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002448 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002449 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002450 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2452 "of VK_SAMPLE_COUNT_2_BIT but "
2453 "must be VK_SAMPLE_COUNT_1_BIT");
2454 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2455 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002456 m_errorMonitor->VerifyFound();
2457 m_commandBuffer->EndCommandBuffer();
2458 }
2459
2460 // Create two images, the dest with sampleCount = 4, and attempt to blit
2461 // between them
2462 {
2463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002464 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002465 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002466 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002467 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002468 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002469 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002471 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2473 "of VK_SAMPLE_COUNT_4_BIT but "
2474 "must be VK_SAMPLE_COUNT_1_BIT");
2475 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2476 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002477 m_errorMonitor->VerifyFound();
2478 m_commandBuffer->EndCommandBuffer();
2479 }
2480
2481 VkBufferImageCopy copy_region = {};
2482 copy_region.bufferRowLength = 128;
2483 copy_region.bufferImageHeight = 128;
2484 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2485 copy_region.imageSubresource.layerCount = 1;
2486 copy_region.imageExtent.height = 64;
2487 copy_region.imageExtent.width = 64;
2488 copy_region.imageExtent.depth = 1;
2489
2490 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2491 // buffer to image
2492 {
2493 vk_testing::Buffer src_buffer;
2494 VkMemoryPropertyFlags reqs = 0;
2495 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2496 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002497 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002498 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002499 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002500 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2502 "of VK_SAMPLE_COUNT_8_BIT but "
2503 "must be VK_SAMPLE_COUNT_1_BIT");
2504 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2505 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002506 m_errorMonitor->VerifyFound();
2507 m_commandBuffer->EndCommandBuffer();
2508 }
2509
2510 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2511 // image to buffer
2512 {
2513 vk_testing::Buffer dst_buffer;
2514 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2515 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002516 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002517 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002518 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002519 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2521 "of VK_SAMPLE_COUNT_2_BIT but "
2522 "must be VK_SAMPLE_COUNT_1_BIT");
2523 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002524 dst_buffer.handle(), 1, &copy_region);
2525 m_errorMonitor->VerifyFound();
2526 m_commandBuffer->EndCommandBuffer();
2527 }
2528}
2529
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002530TEST_F(VkLayerTest, BlitImageFormats) {
2531
2532 // Image blit with mismatched formats
2533 const char * expected_message =
2534 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2535 " the other one must also have signed/unsigned integer format";
2536
2537 ASSERT_NO_FATAL_FAILURE(InitState());
2538
2539 VkImageObj src_image(m_device);
2540 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2541 VkImageObj dst_image(m_device);
2542 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2543 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002544 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 -06002545
2546 VkImageBlit blitRegion = {};
2547 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2548 blitRegion.srcSubresource.baseArrayLayer = 0;
2549 blitRegion.srcSubresource.layerCount = 1;
2550 blitRegion.srcSubresource.mipLevel = 0;
2551 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2552 blitRegion.dstSubresource.baseArrayLayer = 0;
2553 blitRegion.dstSubresource.layerCount = 1;
2554 blitRegion.dstSubresource.mipLevel = 0;
2555
2556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2557
2558 // Unsigned int vs not an int
2559 BeginCommandBuffer();
2560 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2561 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2562
2563 m_errorMonitor->VerifyFound();
2564
2565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2566
2567 // Unsigned int vs signed int
2568 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2569 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2570
2571 m_errorMonitor->VerifyFound();
2572
2573 EndCommandBuffer();
2574}
2575
2576
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002577TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2578 VkResult err;
2579 bool pass;
2580
2581 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2582 ASSERT_NO_FATAL_FAILURE(InitState());
2583
2584 // If w/d/h granularity is 1, test is not meaningful
2585 // TODO: When virtual device limits are available, create a set of limits for this test that
2586 // will always have a granularity of > 1 for w, h, and d
2587 auto index = m_device->graphics_queue_node_index_;
2588 auto queue_family_properties = m_device->phy().queue_properties();
2589
2590 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2591 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2592 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2593 return;
2594 }
2595
2596 // Create two images of different types and try to copy between them
2597 VkImage srcImage;
2598 VkImage dstImage;
2599 VkDeviceMemory srcMem;
2600 VkDeviceMemory destMem;
2601 VkMemoryRequirements memReqs;
2602
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002603 VkImageCreateInfo image_create_info = {};
2604 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2605 image_create_info.pNext = NULL;
2606 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2607 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2608 image_create_info.extent.width = 32;
2609 image_create_info.extent.height = 32;
2610 image_create_info.extent.depth = 1;
2611 image_create_info.mipLevels = 1;
2612 image_create_info.arrayLayers = 4;
2613 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2614 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2615 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2616 image_create_info.flags = 0;
2617
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002619 ASSERT_VK_SUCCESS(err);
2620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002622 ASSERT_VK_SUCCESS(err);
2623
2624 // Allocate memory
2625 VkMemoryAllocateInfo memAlloc = {};
2626 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 memAlloc.pNext = NULL;
2628 memAlloc.allocationSize = 0;
2629 memAlloc.memoryTypeIndex = 0;
2630
2631 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2632 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002633 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002634 ASSERT_TRUE(pass);
2635 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2636 ASSERT_VK_SUCCESS(err);
2637
2638 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2639 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002640 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002641 ASSERT_VK_SUCCESS(err);
2642 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2643 ASSERT_VK_SUCCESS(err);
2644
2645 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2646 ASSERT_VK_SUCCESS(err);
2647 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2648 ASSERT_VK_SUCCESS(err);
2649
2650 BeginCommandBuffer();
2651 VkImageCopy copyRegion;
2652 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2653 copyRegion.srcSubresource.mipLevel = 0;
2654 copyRegion.srcSubresource.baseArrayLayer = 0;
2655 copyRegion.srcSubresource.layerCount = 1;
2656 copyRegion.srcOffset.x = 0;
2657 copyRegion.srcOffset.y = 0;
2658 copyRegion.srcOffset.z = 0;
2659 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2660 copyRegion.dstSubresource.mipLevel = 0;
2661 copyRegion.dstSubresource.baseArrayLayer = 0;
2662 copyRegion.dstSubresource.layerCount = 1;
2663 copyRegion.dstOffset.x = 0;
2664 copyRegion.dstOffset.y = 0;
2665 copyRegion.dstOffset.z = 0;
2666 copyRegion.extent.width = 1;
2667 copyRegion.extent.height = 1;
2668 copyRegion.extent.depth = 1;
2669
2670 // Introduce failure by setting srcOffset to a bad granularity value
2671 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2673 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002674 m_errorMonitor->VerifyFound();
2675
2676 // Introduce failure by setting extent to a bad granularity value
2677 copyRegion.srcOffset.y = 0;
2678 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2680 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002681 m_errorMonitor->VerifyFound();
2682
2683 // Now do some buffer/image copies
2684 vk_testing::Buffer buffer;
2685 VkMemoryPropertyFlags reqs = 0;
2686 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2687 VkBufferImageCopy region = {};
2688 region.bufferOffset = 0;
2689 region.bufferRowLength = 3;
2690 region.bufferImageHeight = 128;
2691 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2692 region.imageSubresource.layerCount = 1;
2693 region.imageExtent.height = 16;
2694 region.imageExtent.width = 16;
2695 region.imageExtent.depth = 1;
2696 region.imageOffset.x = 0;
2697 region.imageOffset.y = 0;
2698 region.imageOffset.z = 0;
2699
2700 // Introduce failure by setting bufferRowLength to a bad granularity value
2701 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2703 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2704 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002705 m_errorMonitor->VerifyFound();
2706 region.bufferRowLength = 128;
2707
2708 // Introduce failure by setting bufferOffset to a bad granularity value
2709 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2711 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2712 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002713 m_errorMonitor->VerifyFound();
2714 region.bufferOffset = 0;
2715
2716 // Introduce failure by setting bufferImageHeight to a bad granularity value
2717 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2719 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2720 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002721 m_errorMonitor->VerifyFound();
2722 region.bufferImageHeight = 128;
2723
2724 // Introduce failure by setting imageExtent to a bad granularity value
2725 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2727 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2728 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002729 m_errorMonitor->VerifyFound();
2730 region.imageExtent.width = 16;
2731
2732 // Introduce failure by setting imageOffset to a bad granularity value
2733 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2735 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2736 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 m_errorMonitor->VerifyFound();
2738
2739 EndCommandBuffer();
2740
2741 vkDestroyImage(m_device->device(), srcImage, NULL);
2742 vkDestroyImage(m_device->device(), dstImage, NULL);
2743 vkFreeMemory(m_device->device(), srcMem, NULL);
2744 vkFreeMemory(m_device->device(), destMem, NULL);
2745}
2746
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002747TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002748 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2749 "attempt to submit them on a queue created in a different "
2750 "queue family.");
2751
Cody Northropc31a84f2016-08-22 10:41:47 -06002752 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002753 // This test is meaningless unless we have multiple queue families
2754 auto queue_family_properties = m_device->phy().queue_properties();
2755 if (queue_family_properties.size() < 2) {
2756 return;
2757 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002759 // Get safe index of another queue family
2760 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2761 ASSERT_NO_FATAL_FAILURE(InitState());
2762 // Create a second queue using a different queue family
2763 VkQueue other_queue;
2764 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2765
2766 // Record an empty cmd buffer
2767 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2768 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2769 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2770 vkEndCommandBuffer(m_commandBuffer->handle());
2771
2772 // And submit on the wrong queue
2773 VkSubmitInfo submit_info = {};
2774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2775 submit_info.commandBufferCount = 1;
2776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002777 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002778
2779 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002780}
2781
Chris Forbesa58c4522016-09-28 15:19:39 +13002782TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2783 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2784 ASSERT_NO_FATAL_FAILURE(InitState());
2785
2786 // A renderpass with two subpasses, both writing the same attachment.
2787 VkAttachmentDescription attach[] = {
2788 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2789 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2790 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2791 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2792 },
2793 };
2794 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2795 VkSubpassDescription subpasses[] = {
2796 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2797 1, &ref, nullptr, nullptr, 0, nullptr },
2798 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2799 1, &ref, nullptr, nullptr, 0, nullptr },
2800 };
2801 VkSubpassDependency dep = {
2802 0, 1,
2803 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2804 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2805 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2806 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2807 VK_DEPENDENCY_BY_REGION_BIT
2808 };
2809 VkRenderPassCreateInfo rpci = {
2810 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2811 0, 1, attach, 2, subpasses, 1, &dep
2812 };
2813 VkRenderPass rp;
2814 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2815 ASSERT_VK_SUCCESS(err);
2816
2817 VkImageObj image(m_device);
2818 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2819 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2820 VK_IMAGE_TILING_OPTIMAL, 0);
2821 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2822
2823 VkFramebufferCreateInfo fbci = {
2824 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2825 0, rp, 1, &imageView, 32, 32, 1
2826 };
2827 VkFramebuffer fb;
2828 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2829 ASSERT_VK_SUCCESS(err);
2830
2831 char const *vsSource =
2832 "#version 450\n"
2833 "void main() { gl_Position = vec4(1); }\n";
2834 char const *fsSource =
2835 "#version 450\n"
2836 "layout(location=0) out vec4 color;\n"
2837 "void main() { color = vec4(1); }\n";
2838
2839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2841 VkPipelineObj pipe(m_device);
2842 pipe.AddColorAttachment();
2843 pipe.AddShader(&vs);
2844 pipe.AddShader(&fs);
2845 VkViewport view_port = {};
2846 m_viewports.push_back(view_port);
2847 pipe.SetViewport(m_viewports);
2848 VkRect2D rect = {};
2849 m_scissors.push_back(rect);
2850 pipe.SetScissor(m_scissors);
2851
2852 VkPipelineLayoutCreateInfo plci = {
2853 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2854 0, 0, nullptr, 0, nullptr
2855 };
2856 VkPipelineLayout pl;
2857 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2858 ASSERT_VK_SUCCESS(err);
2859 pipe.CreateVKPipeline(pl, rp);
2860
2861 BeginCommandBuffer();
2862
2863 VkRenderPassBeginInfo rpbi = {
2864 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2865 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2866 };
2867
2868 // subtest 1: bind in the wrong subpass
2869 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2870 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2872 "built for subpass 0 but used in subpass 1");
2873 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2874 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2875 m_errorMonitor->VerifyFound();
2876
2877 vkCmdEndRenderPass(m_commandBuffer->handle());
2878
2879 // subtest 2: bind in correct subpass, then transition to next subpass
2880 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2881 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2882 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2884 "built for subpass 0 but used in subpass 1");
2885 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2886 m_errorMonitor->VerifyFound();
2887
2888 vkCmdEndRenderPass(m_commandBuffer->handle());
2889
2890 EndCommandBuffer();
2891
2892 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2893 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2894 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2895}
2896
Tony Barbour4e919972016-08-09 13:27:40 -06002897TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2898 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2899 "with extent outside of framebuffer");
2900 ASSERT_NO_FATAL_FAILURE(InitState());
2901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2904 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002905
2906 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2907 m_renderPassBeginInfo.renderArea.extent.width = 257;
2908 m_renderPassBeginInfo.renderArea.extent.height = 257;
2909 BeginCommandBuffer();
2910 m_errorMonitor->VerifyFound();
2911}
2912
2913TEST_F(VkLayerTest, DisabledIndependentBlend) {
2914 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2915 "blend and then specifying different blend states for two "
2916 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002917 VkPhysicalDeviceFeatures features = {};
2918 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002919 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2922 "Invalid Pipeline CreateInfo: If independent blend feature not "
2923 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002924
Cody Northropc31a84f2016-08-22 10:41:47 -06002925 VkDescriptorSetObj descriptorSet(m_device);
2926 descriptorSet.AppendDummy();
2927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002928
Cody Northropc31a84f2016-08-22 10:41:47 -06002929 VkPipelineObj pipeline(m_device);
2930 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002931 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002932 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002933
Cody Northropc31a84f2016-08-22 10:41:47 -06002934 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2935 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2936 att_state1.blendEnable = VK_TRUE;
2937 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2938 att_state2.blendEnable = VK_FALSE;
2939 pipeline.AddColorAttachment(0, &att_state1);
2940 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002941 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06002942 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06002943}
2944
2945TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
2946 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
2947 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06002948 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06002949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2951 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06002952
2953 // Create a renderPass with a single color attachment
2954 VkAttachmentReference attach = {};
2955 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2956 VkSubpassDescription subpass = {};
2957 VkRenderPassCreateInfo rpci = {};
2958 rpci.subpassCount = 1;
2959 rpci.pSubpasses = &subpass;
2960 rpci.attachmentCount = 1;
2961 VkAttachmentDescription attach_desc = {};
2962 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
2963 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
2964 rpci.pAttachments = &attach_desc;
2965 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2966 VkRenderPass rp;
2967 subpass.pDepthStencilAttachment = &attach;
2968 subpass.pColorAttachments = NULL;
2969 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
2970 m_errorMonitor->VerifyFound();
2971}
2972
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002973TEST_F(VkLayerTest, UnusedPreserveAttachment) {
2974 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
2975 "attachment reference of VK_ATTACHMENT_UNUSED");
2976
2977 ASSERT_NO_FATAL_FAILURE(InitState());
2978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002981
2982 VkAttachmentReference color_attach = {};
2983 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
2984 color_attach.attachment = 0;
2985 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
2986 VkSubpassDescription subpass = {};
2987 subpass.colorAttachmentCount = 1;
2988 subpass.pColorAttachments = &color_attach;
2989 subpass.preserveAttachmentCount = 1;
2990 subpass.pPreserveAttachments = &preserve_attachment;
2991
2992 VkRenderPassCreateInfo rpci = {};
2993 rpci.subpassCount = 1;
2994 rpci.pSubpasses = &subpass;
2995 rpci.attachmentCount = 1;
2996 VkAttachmentDescription attach_desc = {};
2997 attach_desc.format = VK_FORMAT_UNDEFINED;
2998 rpci.pAttachments = &attach_desc;
2999 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3000 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003001 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003002
3003 m_errorMonitor->VerifyFound();
3004
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003005 if (result == VK_SUCCESS) {
3006 vkDestroyRenderPass(m_device->device(), rp, NULL);
3007 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003008}
3009
Chris Forbesc5389742016-06-29 11:49:23 +12003010TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003011 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3012 "when the source of a subpass multisample resolve "
3013 "does not have multiple samples.");
3014
Chris Forbesc5389742016-06-29 11:49:23 +12003015 ASSERT_NO_FATAL_FAILURE(InitState());
3016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3018 "Subpass 0 requests multisample resolve from attachment 0 which has "
3019 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003020
3021 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003022 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3023 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3024 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3025 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3026 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3027 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003028 };
3029
3030 VkAttachmentReference color = {
3031 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3032 };
3033
3034 VkAttachmentReference resolve = {
3035 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3036 };
3037
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003038 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003040 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003041
3042 VkRenderPass rp;
3043 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3044
3045 m_errorMonitor->VerifyFound();
3046
3047 if (err == VK_SUCCESS)
3048 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3049}
3050
3051TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003052 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3053 "when a subpass multisample resolve operation is "
3054 "requested, and the destination of that resolve has "
3055 "multiple samples.");
3056
Chris Forbesc5389742016-06-29 11:49:23 +12003057 ASSERT_NO_FATAL_FAILURE(InitState());
3058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3060 "Subpass 0 requests multisample resolve into attachment 1, which "
3061 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003062
3063 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003064 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3065 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3066 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3067 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3068 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3069 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003070 };
3071
3072 VkAttachmentReference color = {
3073 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3074 };
3075
3076 VkAttachmentReference resolve = {
3077 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3078 };
3079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003080 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003082 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003083
3084 VkRenderPass rp;
3085 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3086
3087 m_errorMonitor->VerifyFound();
3088
3089 if (err == VK_SUCCESS)
3090 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3091}
3092
Chris Forbes3f128ef2016-06-29 14:58:53 +12003093TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003094 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3095 "when the color and depth attachments used by a subpass "
3096 "have inconsistent sample counts");
3097
Chris Forbes3f128ef2016-06-29 14:58:53 +12003098 ASSERT_NO_FATAL_FAILURE(InitState());
3099
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3101 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003102
3103 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3105 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3106 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3107 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3108 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3109 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003110 };
3111
3112 VkAttachmentReference color[] = {
3113 {
3114 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3115 },
3116 {
3117 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3118 },
3119 };
3120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003121 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003123 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003124
3125 VkRenderPass rp;
3126 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3127
3128 m_errorMonitor->VerifyFound();
3129
3130 if (err == VK_SUCCESS)
3131 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3132}
3133
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003134TEST_F(VkLayerTest, FramebufferCreateErrors) {
3135 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003136 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003137 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003138 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3139 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3140 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3141 " 6. Framebuffer attachment where dimensions don't match\n"
3142 " 7. Framebuffer attachment w/o identity swizzle\n"
3143 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003144
3145 ASSERT_NO_FATAL_FAILURE(InitState());
3146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3150 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003151
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003152 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003153 VkAttachmentReference attach = {};
3154 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3155 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003156 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003157 VkRenderPassCreateInfo rpci = {};
3158 rpci.subpassCount = 1;
3159 rpci.pSubpasses = &subpass;
3160 rpci.attachmentCount = 1;
3161 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003162 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003163 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003164 rpci.pAttachments = &attach_desc;
3165 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3166 VkRenderPass rp;
3167 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3168 ASSERT_VK_SUCCESS(err);
3169
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003170 VkImageView ivs[2];
3171 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3172 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003173 VkFramebufferCreateInfo fb_info = {};
3174 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3175 fb_info.pNext = NULL;
3176 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003177 // Set mis-matching attachmentCount
3178 fb_info.attachmentCount = 2;
3179 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003180 fb_info.width = 100;
3181 fb_info.height = 100;
3182 fb_info.layers = 1;
3183
3184 VkFramebuffer fb;
3185 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3186
3187 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003188 if (err == VK_SUCCESS) {
3189 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3190 }
3191 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003192
3193 // Create a renderPass with a depth-stencil attachment created with
3194 // IMAGE_USAGE_COLOR_ATTACHMENT
3195 // Add our color attachment to pDepthStencilAttachment
3196 subpass.pDepthStencilAttachment = &attach;
3197 subpass.pColorAttachments = NULL;
3198 VkRenderPass rp_ds;
3199 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3200 ASSERT_VK_SUCCESS(err);
3201 // Set correct attachment count, but attachment has COLOR usage bit set
3202 fb_info.attachmentCount = 1;
3203 fb_info.renderPass = rp_ds;
3204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003206 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3207
3208 m_errorMonitor->VerifyFound();
3209 if (err == VK_SUCCESS) {
3210 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3211 }
3212 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003213
3214 // Create new renderpass with alternate attachment format from fb
3215 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3216 subpass.pDepthStencilAttachment = NULL;
3217 subpass.pColorAttachments = &attach;
3218 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3219 ASSERT_VK_SUCCESS(err);
3220
3221 // Cause error due to mis-matched formats between rp & fb
3222 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3223 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3225 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003226 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3227
3228 m_errorMonitor->VerifyFound();
3229 if (err == VK_SUCCESS) {
3230 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3231 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003232 vkDestroyRenderPass(m_device->device(), rp, NULL);
3233
3234 // Create new renderpass with alternate sample count from fb
3235 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3236 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3237 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3238 ASSERT_VK_SUCCESS(err);
3239
3240 // Cause error due to mis-matched sample count between rp & fb
3241 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3243 "that do not match the "
3244 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003245 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3246
3247 m_errorMonitor->VerifyFound();
3248 if (err == VK_SUCCESS) {
3249 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3250 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003251
3252 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003253
3254 // Create a custom imageView with non-1 mip levels
3255 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003256 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 -06003257 ASSERT_TRUE(image.initialized());
3258
3259 VkImageView view;
3260 VkImageViewCreateInfo ivci = {};
3261 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3262 ivci.image = image.handle();
3263 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3264 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3265 ivci.subresourceRange.layerCount = 1;
3266 ivci.subresourceRange.baseMipLevel = 0;
3267 // Set level count 2 (only 1 is allowed for FB attachment)
3268 ivci.subresourceRange.levelCount = 2;
3269 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3270 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3271 ASSERT_VK_SUCCESS(err);
3272 // Re-create renderpass to have matching sample count
3273 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3274 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3275 ASSERT_VK_SUCCESS(err);
3276
3277 fb_info.renderPass = rp;
3278 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003280 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3281
3282 m_errorMonitor->VerifyFound();
3283 if (err == VK_SUCCESS) {
3284 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3285 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003286 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003287 // Update view to original color buffer and grow FB dimensions too big
3288 fb_info.pAttachments = ivs;
3289 fb_info.height = 1024;
3290 fb_info.width = 1024;
3291 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3293 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003294 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3295
3296 m_errorMonitor->VerifyFound();
3297 if (err == VK_SUCCESS) {
3298 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3299 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003300 // Create view attachment with non-identity swizzle
3301 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3302 ivci.image = image.handle();
3303 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3304 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3305 ivci.subresourceRange.layerCount = 1;
3306 ivci.subresourceRange.baseMipLevel = 0;
3307 ivci.subresourceRange.levelCount = 1;
3308 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3309 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3310 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3311 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3312 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3313 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3314 ASSERT_VK_SUCCESS(err);
3315
3316 fb_info.pAttachments = &view;
3317 fb_info.height = 100;
3318 fb_info.width = 100;
3319 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3321 "framebuffer attachments must have "
3322 "been created with the identity "
3323 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003324 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3325
3326 m_errorMonitor->VerifyFound();
3327 if (err == VK_SUCCESS) {
3328 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3329 }
3330 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003331 // Request fb that exceeds max dimensions
3332 // reset attachment to color attachment
3333 fb_info.pAttachments = ivs;
3334 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3335 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3336 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3338 "dimensions exceed physical device "
3339 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003340 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3341
3342 m_errorMonitor->VerifyFound();
3343 if (err == VK_SUCCESS) {
3344 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3345 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003346
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003347 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003348}
3349
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003350TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003351 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3352 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003353
Cody Northropc31a84f2016-08-22 10:41:47 -06003354 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003355 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3357 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003358 m_errorMonitor->VerifyFound();
3359}
3360
3361TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3363 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003364
Cody Northropc31a84f2016-08-22 10:41:47 -06003365 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003366 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3368 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003369 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003370}
3371
3372TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3374 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003375
Cody Northropc31a84f2016-08-22 10:41:47 -06003376 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003377 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003380 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003381}
3382
3383TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003384 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3385 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003386
Cody Northropc31a84f2016-08-22 10:41:47 -06003387 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003388 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003391 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003392}
3393
Cortd713fe82016-07-27 09:51:27 -07003394TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003395 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3396 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003397
3398 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003399 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3401 "Dynamic blend constants state not set for this command buffer");
3402 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003403 m_errorMonitor->VerifyFound();
3404}
3405
3406TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003407 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3408 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003409
3410 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003411 if (!m_device->phy().features().depthBounds) {
3412 printf("Device does not support depthBounds test; skipped.\n");
3413 return;
3414 }
3415 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3417 "Dynamic depth bounds state not set for this command buffer");
3418 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003419 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003420}
3421
3422TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3424 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003425
3426 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003427 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3429 "Dynamic stencil read mask state not set for this command buffer");
3430 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003431 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003432}
3433
3434TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003435 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3436 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003437
3438 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003439 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3441 "Dynamic stencil write mask state not set for this command buffer");
3442 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003443 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003444}
3445
3446TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003447 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3448 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003449
3450 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003451 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3453 "Dynamic stencil reference state not set for this command buffer");
3454 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003455 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003456}
3457
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003458TEST_F(VkLayerTest, IndexBufferNotBound) {
3459 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003460
3461 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3463 "Index buffer object not bound to this command buffer when Indexed ");
3464 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003465 m_errorMonitor->VerifyFound();
3466}
3467
Karl Schultz6addd812016-02-02 17:17:23 -07003468TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3470 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3471 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003472
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003473 ASSERT_NO_FATAL_FAILURE(InitState());
3474 ASSERT_NO_FATAL_FAILURE(InitViewport());
3475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3476
Karl Schultz6addd812016-02-02 17:17:23 -07003477 // We luck out b/c by default the framework creates CB w/ the
3478 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003479 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003480 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003481 EndCommandBuffer();
3482
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003483 // Bypass framework since it does the waits automatically
3484 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003485 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003486 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3487 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003488 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003489 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003490 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003491 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003492 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003493 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003494 submit_info.pSignalSemaphores = NULL;
3495
Chris Forbes40028e22016-06-13 09:59:34 +12003496 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003497 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003498
Karl Schultz6addd812016-02-02 17:17:23 -07003499 // Cause validation error by re-submitting cmd buffer that should only be
3500 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003501 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003502
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003503 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003504}
3505
Karl Schultz6addd812016-02-02 17:17:23 -07003506TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003507 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003508 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3511 "type "
3512 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003513
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003514 ASSERT_NO_FATAL_FAILURE(InitState());
3515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003516
Karl Schultz6addd812016-02-02 17:17:23 -07003517 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3518 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003519 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003520 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3521 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003522
3523 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003524 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3525 ds_pool_ci.pNext = NULL;
3526 ds_pool_ci.flags = 0;
3527 ds_pool_ci.maxSets = 1;
3528 ds_pool_ci.poolSizeCount = 1;
3529 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003530
3531 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003532 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003533 ASSERT_VK_SUCCESS(err);
3534
3535 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003536 dsl_binding.binding = 0;
3537 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3538 dsl_binding.descriptorCount = 1;
3539 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3540 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003541
3542 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003543 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3544 ds_layout_ci.pNext = NULL;
3545 ds_layout_ci.bindingCount = 1;
3546 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003547
3548 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003550 ASSERT_VK_SUCCESS(err);
3551
3552 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003553 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003554 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003555 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003556 alloc_info.descriptorPool = ds_pool;
3557 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003558 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003559
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003560 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003561
Chia-I Wuf7458c52015-10-26 21:10:41 +08003562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3563 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003564}
3565
Karl Schultz6addd812016-02-02 17:17:23 -07003566TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3567 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003568
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3570 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3571 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003572
Tobin Ehlise735c692015-10-08 13:13:50 -06003573 ASSERT_NO_FATAL_FAILURE(InitState());
3574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003575
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003576 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003577 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3578 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003579
3580 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003581 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3582 ds_pool_ci.pNext = NULL;
3583 ds_pool_ci.maxSets = 1;
3584 ds_pool_ci.poolSizeCount = 1;
3585 ds_pool_ci.flags = 0;
3586 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3587 // app can only call vkResetDescriptorPool on this pool.;
3588 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003589
3590 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003591 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003592 ASSERT_VK_SUCCESS(err);
3593
3594 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003595 dsl_binding.binding = 0;
3596 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3597 dsl_binding.descriptorCount = 1;
3598 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3599 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003600
3601 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003602 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3603 ds_layout_ci.pNext = NULL;
3604 ds_layout_ci.bindingCount = 1;
3605 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003606
3607 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003609 ASSERT_VK_SUCCESS(err);
3610
3611 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003612 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003614 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003615 alloc_info.descriptorPool = ds_pool;
3616 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003618 ASSERT_VK_SUCCESS(err);
3619
3620 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003621 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003622
Chia-I Wuf7458c52015-10-26 21:10:41 +08003623 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3624 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003625}
3626
Karl Schultz6addd812016-02-02 17:17:23 -07003627TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003628 // Attempt to clear Descriptor Pool with bad object.
3629 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003630
3631 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003633 uint64_t fake_pool_handle = 0xbaad6001;
3634 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3635 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003636 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003637}
3638
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003639TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003640 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3641 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003642 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003643 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003644
3645 uint64_t fake_set_handle = 0xbaad6001;
3646 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003647 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003649
3650 ASSERT_NO_FATAL_FAILURE(InitState());
3651
3652 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3653 layout_bindings[0].binding = 0;
3654 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3655 layout_bindings[0].descriptorCount = 1;
3656 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3657 layout_bindings[0].pImmutableSamplers = NULL;
3658
3659 VkDescriptorSetLayout descriptor_set_layout;
3660 VkDescriptorSetLayoutCreateInfo dslci = {};
3661 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3662 dslci.pNext = NULL;
3663 dslci.bindingCount = 1;
3664 dslci.pBindings = layout_bindings;
3665 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003666 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003667
3668 VkPipelineLayout pipeline_layout;
3669 VkPipelineLayoutCreateInfo plci = {};
3670 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3671 plci.pNext = NULL;
3672 plci.setLayoutCount = 1;
3673 plci.pSetLayouts = &descriptor_set_layout;
3674 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003675 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003676
3677 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003678 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3679 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003680 m_errorMonitor->VerifyFound();
3681 EndCommandBuffer();
3682 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3683 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003684}
3685
Karl Schultz6addd812016-02-02 17:17:23 -07003686TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003687 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3688 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003689 uint64_t fake_layout_handle = 0xbaad6001;
3690 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003692 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003693 VkPipelineLayout pipeline_layout;
3694 VkPipelineLayoutCreateInfo plci = {};
3695 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3696 plci.pNext = NULL;
3697 plci.setLayoutCount = 1;
3698 plci.pSetLayouts = &bad_layout;
3699 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3700
3701 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003702}
3703
Mark Muellerd4914412016-06-13 17:52:06 -06003704TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3705 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3706 "1) A uniform buffer update must have a valid buffer index."
3707 "2) When using an array of descriptors in a single WriteDescriptor,"
3708 " the descriptor types and stageflags must all be the same."
3709 "3) Immutable Sampler state must match across descriptors");
3710
3711 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3713 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3714 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3715 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3716 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003717
Mark Muellerd4914412016-06-13 17:52:06 -06003718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3719
3720 ASSERT_NO_FATAL_FAILURE(InitState());
3721 VkDescriptorPoolSize ds_type_count[4] = {};
3722 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3723 ds_type_count[0].descriptorCount = 1;
3724 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3725 ds_type_count[1].descriptorCount = 1;
3726 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3727 ds_type_count[2].descriptorCount = 1;
3728 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3729 ds_type_count[3].descriptorCount = 1;
3730
3731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3733 ds_pool_ci.maxSets = 1;
3734 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3735 ds_pool_ci.pPoolSizes = ds_type_count;
3736
3737 VkDescriptorPool ds_pool;
3738 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3739 ASSERT_VK_SUCCESS(err);
3740
Mark Muellerb9896722016-06-16 09:54:29 -06003741 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003742 layout_binding[0].binding = 0;
3743 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3744 layout_binding[0].descriptorCount = 1;
3745 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3746 layout_binding[0].pImmutableSamplers = NULL;
3747
3748 layout_binding[1].binding = 1;
3749 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3750 layout_binding[1].descriptorCount = 1;
3751 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3752 layout_binding[1].pImmutableSamplers = NULL;
3753
3754 VkSamplerCreateInfo sampler_ci = {};
3755 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3756 sampler_ci.pNext = NULL;
3757 sampler_ci.magFilter = VK_FILTER_NEAREST;
3758 sampler_ci.minFilter = VK_FILTER_NEAREST;
3759 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3760 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3761 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3762 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3763 sampler_ci.mipLodBias = 1.0;
3764 sampler_ci.anisotropyEnable = VK_FALSE;
3765 sampler_ci.maxAnisotropy = 1;
3766 sampler_ci.compareEnable = VK_FALSE;
3767 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3768 sampler_ci.minLod = 1.0;
3769 sampler_ci.maxLod = 1.0;
3770 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3771 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3772 VkSampler sampler;
3773
3774 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3775 ASSERT_VK_SUCCESS(err);
3776
3777 layout_binding[2].binding = 2;
3778 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3779 layout_binding[2].descriptorCount = 1;
3780 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3781 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3782
Mark Muellerd4914412016-06-13 17:52:06 -06003783 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3784 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3785 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3786 ds_layout_ci.pBindings = layout_binding;
3787 VkDescriptorSetLayout ds_layout;
3788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3789 ASSERT_VK_SUCCESS(err);
3790
3791 VkDescriptorSetAllocateInfo alloc_info = {};
3792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3793 alloc_info.descriptorSetCount = 1;
3794 alloc_info.descriptorPool = ds_pool;
3795 alloc_info.pSetLayouts = &ds_layout;
3796 VkDescriptorSet descriptorSet;
3797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3798 ASSERT_VK_SUCCESS(err);
3799
3800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3802 pipeline_layout_ci.pNext = NULL;
3803 pipeline_layout_ci.setLayoutCount = 1;
3804 pipeline_layout_ci.pSetLayouts = &ds_layout;
3805
3806 VkPipelineLayout pipeline_layout;
3807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3808 ASSERT_VK_SUCCESS(err);
3809
Mark Mueller5c838ce2016-06-16 09:54:29 -06003810 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3812 descriptor_write.dstSet = descriptorSet;
3813 descriptor_write.dstBinding = 0;
3814 descriptor_write.descriptorCount = 1;
3815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3816
Mark Mueller5c838ce2016-06-16 09:54:29 -06003817 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3819 m_errorMonitor->VerifyFound();
3820
3821 // Create a buffer to update the descriptor with
3822 uint32_t qfi = 0;
3823 VkBufferCreateInfo buffCI = {};
3824 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3825 buffCI.size = 1024;
3826 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3827 buffCI.queueFamilyIndexCount = 1;
3828 buffCI.pQueueFamilyIndices = &qfi;
3829
3830 VkBuffer dyub;
3831 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3832 ASSERT_VK_SUCCESS(err);
3833 VkDescriptorBufferInfo buffInfo = {};
3834 buffInfo.buffer = dyub;
3835 buffInfo.offset = 0;
3836 buffInfo.range = 1024;
3837
3838 descriptor_write.pBufferInfo = &buffInfo;
3839 descriptor_write.descriptorCount = 2;
3840
Mark Mueller5c838ce2016-06-16 09:54:29 -06003841 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3843 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3844 m_errorMonitor->VerifyFound();
3845
Mark Mueller5c838ce2016-06-16 09:54:29 -06003846 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3847 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003848 descriptor_write.dstBinding = 1;
3849 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003850
Mark Mueller5c838ce2016-06-16 09:54:29 -06003851 // Make pImageInfo index non-null to avoid complaints of it missing
3852 VkDescriptorImageInfo imageInfo = {};
3853 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3854 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3856 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3857 m_errorMonitor->VerifyFound();
3858
Mark Muellerd4914412016-06-13 17:52:06 -06003859 vkDestroyBuffer(m_device->device(), dyub, NULL);
3860 vkDestroySampler(m_device->device(), sampler, NULL);
3861 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3862 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3863 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3864}
3865
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003866TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3867 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3868 "due to a buffer dependency being destroyed.");
3869 ASSERT_NO_FATAL_FAILURE(InitState());
3870
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003871 VkBuffer buffer;
3872 VkDeviceMemory mem;
3873 VkMemoryRequirements mem_reqs;
3874
3875 VkBufferCreateInfo buf_info = {};
3876 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003877 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003878 buf_info.size = 256;
3879 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3880 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3881 ASSERT_VK_SUCCESS(err);
3882
3883 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3884
3885 VkMemoryAllocateInfo alloc_info = {};
3886 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3887 alloc_info.allocationSize = 256;
3888 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003889 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 -06003890 if (!pass) {
3891 vkDestroyBuffer(m_device->device(), buffer, NULL);
3892 return;
3893 }
3894 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3895 ASSERT_VK_SUCCESS(err);
3896
3897 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3898 ASSERT_VK_SUCCESS(err);
3899
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003900 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003901 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003902 m_commandBuffer->EndCommandBuffer();
3903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003905 // Destroy buffer dependency prior to submit to cause ERROR
3906 vkDestroyBuffer(m_device->device(), buffer, NULL);
3907
3908 VkSubmitInfo submit_info = {};
3909 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3910 submit_info.commandBufferCount = 1;
3911 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3912 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3913
3914 m_errorMonitor->VerifyFound();
3915 vkFreeMemory(m_device->handle(), mem, NULL);
3916}
3917
Tobin Ehlisea413442016-09-28 10:23:59 -06003918TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3919 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3920
3921 ASSERT_NO_FATAL_FAILURE(InitState());
3922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3923
3924 VkDescriptorPoolSize ds_type_count;
3925 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3926 ds_type_count.descriptorCount = 1;
3927
3928 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3929 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3930 ds_pool_ci.maxSets = 1;
3931 ds_pool_ci.poolSizeCount = 1;
3932 ds_pool_ci.pPoolSizes = &ds_type_count;
3933
3934 VkDescriptorPool ds_pool;
3935 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3936 ASSERT_VK_SUCCESS(err);
3937
3938 VkDescriptorSetLayoutBinding layout_binding;
3939 layout_binding.binding = 0;
3940 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3941 layout_binding.descriptorCount = 1;
3942 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3943 layout_binding.pImmutableSamplers = NULL;
3944
3945 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3946 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3947 ds_layout_ci.bindingCount = 1;
3948 ds_layout_ci.pBindings = &layout_binding;
3949 VkDescriptorSetLayout ds_layout;
3950 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3951 ASSERT_VK_SUCCESS(err);
3952
3953 VkDescriptorSetAllocateInfo alloc_info = {};
3954 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3955 alloc_info.descriptorSetCount = 1;
3956 alloc_info.descriptorPool = ds_pool;
3957 alloc_info.pSetLayouts = &ds_layout;
3958 VkDescriptorSet descriptor_set;
3959 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
3960 ASSERT_VK_SUCCESS(err);
3961
3962 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3963 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3964 pipeline_layout_ci.pNext = NULL;
3965 pipeline_layout_ci.setLayoutCount = 1;
3966 pipeline_layout_ci.pSetLayouts = &ds_layout;
3967
3968 VkPipelineLayout pipeline_layout;
3969 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3970 ASSERT_VK_SUCCESS(err);
3971
3972 VkBuffer buffer;
3973 uint32_t queue_family_index = 0;
3974 VkBufferCreateInfo buffer_create_info = {};
3975 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3976 buffer_create_info.size = 1024;
3977 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3978 buffer_create_info.queueFamilyIndexCount = 1;
3979 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3980
3981 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
3982 ASSERT_VK_SUCCESS(err);
3983
3984 VkMemoryRequirements memory_reqs;
3985 VkDeviceMemory buffer_memory;
3986
3987 VkMemoryAllocateInfo memory_info = {};
3988 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3989 memory_info.allocationSize = 0;
3990 memory_info.memoryTypeIndex = 0;
3991
3992 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
3993 memory_info.allocationSize = memory_reqs.size;
3994 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
3995 ASSERT_TRUE(pass);
3996
3997 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
3998 ASSERT_VK_SUCCESS(err);
3999 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4000 ASSERT_VK_SUCCESS(err);
4001
4002 VkBufferView view;
4003 VkBufferViewCreateInfo bvci = {};
4004 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4005 bvci.buffer = buffer;
4006 bvci.format = VK_FORMAT_R8_UNORM;
4007 bvci.range = VK_WHOLE_SIZE;
4008
4009 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4010 ASSERT_VK_SUCCESS(err);
4011
4012 VkWriteDescriptorSet descriptor_write = {};
4013 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4014 descriptor_write.dstSet = descriptor_set;
4015 descriptor_write.dstBinding = 0;
4016 descriptor_write.descriptorCount = 1;
4017 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4018 descriptor_write.pTexelBufferView = &view;
4019
4020 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4021
4022 char const *vsSource = "#version 450\n"
4023 "\n"
4024 "out gl_PerVertex { \n"
4025 " vec4 gl_Position;\n"
4026 "};\n"
4027 "void main(){\n"
4028 " gl_Position = vec4(1);\n"
4029 "}\n";
4030 char const *fsSource = "#version 450\n"
4031 "\n"
4032 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4033 "layout(location=0) out vec4 x;\n"
4034 "void main(){\n"
4035 " x = imageLoad(s, 0);\n"
4036 "}\n";
4037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4039 VkPipelineObj pipe(m_device);
4040 pipe.AddShader(&vs);
4041 pipe.AddShader(&fs);
4042 pipe.AddColorAttachment();
4043 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4044
4045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4047
4048 BeginCommandBuffer();
4049 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4050 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4051 VkRect2D scissor = {{0, 0}, {16, 16}};
4052 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4053 // Bind pipeline to cmd buffer
4054 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4055 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4056 &descriptor_set, 0, nullptr);
4057 Draw(1, 0, 0, 0);
4058 EndCommandBuffer();
4059
4060 // Delete BufferView in order to invalidate cmd buffer
4061 vkDestroyBufferView(m_device->device(), view, NULL);
4062 // Now attempt submit of cmd buffer
4063 VkSubmitInfo submit_info = {};
4064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4065 submit_info.commandBufferCount = 1;
4066 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4067 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4068 m_errorMonitor->VerifyFound();
4069
4070 // Clean-up
4071 vkDestroyBuffer(m_device->device(), buffer, NULL);
4072 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4075 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4076}
4077
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004078TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4079 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4080 "due to an image dependency being destroyed.");
4081 ASSERT_NO_FATAL_FAILURE(InitState());
4082
4083 VkImage image;
4084 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4085 VkImageCreateInfo image_create_info = {};
4086 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4087 image_create_info.pNext = NULL;
4088 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4089 image_create_info.format = tex_format;
4090 image_create_info.extent.width = 32;
4091 image_create_info.extent.height = 32;
4092 image_create_info.extent.depth = 1;
4093 image_create_info.mipLevels = 1;
4094 image_create_info.arrayLayers = 1;
4095 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4096 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004098 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004099 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004101 // Have to bind memory to image before recording cmd in cmd buffer using it
4102 VkMemoryRequirements mem_reqs;
4103 VkDeviceMemory image_mem;
4104 bool pass;
4105 VkMemoryAllocateInfo mem_alloc = {};
4106 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4107 mem_alloc.pNext = NULL;
4108 mem_alloc.memoryTypeIndex = 0;
4109 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4110 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004111 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004112 ASSERT_TRUE(pass);
4113 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4114 ASSERT_VK_SUCCESS(err);
4115 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4116 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004117
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004118 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004119 VkClearColorValue ccv;
4120 ccv.float32[0] = 1.0f;
4121 ccv.float32[1] = 1.0f;
4122 ccv.float32[2] = 1.0f;
4123 ccv.float32[3] = 1.0f;
4124 VkImageSubresourceRange isr = {};
4125 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004126 isr.baseArrayLayer = 0;
4127 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004128 isr.layerCount = 1;
4129 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004131 m_commandBuffer->EndCommandBuffer();
4132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004134 // Destroy image dependency prior to submit to cause ERROR
4135 vkDestroyImage(m_device->device(), image, NULL);
4136
4137 VkSubmitInfo submit_info = {};
4138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4139 submit_info.commandBufferCount = 1;
4140 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4142
4143 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004144 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004145}
4146
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004147TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4148 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4149 "due to a framebuffer image dependency being destroyed.");
4150 VkFormatProperties format_properties;
4151 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4153 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004154 return;
4155 }
4156
4157 ASSERT_NO_FATAL_FAILURE(InitState());
4158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4159
4160 VkImageCreateInfo image_ci = {};
4161 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4162 image_ci.pNext = NULL;
4163 image_ci.imageType = VK_IMAGE_TYPE_2D;
4164 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4165 image_ci.extent.width = 32;
4166 image_ci.extent.height = 32;
4167 image_ci.extent.depth = 1;
4168 image_ci.mipLevels = 1;
4169 image_ci.arrayLayers = 1;
4170 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4171 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004172 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004173 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4174 image_ci.flags = 0;
4175 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004176 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004177
4178 VkMemoryRequirements memory_reqs;
4179 VkDeviceMemory image_memory;
4180 bool pass;
4181 VkMemoryAllocateInfo memory_info = {};
4182 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4183 memory_info.pNext = NULL;
4184 memory_info.allocationSize = 0;
4185 memory_info.memoryTypeIndex = 0;
4186 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4187 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004188 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004189 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004191 ASSERT_VK_SUCCESS(err);
4192 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4193 ASSERT_VK_SUCCESS(err);
4194
4195 VkImageViewCreateInfo ivci = {
4196 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4197 nullptr,
4198 0,
4199 image,
4200 VK_IMAGE_VIEW_TYPE_2D,
4201 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004202 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004203 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4204 };
4205 VkImageView view;
4206 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4207 ASSERT_VK_SUCCESS(err);
4208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004209 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004210 VkFramebuffer fb;
4211 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4212 ASSERT_VK_SUCCESS(err);
4213
4214 // Just use default renderpass with our framebuffer
4215 m_renderPassBeginInfo.framebuffer = fb;
4216 // Create Null cmd buffer for submit
4217 BeginCommandBuffer();
4218 EndCommandBuffer();
4219 // Destroy image attached to framebuffer to invalidate cmd buffer
4220 vkDestroyImage(m_device->device(), image, NULL);
4221 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004223 QueueCommandBuffer(false);
4224 m_errorMonitor->VerifyFound();
4225
4226 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4227 vkDestroyImageView(m_device->device(), view, nullptr);
4228 vkFreeMemory(m_device->device(), image_memory, nullptr);
4229}
4230
Tobin Ehlisb329f992016-10-12 13:20:29 -06004231TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4232 TEST_DESCRIPTION("Delete in-use framebuffer.");
4233 VkFormatProperties format_properties;
4234 VkResult err = VK_SUCCESS;
4235 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4236
4237 ASSERT_NO_FATAL_FAILURE(InitState());
4238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4239
4240 VkImageObj image(m_device);
4241 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4242 ASSERT_TRUE(image.initialized());
4243 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4244
4245 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4246 VkFramebuffer fb;
4247 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4248 ASSERT_VK_SUCCESS(err);
4249
4250 // Just use default renderpass with our framebuffer
4251 m_renderPassBeginInfo.framebuffer = fb;
4252 // Create Null cmd buffer for submit
4253 BeginCommandBuffer();
4254 EndCommandBuffer();
4255 // Submit cmd buffer to put it in-flight
4256 VkSubmitInfo submit_info = {};
4257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4258 submit_info.commandBufferCount = 1;
4259 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4260 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4261 // Destroy framebuffer while in-flight
4262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4263 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4264 m_errorMonitor->VerifyFound();
4265 // Wait for queue to complete so we can safely destroy everything
4266 vkQueueWaitIdle(m_device->m_queue);
4267 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4268}
4269
Tobin Ehlis88becd72016-09-21 14:33:41 -06004270TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4271 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4272 VkFormatProperties format_properties;
4273 VkResult err = VK_SUCCESS;
4274 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004275
4276 ASSERT_NO_FATAL_FAILURE(InitState());
4277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4278
4279 VkImageCreateInfo image_ci = {};
4280 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4281 image_ci.pNext = NULL;
4282 image_ci.imageType = VK_IMAGE_TYPE_2D;
4283 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4284 image_ci.extent.width = 256;
4285 image_ci.extent.height = 256;
4286 image_ci.extent.depth = 1;
4287 image_ci.mipLevels = 1;
4288 image_ci.arrayLayers = 1;
4289 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4290 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004291 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004292 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4293 image_ci.flags = 0;
4294 VkImage image;
4295 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4296
4297 VkMemoryRequirements memory_reqs;
4298 VkDeviceMemory image_memory;
4299 bool pass;
4300 VkMemoryAllocateInfo memory_info = {};
4301 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4302 memory_info.pNext = NULL;
4303 memory_info.allocationSize = 0;
4304 memory_info.memoryTypeIndex = 0;
4305 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4306 memory_info.allocationSize = memory_reqs.size;
4307 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4308 ASSERT_TRUE(pass);
4309 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4310 ASSERT_VK_SUCCESS(err);
4311 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4312 ASSERT_VK_SUCCESS(err);
4313
4314 VkImageViewCreateInfo ivci = {
4315 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4316 nullptr,
4317 0,
4318 image,
4319 VK_IMAGE_VIEW_TYPE_2D,
4320 VK_FORMAT_B8G8R8A8_UNORM,
4321 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4322 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4323 };
4324 VkImageView view;
4325 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4326 ASSERT_VK_SUCCESS(err);
4327
4328 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4329 VkFramebuffer fb;
4330 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4331 ASSERT_VK_SUCCESS(err);
4332
4333 // Just use default renderpass with our framebuffer
4334 m_renderPassBeginInfo.framebuffer = fb;
4335 // Create Null cmd buffer for submit
4336 BeginCommandBuffer();
4337 EndCommandBuffer();
4338 // Submit cmd buffer to put it (and attached imageView) in-flight
4339 VkSubmitInfo submit_info = {};
4340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4341 submit_info.commandBufferCount = 1;
4342 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4343 // Submit cmd buffer to put framebuffer and children in-flight
4344 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4345 // Destroy image attached to framebuffer while in-flight
4346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4347 vkDestroyImage(m_device->device(), image, NULL);
4348 m_errorMonitor->VerifyFound();
4349 // Wait for queue to complete so we can safely destroy image and other objects
4350 vkQueueWaitIdle(m_device->m_queue);
4351 vkDestroyImage(m_device->device(), image, NULL);
4352 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4353 vkDestroyImageView(m_device->device(), view, nullptr);
4354 vkFreeMemory(m_device->device(), image_memory, nullptr);
4355}
4356
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004357TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004358 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004359 ASSERT_NO_FATAL_FAILURE(InitState());
4360
4361 VkImage image;
4362 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4363 VkImageCreateInfo image_create_info = {};
4364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4365 image_create_info.pNext = NULL;
4366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4367 image_create_info.format = tex_format;
4368 image_create_info.extent.width = 32;
4369 image_create_info.extent.height = 32;
4370 image_create_info.extent.depth = 1;
4371 image_create_info.mipLevels = 1;
4372 image_create_info.arrayLayers = 1;
4373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004375 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004376 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004377 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004378 ASSERT_VK_SUCCESS(err);
4379 // Have to bind memory to image before recording cmd in cmd buffer using it
4380 VkMemoryRequirements mem_reqs;
4381 VkDeviceMemory image_mem;
4382 bool pass;
4383 VkMemoryAllocateInfo mem_alloc = {};
4384 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4385 mem_alloc.pNext = NULL;
4386 mem_alloc.memoryTypeIndex = 0;
4387 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4388 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004389 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004390 ASSERT_TRUE(pass);
4391 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4392 ASSERT_VK_SUCCESS(err);
4393
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004394 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004396 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004397
4398 m_commandBuffer->BeginCommandBuffer();
4399 VkClearColorValue ccv;
4400 ccv.float32[0] = 1.0f;
4401 ccv.float32[1] = 1.0f;
4402 ccv.float32[2] = 1.0f;
4403 ccv.float32[3] = 1.0f;
4404 VkImageSubresourceRange isr = {};
4405 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4406 isr.baseArrayLayer = 0;
4407 isr.baseMipLevel = 0;
4408 isr.layerCount = 1;
4409 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004410 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004411 m_commandBuffer->EndCommandBuffer();
4412
4413 m_errorMonitor->VerifyFound();
4414 vkDestroyImage(m_device->device(), image, NULL);
4415 vkFreeMemory(m_device->device(), image_mem, nullptr);
4416}
4417
4418TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004419 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004420 ASSERT_NO_FATAL_FAILURE(InitState());
4421
4422 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004423 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 -06004424 VK_IMAGE_TILING_OPTIMAL, 0);
4425 ASSERT_TRUE(image.initialized());
4426
4427 VkBuffer buffer;
4428 VkDeviceMemory mem;
4429 VkMemoryRequirements mem_reqs;
4430
4431 VkBufferCreateInfo buf_info = {};
4432 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004433 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004434 buf_info.size = 256;
4435 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4436 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4437 ASSERT_VK_SUCCESS(err);
4438
4439 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4440
4441 VkMemoryAllocateInfo alloc_info = {};
4442 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4443 alloc_info.allocationSize = 256;
4444 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 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 -06004446 if (!pass) {
4447 vkDestroyBuffer(m_device->device(), buffer, NULL);
4448 return;
4449 }
4450 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4451 ASSERT_VK_SUCCESS(err);
4452
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004453 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004455 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004456 VkBufferImageCopy region = {};
4457 region.bufferRowLength = 128;
4458 region.bufferImageHeight = 128;
4459 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4460
4461 region.imageSubresource.layerCount = 1;
4462 region.imageExtent.height = 4;
4463 region.imageExtent.width = 4;
4464 region.imageExtent.depth = 1;
4465 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004466 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4467 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004468 m_commandBuffer->EndCommandBuffer();
4469
4470 m_errorMonitor->VerifyFound();
4471
4472 vkDestroyBuffer(m_device->device(), buffer, NULL);
4473 vkFreeMemory(m_device->handle(), mem, NULL);
4474}
4475
Tobin Ehlis85940f52016-07-07 16:57:21 -06004476TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4477 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4478 "due to an event dependency being destroyed.");
4479 ASSERT_NO_FATAL_FAILURE(InitState());
4480
4481 VkEvent event;
4482 VkEventCreateInfo evci = {};
4483 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4484 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4485 ASSERT_VK_SUCCESS(result);
4486
4487 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004488 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004489 m_commandBuffer->EndCommandBuffer();
4490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004492 // Destroy event dependency prior to submit to cause ERROR
4493 vkDestroyEvent(m_device->device(), event, NULL);
4494
4495 VkSubmitInfo submit_info = {};
4496 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4497 submit_info.commandBufferCount = 1;
4498 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4500
4501 m_errorMonitor->VerifyFound();
4502}
4503
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004504TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4505 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4506 "due to a query pool dependency being destroyed.");
4507 ASSERT_NO_FATAL_FAILURE(InitState());
4508
4509 VkQueryPool query_pool;
4510 VkQueryPoolCreateInfo qpci{};
4511 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4512 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4513 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004514 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004515 ASSERT_VK_SUCCESS(result);
4516
4517 m_commandBuffer->BeginCommandBuffer();
4518 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4519 m_commandBuffer->EndCommandBuffer();
4520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004522 // Destroy query pool dependency prior to submit to cause ERROR
4523 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4524
4525 VkSubmitInfo submit_info = {};
4526 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4527 submit_info.commandBufferCount = 1;
4528 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4530
4531 m_errorMonitor->VerifyFound();
4532}
4533
Tobin Ehlis24130d92016-07-08 15:50:53 -06004534TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4535 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4536 "due to a pipeline dependency being destroyed.");
4537 ASSERT_NO_FATAL_FAILURE(InitState());
4538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4539
4540 VkResult err;
4541
4542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4544
4545 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004546 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004547 ASSERT_VK_SUCCESS(err);
4548
4549 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4550 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4551 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004552 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004553 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004554 vp_state_ci.scissorCount = 1;
4555 VkRect2D scissors = {}; // Dummy scissors to point to
4556 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004557
4558 VkPipelineShaderStageCreateInfo shaderStages[2];
4559 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004561 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4562 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4563 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004564 shaderStages[0] = vs.GetStageCreateInfo();
4565 shaderStages[1] = fs.GetStageCreateInfo();
4566
4567 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4568 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4569
4570 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4571 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4572 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4573
4574 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4575 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004576 rs_ci.rasterizerDiscardEnable = true;
4577 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004578
4579 VkPipelineColorBlendAttachmentState att = {};
4580 att.blendEnable = VK_FALSE;
4581 att.colorWriteMask = 0xf;
4582
4583 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4584 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4585 cb_ci.attachmentCount = 1;
4586 cb_ci.pAttachments = &att;
4587
4588 VkGraphicsPipelineCreateInfo gp_ci = {};
4589 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4590 gp_ci.stageCount = 2;
4591 gp_ci.pStages = shaderStages;
4592 gp_ci.pVertexInputState = &vi_ci;
4593 gp_ci.pInputAssemblyState = &ia_ci;
4594 gp_ci.pViewportState = &vp_state_ci;
4595 gp_ci.pRasterizationState = &rs_ci;
4596 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004597 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4598 gp_ci.layout = pipeline_layout;
4599 gp_ci.renderPass = renderPass();
4600
4601 VkPipelineCacheCreateInfo pc_ci = {};
4602 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4603
4604 VkPipeline pipeline;
4605 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004607 ASSERT_VK_SUCCESS(err);
4608
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004609 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004610 ASSERT_VK_SUCCESS(err);
4611
4612 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004613 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004614 m_commandBuffer->EndCommandBuffer();
4615 // Now destroy pipeline in order to cause error when submitting
4616 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4617
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004619
4620 VkSubmitInfo submit_info = {};
4621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4622 submit_info.commandBufferCount = 1;
4623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4625
4626 m_errorMonitor->VerifyFound();
4627 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4629}
4630
Tobin Ehlis31289162016-08-17 14:57:58 -06004631TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4632 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4633 "due to a bound descriptor set with a buffer dependency "
4634 "being destroyed.");
4635 ASSERT_NO_FATAL_FAILURE(InitState());
4636 ASSERT_NO_FATAL_FAILURE(InitViewport());
4637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4638
4639 VkDescriptorPoolSize ds_type_count = {};
4640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4641 ds_type_count.descriptorCount = 1;
4642
4643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4645 ds_pool_ci.pNext = NULL;
4646 ds_pool_ci.maxSets = 1;
4647 ds_pool_ci.poolSizeCount = 1;
4648 ds_pool_ci.pPoolSizes = &ds_type_count;
4649
4650 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004651 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004652 ASSERT_VK_SUCCESS(err);
4653
4654 VkDescriptorSetLayoutBinding dsl_binding = {};
4655 dsl_binding.binding = 0;
4656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4657 dsl_binding.descriptorCount = 1;
4658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4659 dsl_binding.pImmutableSamplers = NULL;
4660
4661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4663 ds_layout_ci.pNext = NULL;
4664 ds_layout_ci.bindingCount = 1;
4665 ds_layout_ci.pBindings = &dsl_binding;
4666 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004668 ASSERT_VK_SUCCESS(err);
4669
4670 VkDescriptorSet descriptorSet;
4671 VkDescriptorSetAllocateInfo alloc_info = {};
4672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4673 alloc_info.descriptorSetCount = 1;
4674 alloc_info.descriptorPool = ds_pool;
4675 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004677 ASSERT_VK_SUCCESS(err);
4678
4679 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4680 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4681 pipeline_layout_ci.pNext = NULL;
4682 pipeline_layout_ci.setLayoutCount = 1;
4683 pipeline_layout_ci.pSetLayouts = &ds_layout;
4684
4685 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004687 ASSERT_VK_SUCCESS(err);
4688
4689 // Create a buffer to update the descriptor with
4690 uint32_t qfi = 0;
4691 VkBufferCreateInfo buffCI = {};
4692 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4693 buffCI.size = 1024;
4694 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4695 buffCI.queueFamilyIndexCount = 1;
4696 buffCI.pQueueFamilyIndices = &qfi;
4697
4698 VkBuffer buffer;
4699 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4700 ASSERT_VK_SUCCESS(err);
4701 // Allocate memory and bind to buffer so we can make it to the appropriate
4702 // error
4703 VkMemoryAllocateInfo mem_alloc = {};
4704 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4705 mem_alloc.pNext = NULL;
4706 mem_alloc.allocationSize = 1024;
4707 mem_alloc.memoryTypeIndex = 0;
4708
4709 VkMemoryRequirements memReqs;
4710 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004711 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004712 if (!pass) {
4713 vkDestroyBuffer(m_device->device(), buffer, NULL);
4714 return;
4715 }
4716
4717 VkDeviceMemory mem;
4718 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4719 ASSERT_VK_SUCCESS(err);
4720 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4721 ASSERT_VK_SUCCESS(err);
4722 // Correctly update descriptor to avoid "NOT_UPDATED" error
4723 VkDescriptorBufferInfo buffInfo = {};
4724 buffInfo.buffer = buffer;
4725 buffInfo.offset = 0;
4726 buffInfo.range = 1024;
4727
4728 VkWriteDescriptorSet descriptor_write;
4729 memset(&descriptor_write, 0, sizeof(descriptor_write));
4730 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4731 descriptor_write.dstSet = descriptorSet;
4732 descriptor_write.dstBinding = 0;
4733 descriptor_write.descriptorCount = 1;
4734 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4735 descriptor_write.pBufferInfo = &buffInfo;
4736
4737 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4738
4739 // Create PSO to be used for draw-time errors below
4740 char const *vsSource = "#version 450\n"
4741 "\n"
4742 "out gl_PerVertex { \n"
4743 " vec4 gl_Position;\n"
4744 "};\n"
4745 "void main(){\n"
4746 " gl_Position = vec4(1);\n"
4747 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004748 char const *fsSource = "#version 450\n"
4749 "\n"
4750 "layout(location=0) out vec4 x;\n"
4751 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4752 "void main(){\n"
4753 " x = vec4(bar.y);\n"
4754 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4757 VkPipelineObj pipe(m_device);
4758 pipe.AddShader(&vs);
4759 pipe.AddShader(&fs);
4760 pipe.AddColorAttachment();
4761 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4762
4763 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4765 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4766 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004767 Draw(1, 0, 0, 0);
4768 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004770 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4771 vkDestroyBuffer(m_device->device(), buffer, NULL);
4772 // Attempt to submit cmd buffer
4773 VkSubmitInfo submit_info = {};
4774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4775 submit_info.commandBufferCount = 1;
4776 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4778 m_errorMonitor->VerifyFound();
4779 // Cleanup
4780 vkFreeMemory(m_device->device(), mem, NULL);
4781
4782 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4783 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4784 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4785}
4786
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004787TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4788 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4789 "due to a bound descriptor sets with a combined image "
4790 "sampler having their image, sampler, and descriptor set "
4791 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004792 "submit associated cmd buffers. Attempt to destroy a "
4793 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004794 ASSERT_NO_FATAL_FAILURE(InitState());
4795 ASSERT_NO_FATAL_FAILURE(InitViewport());
4796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4797
4798 VkDescriptorPoolSize ds_type_count = {};
4799 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4800 ds_type_count.descriptorCount = 1;
4801
4802 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4803 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4804 ds_pool_ci.pNext = NULL;
4805 ds_pool_ci.maxSets = 1;
4806 ds_pool_ci.poolSizeCount = 1;
4807 ds_pool_ci.pPoolSizes = &ds_type_count;
4808
4809 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004810 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004811 ASSERT_VK_SUCCESS(err);
4812
4813 VkDescriptorSetLayoutBinding dsl_binding = {};
4814 dsl_binding.binding = 0;
4815 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4816 dsl_binding.descriptorCount = 1;
4817 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4818 dsl_binding.pImmutableSamplers = NULL;
4819
4820 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4821 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4822 ds_layout_ci.pNext = NULL;
4823 ds_layout_ci.bindingCount = 1;
4824 ds_layout_ci.pBindings = &dsl_binding;
4825 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004826 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004827 ASSERT_VK_SUCCESS(err);
4828
4829 VkDescriptorSet descriptorSet;
4830 VkDescriptorSetAllocateInfo alloc_info = {};
4831 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4832 alloc_info.descriptorSetCount = 1;
4833 alloc_info.descriptorPool = ds_pool;
4834 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004835 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004836 ASSERT_VK_SUCCESS(err);
4837
4838 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4839 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4840 pipeline_layout_ci.pNext = NULL;
4841 pipeline_layout_ci.setLayoutCount = 1;
4842 pipeline_layout_ci.pSetLayouts = &ds_layout;
4843
4844 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004846 ASSERT_VK_SUCCESS(err);
4847
4848 // Create images to update the descriptor with
4849 VkImage image;
4850 VkImage image2;
4851 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4852 const int32_t tex_width = 32;
4853 const int32_t tex_height = 32;
4854 VkImageCreateInfo image_create_info = {};
4855 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4856 image_create_info.pNext = NULL;
4857 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4858 image_create_info.format = tex_format;
4859 image_create_info.extent.width = tex_width;
4860 image_create_info.extent.height = tex_height;
4861 image_create_info.extent.depth = 1;
4862 image_create_info.mipLevels = 1;
4863 image_create_info.arrayLayers = 1;
4864 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4865 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4866 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4867 image_create_info.flags = 0;
4868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4869 ASSERT_VK_SUCCESS(err);
4870 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4871 ASSERT_VK_SUCCESS(err);
4872
4873 VkMemoryRequirements memory_reqs;
4874 VkDeviceMemory image_memory;
4875 bool pass;
4876 VkMemoryAllocateInfo memory_info = {};
4877 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4878 memory_info.pNext = NULL;
4879 memory_info.allocationSize = 0;
4880 memory_info.memoryTypeIndex = 0;
4881 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4882 // Allocate enough memory for both images
4883 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004884 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004885 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004887 ASSERT_VK_SUCCESS(err);
4888 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4889 ASSERT_VK_SUCCESS(err);
4890 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004891 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004892 ASSERT_VK_SUCCESS(err);
4893
4894 VkImageViewCreateInfo image_view_create_info = {};
4895 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4896 image_view_create_info.image = image;
4897 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
4898 image_view_create_info.format = tex_format;
4899 image_view_create_info.subresourceRange.layerCount = 1;
4900 image_view_create_info.subresourceRange.baseMipLevel = 0;
4901 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004902 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004903
4904 VkImageView view;
4905 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004906 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004907 ASSERT_VK_SUCCESS(err);
4908 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004909 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004910 ASSERT_VK_SUCCESS(err);
4911 // Create Samplers
4912 VkSamplerCreateInfo sampler_ci = {};
4913 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4914 sampler_ci.pNext = NULL;
4915 sampler_ci.magFilter = VK_FILTER_NEAREST;
4916 sampler_ci.minFilter = VK_FILTER_NEAREST;
4917 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4918 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4919 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4920 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4921 sampler_ci.mipLodBias = 1.0;
4922 sampler_ci.anisotropyEnable = VK_FALSE;
4923 sampler_ci.maxAnisotropy = 1;
4924 sampler_ci.compareEnable = VK_FALSE;
4925 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4926 sampler_ci.minLod = 1.0;
4927 sampler_ci.maxLod = 1.0;
4928 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4929 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4930 VkSampler sampler;
4931 VkSampler sampler2;
4932 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4933 ASSERT_VK_SUCCESS(err);
4934 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
4935 ASSERT_VK_SUCCESS(err);
4936 // Update descriptor with image and sampler
4937 VkDescriptorImageInfo img_info = {};
4938 img_info.sampler = sampler;
4939 img_info.imageView = view;
4940 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4941
4942 VkWriteDescriptorSet descriptor_write;
4943 memset(&descriptor_write, 0, sizeof(descriptor_write));
4944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4945 descriptor_write.dstSet = descriptorSet;
4946 descriptor_write.dstBinding = 0;
4947 descriptor_write.descriptorCount = 1;
4948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4949 descriptor_write.pImageInfo = &img_info;
4950
4951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4952
4953 // Create PSO to be used for draw-time errors below
4954 char const *vsSource = "#version 450\n"
4955 "\n"
4956 "out gl_PerVertex { \n"
4957 " vec4 gl_Position;\n"
4958 "};\n"
4959 "void main(){\n"
4960 " gl_Position = vec4(1);\n"
4961 "}\n";
4962 char const *fsSource = "#version 450\n"
4963 "\n"
4964 "layout(set=0, binding=0) uniform sampler2D s;\n"
4965 "layout(location=0) out vec4 x;\n"
4966 "void main(){\n"
4967 " x = texture(s, vec2(1));\n"
4968 "}\n";
4969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4971 VkPipelineObj pipe(m_device);
4972 pipe.AddShader(&vs);
4973 pipe.AddShader(&fs);
4974 pipe.AddColorAttachment();
4975 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4976
4977 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004979 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004980 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4981 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4982 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004983 Draw(1, 0, 0, 0);
4984 EndCommandBuffer();
4985 // Destroy sampler invalidates the cmd buffer, causing error on submit
4986 vkDestroySampler(m_device->device(), sampler, NULL);
4987 // Attempt to submit cmd buffer
4988 VkSubmitInfo submit_info = {};
4989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4990 submit_info.commandBufferCount = 1;
4991 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4993 m_errorMonitor->VerifyFound();
4994 // Now re-update descriptor with valid sampler and delete image
4995 img_info.sampler = sampler2;
4996 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004998 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004999 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5000 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5001 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005002 Draw(1, 0, 0, 0);
5003 EndCommandBuffer();
5004 // Destroy image invalidates the cmd buffer, causing error on submit
5005 vkDestroyImage(m_device->device(), image, NULL);
5006 // Attempt to submit cmd buffer
5007 submit_info = {};
5008 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5009 submit_info.commandBufferCount = 1;
5010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5011 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5012 m_errorMonitor->VerifyFound();
5013 // Now update descriptor to be valid, but then free descriptor
5014 img_info.imageView = view2;
5015 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005017 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005018 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5019 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5020 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005021 Draw(1, 0, 0, 0);
5022 EndCommandBuffer();
5023 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005025 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005026 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005027 // Attempt to submit cmd buffer
5028 submit_info = {};
5029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5030 submit_info.commandBufferCount = 1;
5031 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5032 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5033 m_errorMonitor->VerifyFound();
5034 // Cleanup
5035 vkFreeMemory(m_device->device(), image_memory, NULL);
5036 vkDestroySampler(m_device->device(), sampler2, NULL);
5037 vkDestroyImage(m_device->device(), image2, NULL);
5038 vkDestroyImageView(m_device->device(), view, NULL);
5039 vkDestroyImageView(m_device->device(), view2, NULL);
5040 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5041 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5042 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5043}
5044
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005045TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5046 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5047 ASSERT_NO_FATAL_FAILURE(InitState());
5048 ASSERT_NO_FATAL_FAILURE(InitViewport());
5049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5050
5051 VkDescriptorPoolSize ds_type_count = {};
5052 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5053 ds_type_count.descriptorCount = 1;
5054
5055 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5056 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5057 ds_pool_ci.pNext = NULL;
5058 ds_pool_ci.maxSets = 1;
5059 ds_pool_ci.poolSizeCount = 1;
5060 ds_pool_ci.pPoolSizes = &ds_type_count;
5061
5062 VkDescriptorPool ds_pool;
5063 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5064 ASSERT_VK_SUCCESS(err);
5065
5066 VkDescriptorSetLayoutBinding dsl_binding = {};
5067 dsl_binding.binding = 0;
5068 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5069 dsl_binding.descriptorCount = 1;
5070 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5071 dsl_binding.pImmutableSamplers = NULL;
5072
5073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5075 ds_layout_ci.pNext = NULL;
5076 ds_layout_ci.bindingCount = 1;
5077 ds_layout_ci.pBindings = &dsl_binding;
5078 VkDescriptorSetLayout ds_layout;
5079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5080 ASSERT_VK_SUCCESS(err);
5081
5082 VkDescriptorSet descriptor_set;
5083 VkDescriptorSetAllocateInfo alloc_info = {};
5084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5085 alloc_info.descriptorSetCount = 1;
5086 alloc_info.descriptorPool = ds_pool;
5087 alloc_info.pSetLayouts = &ds_layout;
5088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5089 ASSERT_VK_SUCCESS(err);
5090
5091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5093 pipeline_layout_ci.pNext = NULL;
5094 pipeline_layout_ci.setLayoutCount = 1;
5095 pipeline_layout_ci.pSetLayouts = &ds_layout;
5096
5097 VkPipelineLayout pipeline_layout;
5098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5099 ASSERT_VK_SUCCESS(err);
5100
5101 // Create image to update the descriptor with
5102 VkImageObj image(m_device);
5103 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5104 ASSERT_TRUE(image.initialized());
5105
5106 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5107 // Create Sampler
5108 VkSamplerCreateInfo sampler_ci = {};
5109 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5110 sampler_ci.pNext = NULL;
5111 sampler_ci.magFilter = VK_FILTER_NEAREST;
5112 sampler_ci.minFilter = VK_FILTER_NEAREST;
5113 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5114 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5115 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5116 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5117 sampler_ci.mipLodBias = 1.0;
5118 sampler_ci.anisotropyEnable = VK_FALSE;
5119 sampler_ci.maxAnisotropy = 1;
5120 sampler_ci.compareEnable = VK_FALSE;
5121 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5122 sampler_ci.minLod = 1.0;
5123 sampler_ci.maxLod = 1.0;
5124 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5125 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5126 VkSampler sampler;
5127 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5128 ASSERT_VK_SUCCESS(err);
5129 // Update descriptor with image and sampler
5130 VkDescriptorImageInfo img_info = {};
5131 img_info.sampler = sampler;
5132 img_info.imageView = view;
5133 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5134
5135 VkWriteDescriptorSet descriptor_write;
5136 memset(&descriptor_write, 0, sizeof(descriptor_write));
5137 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5138 descriptor_write.dstSet = descriptor_set;
5139 descriptor_write.dstBinding = 0;
5140 descriptor_write.descriptorCount = 1;
5141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5142 descriptor_write.pImageInfo = &img_info;
5143
5144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5145
5146 // Create PSO to be used for draw-time errors below
5147 char const *vsSource = "#version 450\n"
5148 "\n"
5149 "out gl_PerVertex { \n"
5150 " vec4 gl_Position;\n"
5151 "};\n"
5152 "void main(){\n"
5153 " gl_Position = vec4(1);\n"
5154 "}\n";
5155 char const *fsSource = "#version 450\n"
5156 "\n"
5157 "layout(set=0, binding=0) uniform sampler2D s;\n"
5158 "layout(location=0) out vec4 x;\n"
5159 "void main(){\n"
5160 " x = texture(s, vec2(1));\n"
5161 "}\n";
5162 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5163 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5164 VkPipelineObj pipe(m_device);
5165 pipe.AddShader(&vs);
5166 pipe.AddShader(&fs);
5167 pipe.AddColorAttachment();
5168 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5169
5170 BeginCommandBuffer();
5171 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5172 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5173 &descriptor_set, 0, NULL);
5174 Draw(1, 0, 0, 0);
5175 EndCommandBuffer();
5176 // Submit cmd buffer to put pool in-flight
5177 VkSubmitInfo submit_info = {};
5178 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5179 submit_info.commandBufferCount = 1;
5180 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5181 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5182 // Destroy pool while in-flight, causing error
5183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5184 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5185 m_errorMonitor->VerifyFound();
5186 vkQueueWaitIdle(m_device->m_queue);
5187 // Cleanup
5188 vkDestroySampler(m_device->device(), sampler, NULL);
5189 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5190 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5191 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5192}
5193
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005194TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5195 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5196 ASSERT_NO_FATAL_FAILURE(InitState());
5197 ASSERT_NO_FATAL_FAILURE(InitViewport());
5198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5199
5200 VkDescriptorPoolSize ds_type_count = {};
5201 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5202 ds_type_count.descriptorCount = 1;
5203
5204 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5205 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5206 ds_pool_ci.pNext = NULL;
5207 ds_pool_ci.maxSets = 1;
5208 ds_pool_ci.poolSizeCount = 1;
5209 ds_pool_ci.pPoolSizes = &ds_type_count;
5210
5211 VkDescriptorPool ds_pool;
5212 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5213 ASSERT_VK_SUCCESS(err);
5214
5215 VkDescriptorSetLayoutBinding dsl_binding = {};
5216 dsl_binding.binding = 0;
5217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5218 dsl_binding.descriptorCount = 1;
5219 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5220 dsl_binding.pImmutableSamplers = NULL;
5221
5222 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5223 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5224 ds_layout_ci.pNext = NULL;
5225 ds_layout_ci.bindingCount = 1;
5226 ds_layout_ci.pBindings = &dsl_binding;
5227 VkDescriptorSetLayout ds_layout;
5228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5229 ASSERT_VK_SUCCESS(err);
5230
5231 VkDescriptorSet descriptorSet;
5232 VkDescriptorSetAllocateInfo alloc_info = {};
5233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5234 alloc_info.descriptorSetCount = 1;
5235 alloc_info.descriptorPool = ds_pool;
5236 alloc_info.pSetLayouts = &ds_layout;
5237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5238 ASSERT_VK_SUCCESS(err);
5239
5240 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5241 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5242 pipeline_layout_ci.pNext = NULL;
5243 pipeline_layout_ci.setLayoutCount = 1;
5244 pipeline_layout_ci.pSetLayouts = &ds_layout;
5245
5246 VkPipelineLayout pipeline_layout;
5247 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5248 ASSERT_VK_SUCCESS(err);
5249
5250 // Create images to update the descriptor with
5251 VkImage image;
5252 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5253 const int32_t tex_width = 32;
5254 const int32_t tex_height = 32;
5255 VkImageCreateInfo image_create_info = {};
5256 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5257 image_create_info.pNext = NULL;
5258 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5259 image_create_info.format = tex_format;
5260 image_create_info.extent.width = tex_width;
5261 image_create_info.extent.height = tex_height;
5262 image_create_info.extent.depth = 1;
5263 image_create_info.mipLevels = 1;
5264 image_create_info.arrayLayers = 1;
5265 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5266 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5267 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5268 image_create_info.flags = 0;
5269 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5270 ASSERT_VK_SUCCESS(err);
5271 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5272 VkMemoryRequirements memory_reqs;
5273 VkDeviceMemory image_memory;
5274 bool pass;
5275 VkMemoryAllocateInfo memory_info = {};
5276 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5277 memory_info.pNext = NULL;
5278 memory_info.allocationSize = 0;
5279 memory_info.memoryTypeIndex = 0;
5280 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5281 // Allocate enough memory for image
5282 memory_info.allocationSize = memory_reqs.size;
5283 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5284 ASSERT_TRUE(pass);
5285 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5286 ASSERT_VK_SUCCESS(err);
5287 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5288 ASSERT_VK_SUCCESS(err);
5289
5290 VkImageViewCreateInfo image_view_create_info = {};
5291 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5292 image_view_create_info.image = image;
5293 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5294 image_view_create_info.format = tex_format;
5295 image_view_create_info.subresourceRange.layerCount = 1;
5296 image_view_create_info.subresourceRange.baseMipLevel = 0;
5297 image_view_create_info.subresourceRange.levelCount = 1;
5298 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5299
5300 VkImageView view;
5301 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5302 ASSERT_VK_SUCCESS(err);
5303 // Create Samplers
5304 VkSamplerCreateInfo sampler_ci = {};
5305 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5306 sampler_ci.pNext = NULL;
5307 sampler_ci.magFilter = VK_FILTER_NEAREST;
5308 sampler_ci.minFilter = VK_FILTER_NEAREST;
5309 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5310 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5311 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5312 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5313 sampler_ci.mipLodBias = 1.0;
5314 sampler_ci.anisotropyEnable = VK_FALSE;
5315 sampler_ci.maxAnisotropy = 1;
5316 sampler_ci.compareEnable = VK_FALSE;
5317 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5318 sampler_ci.minLod = 1.0;
5319 sampler_ci.maxLod = 1.0;
5320 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5321 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5322 VkSampler sampler;
5323 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5324 ASSERT_VK_SUCCESS(err);
5325 // Update descriptor with image and sampler
5326 VkDescriptorImageInfo img_info = {};
5327 img_info.sampler = sampler;
5328 img_info.imageView = view;
5329 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5330
5331 VkWriteDescriptorSet descriptor_write;
5332 memset(&descriptor_write, 0, sizeof(descriptor_write));
5333 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5334 descriptor_write.dstSet = descriptorSet;
5335 descriptor_write.dstBinding = 0;
5336 descriptor_write.descriptorCount = 1;
5337 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5338 descriptor_write.pImageInfo = &img_info;
5339 // Break memory binding and attempt update
5340 vkFreeMemory(m_device->device(), image_memory, nullptr);
5341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005342 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5344 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5345 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5346 m_errorMonitor->VerifyFound();
5347 // Cleanup
5348 vkDestroyImage(m_device->device(), image, NULL);
5349 vkDestroySampler(m_device->device(), sampler, NULL);
5350 vkDestroyImageView(m_device->device(), view, NULL);
5351 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5352 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5353 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5354}
5355
Karl Schultz6addd812016-02-02 17:17:23 -07005356TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005357 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5358 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005359 // Create a valid cmd buffer
5360 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005361 uint64_t fake_pipeline_handle = 0xbaad6001;
5362 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005363 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5365
5366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005367 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005368 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005369 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005370
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005371 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005372 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 -06005373 Draw(1, 0, 0, 0);
5374 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005375
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005376 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005378 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005379 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5380 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005381}
5382
Karl Schultz6addd812016-02-02 17:17:23 -07005383TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005384 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005385 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005388
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005389 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005390 ASSERT_NO_FATAL_FAILURE(InitViewport());
5391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005392 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005393 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5394 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005395
5396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5398 ds_pool_ci.pNext = NULL;
5399 ds_pool_ci.maxSets = 1;
5400 ds_pool_ci.poolSizeCount = 1;
5401 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005402
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005403 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005405 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005406
Tony Barboureb254902015-07-15 12:50:33 -06005407 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005408 dsl_binding.binding = 0;
5409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5410 dsl_binding.descriptorCount = 1;
5411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5412 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005413
Tony Barboureb254902015-07-15 12:50:33 -06005414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5416 ds_layout_ci.pNext = NULL;
5417 ds_layout_ci.bindingCount = 1;
5418 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005421 ASSERT_VK_SUCCESS(err);
5422
5423 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005424 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005426 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005427 alloc_info.descriptorPool = ds_pool;
5428 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005430 ASSERT_VK_SUCCESS(err);
5431
Tony Barboureb254902015-07-15 12:50:33 -06005432 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005433 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5434 pipeline_layout_ci.pNext = NULL;
5435 pipeline_layout_ci.setLayoutCount = 1;
5436 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005437
5438 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005439 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005440 ASSERT_VK_SUCCESS(err);
5441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005442 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005443 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005444 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005445 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005446
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005447 VkPipelineObj pipe(m_device);
5448 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005449 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005450 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005451 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005452
5453 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005454 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5455 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5456 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005458 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005459
Chia-I Wuf7458c52015-10-26 21:10:41 +08005460 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005463}
5464
Karl Schultz6addd812016-02-02 17:17:23 -07005465TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005466 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005467 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5470 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005471
5472 ASSERT_NO_FATAL_FAILURE(InitState());
5473 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005474 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5475 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005476
5477 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005478 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5479 ds_pool_ci.pNext = NULL;
5480 ds_pool_ci.maxSets = 1;
5481 ds_pool_ci.poolSizeCount = 1;
5482 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005483
5484 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005485 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005486 ASSERT_VK_SUCCESS(err);
5487
5488 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005489 dsl_binding.binding = 0;
5490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5491 dsl_binding.descriptorCount = 1;
5492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005494
5495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5497 ds_layout_ci.pNext = NULL;
5498 ds_layout_ci.bindingCount = 1;
5499 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005500 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005502 ASSERT_VK_SUCCESS(err);
5503
5504 VkDescriptorSet descriptorSet;
5505 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005506 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005507 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005508 alloc_info.descriptorPool = ds_pool;
5509 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005510 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005511 ASSERT_VK_SUCCESS(err);
5512
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005513 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005514 VkWriteDescriptorSet descriptor_write;
5515 memset(&descriptor_write, 0, sizeof(descriptor_write));
5516 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5517 descriptor_write.dstSet = descriptorSet;
5518 descriptor_write.dstBinding = 0;
5519 descriptor_write.descriptorCount = 1;
5520 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5521 descriptor_write.pTexelBufferView = &view;
5522
5523 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5524
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005525 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005526
5527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5528 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5529}
5530
Mark Youngd339ba32016-05-30 13:28:35 -06005531TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005532 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 -06005533
5534 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005536 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005537
5538 ASSERT_NO_FATAL_FAILURE(InitState());
5539
5540 // Create a buffer with no bound memory and then attempt to create
5541 // a buffer view.
5542 VkBufferCreateInfo buff_ci = {};
5543 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005544 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005545 buff_ci.size = 256;
5546 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5547 VkBuffer buffer;
5548 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5549 ASSERT_VK_SUCCESS(err);
5550
5551 VkBufferViewCreateInfo buff_view_ci = {};
5552 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5553 buff_view_ci.buffer = buffer;
5554 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5555 buff_view_ci.range = VK_WHOLE_SIZE;
5556 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005557 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005558
5559 m_errorMonitor->VerifyFound();
5560 vkDestroyBuffer(m_device->device(), buffer, NULL);
5561 // If last error is success, it still created the view, so delete it.
5562 if (err == VK_SUCCESS) {
5563 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5564 }
5565}
5566
Karl Schultz6addd812016-02-02 17:17:23 -07005567TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5568 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5569 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005570 // 1. No dynamicOffset supplied
5571 // 2. Too many dynamicOffsets supplied
5572 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005573 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5575 "0 dynamicOffsets are left in "
5576 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005577
5578 ASSERT_NO_FATAL_FAILURE(InitState());
5579 ASSERT_NO_FATAL_FAILURE(InitViewport());
5580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5581
5582 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005583 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5584 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005585
5586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5588 ds_pool_ci.pNext = NULL;
5589 ds_pool_ci.maxSets = 1;
5590 ds_pool_ci.poolSizeCount = 1;
5591 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005592
5593 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005594 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005595 ASSERT_VK_SUCCESS(err);
5596
5597 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005598 dsl_binding.binding = 0;
5599 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5600 dsl_binding.descriptorCount = 1;
5601 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5602 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005603
5604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5606 ds_layout_ci.pNext = NULL;
5607 ds_layout_ci.bindingCount = 1;
5608 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005609 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005610 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005611 ASSERT_VK_SUCCESS(err);
5612
5613 VkDescriptorSet descriptorSet;
5614 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005615 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005616 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005617 alloc_info.descriptorPool = ds_pool;
5618 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005620 ASSERT_VK_SUCCESS(err);
5621
5622 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005623 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5624 pipeline_layout_ci.pNext = NULL;
5625 pipeline_layout_ci.setLayoutCount = 1;
5626 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005627
5628 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005629 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005630 ASSERT_VK_SUCCESS(err);
5631
5632 // Create a buffer to update the descriptor with
5633 uint32_t qfi = 0;
5634 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005635 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5636 buffCI.size = 1024;
5637 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5638 buffCI.queueFamilyIndexCount = 1;
5639 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005640
5641 VkBuffer dyub;
5642 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5643 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005644 // Allocate memory and bind to buffer so we can make it to the appropriate
5645 // error
5646 VkMemoryAllocateInfo mem_alloc = {};
5647 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5648 mem_alloc.pNext = NULL;
5649 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005650 mem_alloc.memoryTypeIndex = 0;
5651
5652 VkMemoryRequirements memReqs;
5653 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005655 if (!pass) {
5656 vkDestroyBuffer(m_device->device(), dyub, NULL);
5657 return;
5658 }
5659
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005660 VkDeviceMemory mem;
5661 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5662 ASSERT_VK_SUCCESS(err);
5663 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5664 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005665 // Correctly update descriptor to avoid "NOT_UPDATED" error
5666 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005667 buffInfo.buffer = dyub;
5668 buffInfo.offset = 0;
5669 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005670
5671 VkWriteDescriptorSet descriptor_write;
5672 memset(&descriptor_write, 0, sizeof(descriptor_write));
5673 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5674 descriptor_write.dstSet = descriptorSet;
5675 descriptor_write.dstBinding = 0;
5676 descriptor_write.descriptorCount = 1;
5677 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5678 descriptor_write.pBufferInfo = &buffInfo;
5679
5680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5681
5682 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5684 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005685 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005686 uint32_t pDynOff[2] = {512, 756};
5687 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5689 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5690 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5691 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005692 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005693 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5695 "offset 0 and range 1024 that "
5696 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005697 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005698 char const *vsSource = "#version 450\n"
5699 "\n"
5700 "out gl_PerVertex { \n"
5701 " vec4 gl_Position;\n"
5702 "};\n"
5703 "void main(){\n"
5704 " gl_Position = vec4(1);\n"
5705 "}\n";
5706 char const *fsSource = "#version 450\n"
5707 "\n"
5708 "layout(location=0) out vec4 x;\n"
5709 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5710 "void main(){\n"
5711 " x = vec4(bar.y);\n"
5712 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5715 VkPipelineObj pipe(m_device);
5716 pipe.AddShader(&vs);
5717 pipe.AddShader(&fs);
5718 pipe.AddColorAttachment();
5719 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005722 // This update should succeed, but offset size of 512 will overstep buffer
5723 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5725 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005726 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005727 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005728
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005729 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005730 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005731
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005732 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5735}
5736
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005737TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5738 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5739 "that doesn't have memory bound");
5740 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005742 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5744 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005745
5746 ASSERT_NO_FATAL_FAILURE(InitState());
5747 ASSERT_NO_FATAL_FAILURE(InitViewport());
5748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5749
5750 VkDescriptorPoolSize ds_type_count = {};
5751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5752 ds_type_count.descriptorCount = 1;
5753
5754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5756 ds_pool_ci.pNext = NULL;
5757 ds_pool_ci.maxSets = 1;
5758 ds_pool_ci.poolSizeCount = 1;
5759 ds_pool_ci.pPoolSizes = &ds_type_count;
5760
5761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005763 ASSERT_VK_SUCCESS(err);
5764
5765 VkDescriptorSetLayoutBinding dsl_binding = {};
5766 dsl_binding.binding = 0;
5767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5768 dsl_binding.descriptorCount = 1;
5769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5770 dsl_binding.pImmutableSamplers = NULL;
5771
5772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5774 ds_layout_ci.pNext = NULL;
5775 ds_layout_ci.bindingCount = 1;
5776 ds_layout_ci.pBindings = &dsl_binding;
5777 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSet descriptorSet;
5782 VkDescriptorSetAllocateInfo alloc_info = {};
5783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5784 alloc_info.descriptorSetCount = 1;
5785 alloc_info.descriptorPool = ds_pool;
5786 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005788 ASSERT_VK_SUCCESS(err);
5789
5790 // Create a buffer to update the descriptor with
5791 uint32_t qfi = 0;
5792 VkBufferCreateInfo buffCI = {};
5793 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5794 buffCI.size = 1024;
5795 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5796 buffCI.queueFamilyIndexCount = 1;
5797 buffCI.pQueueFamilyIndices = &qfi;
5798
5799 VkBuffer dyub;
5800 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5801 ASSERT_VK_SUCCESS(err);
5802
5803 // Attempt to update descriptor without binding memory to it
5804 VkDescriptorBufferInfo buffInfo = {};
5805 buffInfo.buffer = dyub;
5806 buffInfo.offset = 0;
5807 buffInfo.range = 1024;
5808
5809 VkWriteDescriptorSet descriptor_write;
5810 memset(&descriptor_write, 0, sizeof(descriptor_write));
5811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5812 descriptor_write.dstSet = descriptorSet;
5813 descriptor_write.dstBinding = 0;
5814 descriptor_write.descriptorCount = 1;
5815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5816 descriptor_write.pBufferInfo = &buffInfo;
5817
5818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5819 m_errorMonitor->VerifyFound();
5820
5821 vkDestroyBuffer(m_device->device(), dyub, NULL);
5822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5823 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5824}
5825
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005826TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005827 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 ASSERT_NO_FATAL_FAILURE(InitViewport());
5830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5831
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005832 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005833 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005834 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5835 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5836 pipeline_layout_ci.pushConstantRangeCount = 1;
5837 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5838
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005839 //
5840 // Check for invalid push constant ranges in pipeline layouts.
5841 //
5842 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005843 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005844 char const *msg;
5845 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005846
Karl Schultzc81037d2016-05-12 08:11:23 -06005847 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5848 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5849 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5850 "vkCreatePipelineLayout() call has push constants index 0 with "
5851 "size 0."},
5852 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5853 "vkCreatePipelineLayout() call has push constants index 0 with "
5854 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005855 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005856 "vkCreatePipelineLayout() call has push constants index 0 with "
5857 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005858 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005859 "vkCreatePipelineLayout() call has push constants index 0 with "
5860 "size 0."},
5861 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5862 "vkCreatePipelineLayout() call has push constants index 0 with "
5863 "offset 1. Offset must"},
5864 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5865 "vkCreatePipelineLayout() call has push constants index 0 "
5866 "with offset "},
5867 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5868 "vkCreatePipelineLayout() call has push constants "
5869 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005870 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005871 "vkCreatePipelineLayout() call has push constants index 0 "
5872 "with offset "},
5873 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5874 "vkCreatePipelineLayout() call has push "
5875 "constants index 0 with offset "},
5876 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5877 "vkCreatePipelineLayout() call has push "
5878 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005879 }};
5880
5881 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005882 for (const auto &iter : range_tests) {
5883 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
5885 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005886 m_errorMonitor->VerifyFound();
5887 if (VK_SUCCESS == err) {
5888 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5889 }
5890 }
5891
5892 // Check for invalid stage flag
5893 pc_range.offset = 0;
5894 pc_range.size = 16;
5895 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005896 m_errorMonitor->SetDesiredFailureMsg(
5897 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5898 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005899 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005900 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005901 if (VK_SUCCESS == err) {
5902 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5903 }
5904
5905 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005906 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005907 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005908 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005909 char const *msg;
5910 };
5911
Karl Schultzc81037d2016-05-12 08:11:23 -06005912 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005913 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5914 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5915 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5916 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5917 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005918 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005919 {
5920 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5921 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5922 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5923 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5924 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005925 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005926 },
5927 {
5928 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5929 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5930 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5931 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5932 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005933 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005934 },
5935 {
5936 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5937 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5938 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5939 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5940 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005941 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005942 },
5943 {
5944 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5945 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5946 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5947 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5948 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005949 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005950 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005951
Karl Schultzc81037d2016-05-12 08:11:23 -06005952 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005953 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005954 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
5956 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005957 m_errorMonitor->VerifyFound();
5958 if (VK_SUCCESS == err) {
5959 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5960 }
5961 }
5962
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005963 //
5964 // CmdPushConstants tests
5965 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005966 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005967
5968 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005969 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
5970 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06005971 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5972 "vkCmdPushConstants() call has push constants with size 1. Size "
5973 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005974 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005975 "vkCmdPushConstants() call has push constants with size 1. Size "
5976 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005977 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005978 "vkCmdPushConstants() call has push constants with offset 1. "
5979 "Offset must be a multiple of 4."},
5980 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5981 "vkCmdPushConstants() call has push constants with offset 1. "
5982 "Offset must be a multiple of 4."},
5983 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5984 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5985 "0x1 not within flag-matching ranges in pipeline layout"},
5986 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5987 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5988 "0x1 not within flag-matching ranges in pipeline layout"},
5989 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5990 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5991 "0x1 not within flag-matching ranges in pipeline layout"},
5992 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5993 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5994 "0x1 not within flag-matching ranges in pipeline layout"},
5995 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5996 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5997 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005998 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005999 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6000 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006001 }};
6002
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006003 BeginCommandBuffer();
6004
6005 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006006 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006007 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006008 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006009 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006010 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006011 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006012 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006013 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6015 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006016 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006017 m_errorMonitor->VerifyFound();
6018 }
6019
6020 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006022 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006023 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006024 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006025
Karl Schultzc81037d2016-05-12 08:11:23 -06006026 // overlapping range tests with cmd
6027 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6028 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6029 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6030 "0x1 not within flag-matching ranges in pipeline layout"},
6031 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6032 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6033 "0x1 not within flag-matching ranges in pipeline layout"},
6034 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6035 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6036 "0x1 not within flag-matching ranges in pipeline layout"},
6037 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006038 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006039 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006040 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6041 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006042 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006043 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006044 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006045 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006046 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006047 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6049 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006050 iter.range.size, dummy_values);
6051 m_errorMonitor->VerifyFound();
6052 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006053 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6054
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006055 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006056}
6057
Karl Schultz6addd812016-02-02 17:17:23 -07006058TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006059 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006060 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006061
6062 ASSERT_NO_FATAL_FAILURE(InitState());
6063 ASSERT_NO_FATAL_FAILURE(InitViewport());
6064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6065
Mike Stroyanb8a61002016-06-20 16:00:28 -06006066 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6067 VkImageTiling tiling;
6068 VkFormatProperties format_properties;
6069 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006070 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006071 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006073 tiling = VK_IMAGE_TILING_OPTIMAL;
6074 } else {
6075 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6076 "skipped.\n");
6077 return;
6078 }
6079
Tobin Ehlis559c6382015-11-05 09:52:49 -07006080 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6081 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006082 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6083 ds_type_count[0].descriptorCount = 10;
6084 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6085 ds_type_count[1].descriptorCount = 2;
6086 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6087 ds_type_count[2].descriptorCount = 2;
6088 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6089 ds_type_count[3].descriptorCount = 5;
6090 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6091 // type
6092 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6093 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6094 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006095
6096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6098 ds_pool_ci.pNext = NULL;
6099 ds_pool_ci.maxSets = 5;
6100 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6101 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006102
6103 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006104 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006105 ASSERT_VK_SUCCESS(err);
6106
6107 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6108 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006109 dsl_binding[0].binding = 0;
6110 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6111 dsl_binding[0].descriptorCount = 5;
6112 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6113 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006114
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006115 // Create layout identical to set0 layout but w/ different stageFlags
6116 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006117 dsl_fs_stage_only.binding = 0;
6118 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6119 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006120 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6121 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006122 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6125 ds_layout_ci.pNext = NULL;
6126 ds_layout_ci.bindingCount = 1;
6127 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006128 static const uint32_t NUM_LAYOUTS = 4;
6129 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006130 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006131 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6132 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006133 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006134 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006135 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006136 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006137 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006138 dsl_binding[0].binding = 0;
6139 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006140 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006141 dsl_binding[1].binding = 1;
6142 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6143 dsl_binding[1].descriptorCount = 2;
6144 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6145 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006146 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006147 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006149 ASSERT_VK_SUCCESS(err);
6150 dsl_binding[0].binding = 0;
6151 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006152 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006153 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006155 ASSERT_VK_SUCCESS(err);
6156 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006157 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006159 ASSERT_VK_SUCCESS(err);
6160
6161 static const uint32_t NUM_SETS = 4;
6162 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6163 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006164 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006165 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006166 alloc_info.descriptorPool = ds_pool;
6167 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006169 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006170 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006171 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006172 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006174 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006175
6176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6178 pipeline_layout_ci.pNext = NULL;
6179 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6180 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006181
6182 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006183 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006184 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006185 // Create pipelineLayout with only one setLayout
6186 pipeline_layout_ci.setLayoutCount = 1;
6187 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006188 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006189 ASSERT_VK_SUCCESS(err);
6190 // Create pipelineLayout with 2 descriptor setLayout at index 0
6191 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6192 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006193 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006194 ASSERT_VK_SUCCESS(err);
6195 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6196 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6197 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006199 ASSERT_VK_SUCCESS(err);
6200 // Create pipelineLayout with UB type, but stageFlags for FS only
6201 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6202 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006203 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006204 ASSERT_VK_SUCCESS(err);
6205 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6206 VkDescriptorSetLayout pl_bad_s0[2] = {};
6207 pl_bad_s0[0] = ds_layout_fs_only;
6208 pl_bad_s0[1] = ds_layout[1];
6209 pipeline_layout_ci.setLayoutCount = 2;
6210 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6211 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006213 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006214
6215 // Create a buffer to update the descriptor with
6216 uint32_t qfi = 0;
6217 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006218 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6219 buffCI.size = 1024;
6220 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6221 buffCI.queueFamilyIndexCount = 1;
6222 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006223
6224 VkBuffer dyub;
6225 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6226 ASSERT_VK_SUCCESS(err);
6227 // Correctly update descriptor to avoid "NOT_UPDATED" error
6228 static const uint32_t NUM_BUFFS = 5;
6229 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006230 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006231 buffInfo[i].buffer = dyub;
6232 buffInfo[i].offset = 0;
6233 buffInfo[i].range = 1024;
6234 }
Karl Schultz6addd812016-02-02 17:17:23 -07006235 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006236 const int32_t tex_width = 32;
6237 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006238 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6240 image_create_info.pNext = NULL;
6241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6242 image_create_info.format = tex_format;
6243 image_create_info.extent.width = tex_width;
6244 image_create_info.extent.height = tex_height;
6245 image_create_info.extent.depth = 1;
6246 image_create_info.mipLevels = 1;
6247 image_create_info.arrayLayers = 1;
6248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006249 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006250 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006251 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006252 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6253 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006254
Karl Schultz6addd812016-02-02 17:17:23 -07006255 VkMemoryRequirements memReqs;
6256 VkDeviceMemory imageMem;
6257 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006258 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006259 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6260 memAlloc.pNext = NULL;
6261 memAlloc.allocationSize = 0;
6262 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006263 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6264 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006265 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006266 ASSERT_TRUE(pass);
6267 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6268 ASSERT_VK_SUCCESS(err);
6269 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6270 ASSERT_VK_SUCCESS(err);
6271
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006272 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006273 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6274 image_view_create_info.image = image;
6275 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6276 image_view_create_info.format = tex_format;
6277 image_view_create_info.subresourceRange.layerCount = 1;
6278 image_view_create_info.subresourceRange.baseMipLevel = 0;
6279 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006280 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006281
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006282 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006283 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006284 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006285 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006286 imageInfo[0].imageView = view;
6287 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6288 imageInfo[1].imageView = view;
6289 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006290 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006291 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006292 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006293 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006294
6295 static const uint32_t NUM_SET_UPDATES = 3;
6296 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6297 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6298 descriptor_write[0].dstSet = descriptorSet[0];
6299 descriptor_write[0].dstBinding = 0;
6300 descriptor_write[0].descriptorCount = 5;
6301 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6302 descriptor_write[0].pBufferInfo = buffInfo;
6303 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6304 descriptor_write[1].dstSet = descriptorSet[1];
6305 descriptor_write[1].dstBinding = 0;
6306 descriptor_write[1].descriptorCount = 2;
6307 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6308 descriptor_write[1].pImageInfo = imageInfo;
6309 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6310 descriptor_write[2].dstSet = descriptorSet[1];
6311 descriptor_write[2].dstBinding = 1;
6312 descriptor_write[2].descriptorCount = 2;
6313 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006314 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006315
6316 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006317
Tobin Ehlis88452832015-12-03 09:40:56 -07006318 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006319 char const *vsSource = "#version 450\n"
6320 "\n"
6321 "out gl_PerVertex {\n"
6322 " vec4 gl_Position;\n"
6323 "};\n"
6324 "void main(){\n"
6325 " gl_Position = vec4(1);\n"
6326 "}\n";
6327 char const *fsSource = "#version 450\n"
6328 "\n"
6329 "layout(location=0) out vec4 x;\n"
6330 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6331 "void main(){\n"
6332 " x = vec4(bar.y);\n"
6333 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006334 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6335 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006336 VkPipelineObj pipe(m_device);
6337 pipe.AddShader(&vs);
6338 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006339 pipe.AddColorAttachment();
6340 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006341
6342 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006345 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6346 // of PSO
6347 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6348 // cmd_pipeline.c
6349 // due to the fact that cmd_alloc_dset_data() has not been called in
6350 // cmd_bind_graphics_pipeline()
6351 // TODO : Want to cause various binding incompatibility issues here to test
6352 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006353 // First cause various verify_layout_compatibility() fails
6354 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006355 // verify_set_layout_compatibility fail cases:
6356 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6358 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6359 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006360 m_errorMonitor->VerifyFound();
6361
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006362 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6364 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6365 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006366 m_errorMonitor->VerifyFound();
6367
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006368 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006369 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6370 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6372 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6373 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006374 m_errorMonitor->VerifyFound();
6375
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006376 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6377 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6379 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6380 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006381 m_errorMonitor->VerifyFound();
6382
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006383 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6384 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6386 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6387 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6388 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006389 m_errorMonitor->VerifyFound();
6390
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006391 // Cause INFO messages due to disturbing previously bound Sets
6392 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006393 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6394 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006395 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6397 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6398 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006399 m_errorMonitor->VerifyFound();
6400
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006401 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6402 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006403 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6405 "any subsequent sets were disturbed ");
6406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6407 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006408 m_errorMonitor->VerifyFound();
6409
Tobin Ehlis10fad692016-07-07 12:00:36 -06006410 // Now that we're done actively using the pipelineLayout that gfx pipeline
6411 // was created with, we should be able to delete it. Do that now to verify
6412 // that validation obeys pipelineLayout lifetime
6413 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6414
Tobin Ehlis88452832015-12-03 09:40:56 -07006415 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006416 // 1. Error due to not binding required set (we actually use same code as
6417 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6419 &descriptorSet[0], 0, NULL);
6420 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6421 &descriptorSet[1], 0, NULL);
6422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006423 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006424 m_errorMonitor->VerifyFound();
6425
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006426 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006427 // 2. Error due to bound set not being compatible with PSO's
6428 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6430 &descriptorSet[0], 0, NULL);
6431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006432 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006433 m_errorMonitor->VerifyFound();
6434
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006436 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006437 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6438 }
6439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006440 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006441 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006443 vkFreeMemory(m_device->device(), imageMem, NULL);
6444 vkDestroyImage(m_device->device(), image, NULL);
6445 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006446}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006447
Karl Schultz6addd812016-02-02 17:17:23 -07006448TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6451 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006452
6453 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006454 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006455 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006456 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006458 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006459}
6460
Karl Schultz6addd812016-02-02 17:17:23 -07006461TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6462 VkResult err;
6463 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006466
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006467 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006468
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006469 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006470 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006471 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006472 cmd.commandPool = m_commandPool;
6473 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006474 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006475
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006476 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006477 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006478
6479 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006480 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006481 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006482 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006483 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006484 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 -07006485 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006486
6487 // The error should be caught by validation of the BeginCommandBuffer call
6488 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6489
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006490 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006491 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006492}
6493
Karl Schultz6addd812016-02-02 17:17:23 -07006494TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006495 // Cause error due to Begin while recording CB
6496 // Then cause 2 errors for attempting to reset CB w/o having
6497 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6498 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006500
6501 ASSERT_NO_FATAL_FAILURE(InitState());
6502
6503 // Calls AllocateCommandBuffers
6504 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6505
Karl Schultz6addd812016-02-02 17:17:23 -07006506 // Force the failure by setting the Renderpass and Framebuffer fields with
6507 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006508 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006509 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006510 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6511 cmd_buf_info.pNext = NULL;
6512 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006513 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006514
6515 // Begin CB to transition to recording state
6516 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6517 // Can't re-begin. This should trigger error
6518 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006519 m_errorMonitor->VerifyFound();
6520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006522 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6523 // Reset attempt will trigger error due to incorrect CommandPool state
6524 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006525 m_errorMonitor->VerifyFound();
6526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006528 // Transition CB to RECORDED state
6529 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6530 // Now attempting to Begin will implicitly reset, which triggers error
6531 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006532 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006533}
6534
Karl Schultz6addd812016-02-02 17:17:23 -07006535TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006536 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006537 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006538
Mike Weiblencce7ec72016-10-17 19:33:05 -06006539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006540
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006543
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006544 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6546 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006547
6548 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006549 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6550 ds_pool_ci.pNext = NULL;
6551 ds_pool_ci.maxSets = 1;
6552 ds_pool_ci.poolSizeCount = 1;
6553 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006554
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006555 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006556 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006557 ASSERT_VK_SUCCESS(err);
6558
Tony Barboureb254902015-07-15 12:50:33 -06006559 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006560 dsl_binding.binding = 0;
6561 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6562 dsl_binding.descriptorCount = 1;
6563 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6564 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006565
Tony Barboureb254902015-07-15 12:50:33 -06006566 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006567 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6568 ds_layout_ci.pNext = NULL;
6569 ds_layout_ci.bindingCount = 1;
6570 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006571
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006572 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006574 ASSERT_VK_SUCCESS(err);
6575
6576 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006577 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006579 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006580 alloc_info.descriptorPool = ds_pool;
6581 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006582 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006583 ASSERT_VK_SUCCESS(err);
6584
Tony Barboureb254902015-07-15 12:50:33 -06006585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6587 pipeline_layout_ci.setLayoutCount = 1;
6588 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006589
6590 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006592 ASSERT_VK_SUCCESS(err);
6593
Tobin Ehlise68360f2015-10-01 11:15:13 -06006594 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006595 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006596
6597 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006598 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6599 vp_state_ci.scissorCount = 1;
6600 vp_state_ci.pScissors = &sc;
6601 vp_state_ci.viewportCount = 1;
6602 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006603
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006604 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6605 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6606 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6607 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6608 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6609 rs_state_ci.depthClampEnable = VK_FALSE;
6610 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6611 rs_state_ci.depthBiasEnable = VK_FALSE;
6612
Tony Barboureb254902015-07-15 12:50:33 -06006613 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006614 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6615 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006616 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006617 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6618 gp_ci.layout = pipeline_layout;
6619 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006620
6621 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006622 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6623 pc_ci.initialDataSize = 0;
6624 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006625
6626 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006627 VkPipelineCache pipelineCache;
6628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006630 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006631 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006632
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006633 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006634
Chia-I Wuf7458c52015-10-26 21:10:41 +08006635 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6636 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6637 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6638 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006639}
Tobin Ehlis912df022015-09-17 08:46:18 -06006640/*// TODO : This test should be good, but needs Tess support in compiler to run
6641TEST_F(VkLayerTest, InvalidPatchControlPoints)
6642{
6643 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006644 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006645
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006647 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6648primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006649
Tobin Ehlis912df022015-09-17 08:46:18 -06006650 ASSERT_NO_FATAL_FAILURE(InitState());
6651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006652
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006653 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006654 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006655 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006656
6657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6659 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006660 ds_pool_ci.poolSizeCount = 1;
6661 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006662
6663 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006664 err = vkCreateDescriptorPool(m_device->device(),
6665VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006666 ASSERT_VK_SUCCESS(err);
6667
6668 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006669 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006671 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6673 dsl_binding.pImmutableSamplers = NULL;
6674
6675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006676 ds_layout_ci.sType =
6677VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006678 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006679 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006680 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006681
6682 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6684&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006685 ASSERT_VK_SUCCESS(err);
6686
6687 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006688 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6689VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006690 ASSERT_VK_SUCCESS(err);
6691
6692 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006693 pipeline_layout_ci.sType =
6694VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006695 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006696 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006697 pipeline_layout_ci.pSetLayouts = &ds_layout;
6698
6699 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006700 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6701&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006702 ASSERT_VK_SUCCESS(err);
6703
6704 VkPipelineShaderStageCreateInfo shaderStages[3];
6705 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6706
Karl Schultz6addd812016-02-02 17:17:23 -07006707 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6708this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006709 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006710 VkShaderObj
6711tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6712this);
6713 VkShaderObj
6714te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6715this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006716
Karl Schultz6addd812016-02-02 17:17:23 -07006717 shaderStages[0].sType =
6718VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006719 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006720 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006721 shaderStages[1].sType =
6722VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006723 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006724 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006725 shaderStages[2].sType =
6726VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006727 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006728 shaderStages[2].shader = te.handle();
6729
6730 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006731 iaCI.sType =
6732VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006733 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006734
6735 VkPipelineTessellationStateCreateInfo tsCI = {};
6736 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6737 tsCI.patchControlPoints = 0; // This will cause an error
6738
6739 VkGraphicsPipelineCreateInfo gp_ci = {};
6740 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6741 gp_ci.pNext = NULL;
6742 gp_ci.stageCount = 3;
6743 gp_ci.pStages = shaderStages;
6744 gp_ci.pVertexInputState = NULL;
6745 gp_ci.pInputAssemblyState = &iaCI;
6746 gp_ci.pTessellationState = &tsCI;
6747 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006748 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006749 gp_ci.pMultisampleState = NULL;
6750 gp_ci.pDepthStencilState = NULL;
6751 gp_ci.pColorBlendState = NULL;
6752 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6753 gp_ci.layout = pipeline_layout;
6754 gp_ci.renderPass = renderPass();
6755
6756 VkPipelineCacheCreateInfo pc_ci = {};
6757 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6758 pc_ci.pNext = NULL;
6759 pc_ci.initialSize = 0;
6760 pc_ci.initialData = 0;
6761 pc_ci.maxSize = 0;
6762
6763 VkPipeline pipeline;
6764 VkPipelineCache pipelineCache;
6765
Karl Schultz6addd812016-02-02 17:17:23 -07006766 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6767&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006768 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006769 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6770&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006771
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006772 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006773
Chia-I Wuf7458c52015-10-26 21:10:41 +08006774 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6775 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006778}
6779*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006780// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006781TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006782 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6785 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006786
Tobin Ehlise68360f2015-10-01 11:15:13 -06006787 ASSERT_NO_FATAL_FAILURE(InitState());
6788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006789
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006790 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006791 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6792 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006793
6794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6796 ds_pool_ci.maxSets = 1;
6797 ds_pool_ci.poolSizeCount = 1;
6798 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006799
6800 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006801 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006802 ASSERT_VK_SUCCESS(err);
6803
6804 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006805 dsl_binding.binding = 0;
6806 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6807 dsl_binding.descriptorCount = 1;
6808 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006809
6810 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006811 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6812 ds_layout_ci.bindingCount = 1;
6813 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006814
6815 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006816 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006817 ASSERT_VK_SUCCESS(err);
6818
6819 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006820 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006821 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006822 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006823 alloc_info.descriptorPool = ds_pool;
6824 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006826 ASSERT_VK_SUCCESS(err);
6827
6828 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006829 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6830 pipeline_layout_ci.setLayoutCount = 1;
6831 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006832
6833 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006834 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006835 ASSERT_VK_SUCCESS(err);
6836
6837 VkViewport vp = {}; // Just need dummy vp to point to
6838
6839 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006840 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6841 vp_state_ci.scissorCount = 0;
6842 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6843 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006845 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6846 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6847 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6848 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6849 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6850 rs_state_ci.depthClampEnable = VK_FALSE;
6851 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6852 rs_state_ci.depthBiasEnable = VK_FALSE;
6853
Cody Northropeb3a6c12015-10-05 14:44:45 -06006854 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006855 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006857 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6858 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6859 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006860 shaderStages[0] = vs.GetStageCreateInfo();
6861 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006862
6863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6865 gp_ci.stageCount = 2;
6866 gp_ci.pStages = shaderStages;
6867 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006868 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006869 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6870 gp_ci.layout = pipeline_layout;
6871 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006872
6873 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006874 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006875
6876 VkPipeline pipeline;
6877 VkPipelineCache pipelineCache;
6878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006884
Chia-I Wuf7458c52015-10-26 21:10:41 +08006885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006889}
Karl Schultz6addd812016-02-02 17:17:23 -07006890// Don't set viewport state in PSO. This is an error b/c we always need this
6891// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006892// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006893TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006894 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006895 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006898
Tobin Ehlise68360f2015-10-01 11:15:13 -06006899 ASSERT_NO_FATAL_FAILURE(InitState());
6900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006901
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006902 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006903 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6904 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006905
6906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6908 ds_pool_ci.maxSets = 1;
6909 ds_pool_ci.poolSizeCount = 1;
6910 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006911
6912 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006913 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006914 ASSERT_VK_SUCCESS(err);
6915
6916 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006917 dsl_binding.binding = 0;
6918 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6919 dsl_binding.descriptorCount = 1;
6920 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006921
6922 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006923 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6924 ds_layout_ci.bindingCount = 1;
6925 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006926
6927 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006928 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006929 ASSERT_VK_SUCCESS(err);
6930
6931 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006932 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006933 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006934 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006935 alloc_info.descriptorPool = ds_pool;
6936 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006937 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006938 ASSERT_VK_SUCCESS(err);
6939
6940 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006941 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6942 pipeline_layout_ci.setLayoutCount = 1;
6943 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006944
6945 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006946 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006947 ASSERT_VK_SUCCESS(err);
6948
6949 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6950 // Set scissor as dynamic to avoid second error
6951 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006952 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6953 dyn_state_ci.dynamicStateCount = 1;
6954 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006955
Cody Northropeb3a6c12015-10-05 14:44:45 -06006956 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006957 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006959 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6960 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6961 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006962 shaderStages[0] = vs.GetStageCreateInfo();
6963 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006964
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006965 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6966 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6967 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6968 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6969 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6970 rs_state_ci.depthClampEnable = VK_FALSE;
6971 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6972 rs_state_ci.depthBiasEnable = VK_FALSE;
6973
Tobin Ehlise68360f2015-10-01 11:15:13 -06006974 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006975 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6976 gp_ci.stageCount = 2;
6977 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006978 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006979 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6980 // should cause validation error
6981 gp_ci.pDynamicState = &dyn_state_ci;
6982 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6983 gp_ci.layout = pipeline_layout;
6984 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006985
6986 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006987 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006988
6989 VkPipeline pipeline;
6990 VkPipelineCache pipelineCache;
6991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006992 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006993 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006995
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006996 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997
Chia-I Wuf7458c52015-10-26 21:10:41 +08006998 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007002}
7003// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007004// Then run second test where dynamic scissor count doesn't match PSO scissor
7005// count
7006TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7007 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007008
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7010 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007011
Tobin Ehlise68360f2015-10-01 11:15:13 -06007012 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007013
7014 if (!m_device->phy().features().multiViewport) {
7015 printf("Device does not support multiple viewports/scissors; skipped.\n");
7016 return;
7017 }
7018
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007020
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007021 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7023 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007024
7025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7027 ds_pool_ci.maxSets = 1;
7028 ds_pool_ci.poolSizeCount = 1;
7029 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030
7031 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033 ASSERT_VK_SUCCESS(err);
7034
7035 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007036 dsl_binding.binding = 0;
7037 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7038 dsl_binding.descriptorCount = 1;
7039 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007040
7041 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007042 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7043 ds_layout_ci.bindingCount = 1;
7044 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007045
7046 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007047 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007048 ASSERT_VK_SUCCESS(err);
7049
7050 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007051 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007052 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007053 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007054 alloc_info.descriptorPool = ds_pool;
7055 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007056 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007057 ASSERT_VK_SUCCESS(err);
7058
7059 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007060 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7061 pipeline_layout_ci.setLayoutCount = 1;
7062 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007063
7064 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007065 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007066 ASSERT_VK_SUCCESS(err);
7067
7068 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7070 vp_state_ci.viewportCount = 1;
7071 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7072 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007073 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007074
7075 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7076 // Set scissor as dynamic to avoid that error
7077 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007078 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7079 dyn_state_ci.dynamicStateCount = 1;
7080 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
Cody Northropeb3a6c12015-10-05 14:44:45 -06007082 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007083 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007085 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7086 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7087 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007088 shaderStages[0] = vs.GetStageCreateInfo();
7089 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007090
Cody Northropf6622dc2015-10-06 10:33:21 -06007091 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7092 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7093 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007094 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007095 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007096 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007097 vi_ci.pVertexAttributeDescriptions = nullptr;
7098
7099 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7100 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7101 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7102
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007103 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007104 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007105 rs_ci.pNext = nullptr;
7106
Mark Youngc89c6312016-03-31 16:03:20 -06007107 VkPipelineColorBlendAttachmentState att = {};
7108 att.blendEnable = VK_FALSE;
7109 att.colorWriteMask = 0xf;
7110
Cody Northropf6622dc2015-10-06 10:33:21 -06007111 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7112 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7113 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007114 cb_ci.attachmentCount = 1;
7115 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007116
Tobin Ehlise68360f2015-10-01 11:15:13 -06007117 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007118 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7119 gp_ci.stageCount = 2;
7120 gp_ci.pStages = shaderStages;
7121 gp_ci.pVertexInputState = &vi_ci;
7122 gp_ci.pInputAssemblyState = &ia_ci;
7123 gp_ci.pViewportState = &vp_state_ci;
7124 gp_ci.pRasterizationState = &rs_ci;
7125 gp_ci.pColorBlendState = &cb_ci;
7126 gp_ci.pDynamicState = &dyn_state_ci;
7127 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7128 gp_ci.layout = pipeline_layout;
7129 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130
7131 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007132 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133
7134 VkPipeline pipeline;
7135 VkPipelineCache pipelineCache;
7136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007137 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007138 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007139 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007140
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007141 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007142
Tobin Ehlisd332f282015-10-02 11:00:56 -06007143 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007144 // First need to successfully create the PSO from above by setting
7145 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007146 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 -07007147
7148 VkViewport vp = {}; // Just need dummy vp to point to
7149 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007151 ASSERT_VK_SUCCESS(err);
7152 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007154 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007155 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007156 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007157 Draw(1, 0, 0, 0);
7158
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007159 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007160
7161 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7164 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007165 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007166}
7167// Create PSO w/o non-zero scissorCount but no scissor data
7168// Then run second test where dynamic viewportCount doesn't match PSO
7169// viewportCount
7170TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7171 VkResult err;
7172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007174
7175 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007176
7177 if (!m_device->phy().features().multiViewport) {
7178 printf("Device does not support multiple viewports/scissors; skipped.\n");
7179 return;
7180 }
7181
Karl Schultz6addd812016-02-02 17:17:23 -07007182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7183
7184 VkDescriptorPoolSize ds_type_count = {};
7185 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7186 ds_type_count.descriptorCount = 1;
7187
7188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7190 ds_pool_ci.maxSets = 1;
7191 ds_pool_ci.poolSizeCount = 1;
7192 ds_pool_ci.pPoolSizes = &ds_type_count;
7193
7194 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007196 ASSERT_VK_SUCCESS(err);
7197
7198 VkDescriptorSetLayoutBinding dsl_binding = {};
7199 dsl_binding.binding = 0;
7200 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7201 dsl_binding.descriptorCount = 1;
7202 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7203
7204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7206 ds_layout_ci.bindingCount = 1;
7207 ds_layout_ci.pBindings = &dsl_binding;
7208
7209 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007211 ASSERT_VK_SUCCESS(err);
7212
7213 VkDescriptorSet descriptorSet;
7214 VkDescriptorSetAllocateInfo alloc_info = {};
7215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7216 alloc_info.descriptorSetCount = 1;
7217 alloc_info.descriptorPool = ds_pool;
7218 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007220 ASSERT_VK_SUCCESS(err);
7221
7222 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7223 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7224 pipeline_layout_ci.setLayoutCount = 1;
7225 pipeline_layout_ci.pSetLayouts = &ds_layout;
7226
7227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007229 ASSERT_VK_SUCCESS(err);
7230
7231 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7232 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7233 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007234 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007235 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007237
7238 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7239 // Set scissor as dynamic to avoid that error
7240 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7241 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7242 dyn_state_ci.dynamicStateCount = 1;
7243 dyn_state_ci.pDynamicStates = &vp_state;
7244
7245 VkPipelineShaderStageCreateInfo shaderStages[2];
7246 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7249 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7250 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007251 shaderStages[0] = vs.GetStageCreateInfo();
7252 shaderStages[1] = fs.GetStageCreateInfo();
7253
7254 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7255 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7256 vi_ci.pNext = nullptr;
7257 vi_ci.vertexBindingDescriptionCount = 0;
7258 vi_ci.pVertexBindingDescriptions = nullptr;
7259 vi_ci.vertexAttributeDescriptionCount = 0;
7260 vi_ci.pVertexAttributeDescriptions = nullptr;
7261
7262 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7263 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7264 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7265
7266 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7267 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7268 rs_ci.pNext = nullptr;
7269
Mark Youngc89c6312016-03-31 16:03:20 -06007270 VkPipelineColorBlendAttachmentState att = {};
7271 att.blendEnable = VK_FALSE;
7272 att.colorWriteMask = 0xf;
7273
Karl Schultz6addd812016-02-02 17:17:23 -07007274 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7275 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7276 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007277 cb_ci.attachmentCount = 1;
7278 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007279
7280 VkGraphicsPipelineCreateInfo gp_ci = {};
7281 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7282 gp_ci.stageCount = 2;
7283 gp_ci.pStages = shaderStages;
7284 gp_ci.pVertexInputState = &vi_ci;
7285 gp_ci.pInputAssemblyState = &ia_ci;
7286 gp_ci.pViewportState = &vp_state_ci;
7287 gp_ci.pRasterizationState = &rs_ci;
7288 gp_ci.pColorBlendState = &cb_ci;
7289 gp_ci.pDynamicState = &dyn_state_ci;
7290 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7291 gp_ci.layout = pipeline_layout;
7292 gp_ci.renderPass = renderPass();
7293
7294 VkPipelineCacheCreateInfo pc_ci = {};
7295 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7296
7297 VkPipeline pipeline;
7298 VkPipelineCache pipelineCache;
7299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007300 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007301 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007302 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007304 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007305
7306 // Now hit second fail case where we set scissor w/ different count than PSO
7307 // First need to successfully create the PSO from above by setting
7308 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007310
Tobin Ehlisd332f282015-10-02 11:00:56 -06007311 VkRect2D sc = {}; // Just need dummy vp to point to
7312 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007314 ASSERT_VK_SUCCESS(err);
7315 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007317 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007318 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007319 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007320 Draw(1, 0, 0, 0);
7321
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007322 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
Chia-I Wuf7458c52015-10-26 21:10:41 +08007324 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7325 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7326 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7327 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007328 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329}
7330
Mark Young7394fdd2016-03-31 14:56:43 -06007331TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7332 VkResult err;
7333
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007335
7336 ASSERT_NO_FATAL_FAILURE(InitState());
7337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7338
7339 VkDescriptorPoolSize ds_type_count = {};
7340 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7341 ds_type_count.descriptorCount = 1;
7342
7343 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7344 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7345 ds_pool_ci.maxSets = 1;
7346 ds_pool_ci.poolSizeCount = 1;
7347 ds_pool_ci.pPoolSizes = &ds_type_count;
7348
7349 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007351 ASSERT_VK_SUCCESS(err);
7352
7353 VkDescriptorSetLayoutBinding dsl_binding = {};
7354 dsl_binding.binding = 0;
7355 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7356 dsl_binding.descriptorCount = 1;
7357 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7358
7359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7361 ds_layout_ci.bindingCount = 1;
7362 ds_layout_ci.pBindings = &dsl_binding;
7363
7364 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007366 ASSERT_VK_SUCCESS(err);
7367
7368 VkDescriptorSet descriptorSet;
7369 VkDescriptorSetAllocateInfo alloc_info = {};
7370 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7371 alloc_info.descriptorSetCount = 1;
7372 alloc_info.descriptorPool = ds_pool;
7373 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007374 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007375 ASSERT_VK_SUCCESS(err);
7376
7377 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7378 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7379 pipeline_layout_ci.setLayoutCount = 1;
7380 pipeline_layout_ci.pSetLayouts = &ds_layout;
7381
7382 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007383 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007384 ASSERT_VK_SUCCESS(err);
7385
7386 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7387 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7388 vp_state_ci.scissorCount = 1;
7389 vp_state_ci.pScissors = NULL;
7390 vp_state_ci.viewportCount = 1;
7391 vp_state_ci.pViewports = NULL;
7392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007394 // Set scissor as dynamic to avoid that error
7395 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7396 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7397 dyn_state_ci.dynamicStateCount = 2;
7398 dyn_state_ci.pDynamicStates = dynamic_states;
7399
7400 VkPipelineShaderStageCreateInfo shaderStages[2];
7401 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7402
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7404 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007405 this); // TODO - We shouldn't need a fragment shader
7406 // but add it to be able to run on more devices
7407 shaderStages[0] = vs.GetStageCreateInfo();
7408 shaderStages[1] = fs.GetStageCreateInfo();
7409
7410 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7411 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7412 vi_ci.pNext = nullptr;
7413 vi_ci.vertexBindingDescriptionCount = 0;
7414 vi_ci.pVertexBindingDescriptions = nullptr;
7415 vi_ci.vertexAttributeDescriptionCount = 0;
7416 vi_ci.pVertexAttributeDescriptions = nullptr;
7417
7418 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7419 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7420 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7421
7422 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7423 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7424 rs_ci.pNext = nullptr;
7425
Mark Young47107952016-05-02 15:59:55 -06007426 // Check too low (line width of -1.0f).
7427 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007428
7429 VkPipelineColorBlendAttachmentState att = {};
7430 att.blendEnable = VK_FALSE;
7431 att.colorWriteMask = 0xf;
7432
7433 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7434 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7435 cb_ci.pNext = nullptr;
7436 cb_ci.attachmentCount = 1;
7437 cb_ci.pAttachments = &att;
7438
7439 VkGraphicsPipelineCreateInfo gp_ci = {};
7440 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7441 gp_ci.stageCount = 2;
7442 gp_ci.pStages = shaderStages;
7443 gp_ci.pVertexInputState = &vi_ci;
7444 gp_ci.pInputAssemblyState = &ia_ci;
7445 gp_ci.pViewportState = &vp_state_ci;
7446 gp_ci.pRasterizationState = &rs_ci;
7447 gp_ci.pColorBlendState = &cb_ci;
7448 gp_ci.pDynamicState = &dyn_state_ci;
7449 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7450 gp_ci.layout = pipeline_layout;
7451 gp_ci.renderPass = renderPass();
7452
7453 VkPipelineCacheCreateInfo pc_ci = {};
7454 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7455
7456 VkPipeline pipeline;
7457 VkPipelineCache pipelineCache;
7458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007460 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007461 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007462
7463 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007464 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007465
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007467
7468 // Check too high (line width of 65536.0f).
7469 rs_ci.lineWidth = 65536.0f;
7470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007471 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007472 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007474
7475 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007476 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007477
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007479
7480 dyn_state_ci.dynamicStateCount = 3;
7481
7482 rs_ci.lineWidth = 1.0f;
7483
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007485 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007487 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007489
7490 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007491 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007492 m_errorMonitor->VerifyFound();
7493
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007495
7496 // Check too high with dynamic setting.
7497 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7498 m_errorMonitor->VerifyFound();
7499 EndCommandBuffer();
7500
7501 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7502 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7504 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007505 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007506}
7507
Karl Schultz6addd812016-02-02 17:17:23 -07007508TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007509 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7511 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007512
7513 ASSERT_NO_FATAL_FAILURE(InitState());
7514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007515
Tony Barbourfe3351b2015-07-28 10:17:20 -06007516 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007517 // Don't care about RenderPass handle b/c error should be flagged before
7518 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007519 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007521 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007522}
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007525 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7527 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
7529 ASSERT_NO_FATAL_FAILURE(InitState());
7530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007531
Tony Barbourfe3351b2015-07-28 10:17:20 -06007532 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007533 // Just create a dummy Renderpass that's non-NULL so we can get to the
7534 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007535 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007536
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007537 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007538}
7539
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007540TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7541 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7542 "the number of renderPass attachments that use loadOp"
7543 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7544
7545 ASSERT_NO_FATAL_FAILURE(InitState());
7546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7547
7548 // Create a renderPass with a single attachment that uses loadOp CLEAR
7549 VkAttachmentReference attach = {};
7550 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7551 VkSubpassDescription subpass = {};
7552 subpass.inputAttachmentCount = 1;
7553 subpass.pInputAttachments = &attach;
7554 VkRenderPassCreateInfo rpci = {};
7555 rpci.subpassCount = 1;
7556 rpci.pSubpasses = &subpass;
7557 rpci.attachmentCount = 1;
7558 VkAttachmentDescription attach_desc = {};
7559 attach_desc.format = VK_FORMAT_UNDEFINED;
7560 // Set loadOp to CLEAR
7561 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7562 rpci.pAttachments = &attach_desc;
7563 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7564 VkRenderPass rp;
7565 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7566
7567 VkCommandBufferInheritanceInfo hinfo = {};
7568 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7569 hinfo.renderPass = VK_NULL_HANDLE;
7570 hinfo.subpass = 0;
7571 hinfo.framebuffer = VK_NULL_HANDLE;
7572 hinfo.occlusionQueryEnable = VK_FALSE;
7573 hinfo.queryFlags = 0;
7574 hinfo.pipelineStatistics = 0;
7575 VkCommandBufferBeginInfo info = {};
7576 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7577 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7578 info.pInheritanceInfo = &hinfo;
7579
7580 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7581 VkRenderPassBeginInfo rp_begin = {};
7582 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7583 rp_begin.pNext = NULL;
7584 rp_begin.renderPass = renderPass();
7585 rp_begin.framebuffer = framebuffer();
7586 rp_begin.clearValueCount = 0; // Should be 1
7587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7589 "there must be at least 1 entries in "
7590 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007592 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007593
7594 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007595
7596 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007597}
7598
Cody Northrop3bb4d962016-05-09 16:15:57 -06007599TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7600
7601 TEST_DESCRIPTION("End a command buffer with an active render pass");
7602
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7604 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007605
7606 ASSERT_NO_FATAL_FAILURE(InitState());
7607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7608
7609 // The framework's BeginCommandBuffer calls CreateRenderPass
7610 BeginCommandBuffer();
7611
7612 // Call directly into vkEndCommandBuffer instead of the
7613 // the framework's EndCommandBuffer, which inserts a
7614 // vkEndRenderPass
7615 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7616
7617 m_errorMonitor->VerifyFound();
7618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007619 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7620 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007621}
7622
Karl Schultz6addd812016-02-02 17:17:23 -07007623TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007624 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7626 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007627
7628 ASSERT_NO_FATAL_FAILURE(InitState());
7629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007630
7631 // Renderpass is started here
7632 BeginCommandBuffer();
7633
7634 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007635 vk_testing::Buffer dstBuffer;
7636 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007637
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007638 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007639
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007640 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007641}
7642
Karl Schultz6addd812016-02-02 17:17:23 -07007643TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007644 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7646 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007647
7648 ASSERT_NO_FATAL_FAILURE(InitState());
7649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007650
7651 // Renderpass is started here
7652 BeginCommandBuffer();
7653
7654 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007655 vk_testing::Buffer dstBuffer;
7656 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007657
Karl Schultz6addd812016-02-02 17:17:23 -07007658 VkDeviceSize dstOffset = 0;
7659 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007660 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007662 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007664 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007665}
7666
Karl Schultz6addd812016-02-02 17:17:23 -07007667TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007668 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7670 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007671
7672 ASSERT_NO_FATAL_FAILURE(InitState());
7673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007674
7675 // Renderpass is started here
7676 BeginCommandBuffer();
7677
Michael Lentine0a369f62016-02-03 16:51:46 -06007678 VkClearColorValue clear_color;
7679 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007680 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7681 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7682 const int32_t tex_width = 32;
7683 const int32_t tex_height = 32;
7684 VkImageCreateInfo image_create_info = {};
7685 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7686 image_create_info.pNext = NULL;
7687 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7688 image_create_info.format = tex_format;
7689 image_create_info.extent.width = tex_width;
7690 image_create_info.extent.height = tex_height;
7691 image_create_info.extent.depth = 1;
7692 image_create_info.mipLevels = 1;
7693 image_create_info.arrayLayers = 1;
7694 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7695 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7696 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007697
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007698 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007699 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007700
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007701 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007704
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007705 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007706}
7707
Karl Schultz6addd812016-02-02 17:17:23 -07007708TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007709 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7711 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007712
7713 ASSERT_NO_FATAL_FAILURE(InitState());
7714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007715
7716 // Renderpass is started here
7717 BeginCommandBuffer();
7718
7719 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007720 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007721 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7722 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7723 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7724 image_create_info.extent.width = 64;
7725 image_create_info.extent.height = 64;
7726 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7727 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007728
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007729 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007730 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007732 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7735 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007736
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007737 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007738}
7739
Karl Schultz6addd812016-02-02 17:17:23 -07007740TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007741 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007742 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7745 "must be issued inside an active "
7746 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007747
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007748 ASSERT_NO_FATAL_FAILURE(InitState());
7749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007750
7751 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007752 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007753 ASSERT_VK_SUCCESS(err);
7754
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007755 VkClearAttachment color_attachment;
7756 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7757 color_attachment.clearValue.color.float32[0] = 0;
7758 color_attachment.clearValue.color.float32[1] = 0;
7759 color_attachment.clearValue.color.float32[2] = 0;
7760 color_attachment.clearValue.color.float32[3] = 0;
7761 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007762 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007765 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007766}
7767
Chris Forbes3b97e932016-09-07 11:29:24 +12007768TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7769 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7770 "called too many times in a renderpass instance");
7771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7773 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007774
7775 ASSERT_NO_FATAL_FAILURE(InitState());
7776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7777
7778 BeginCommandBuffer();
7779
7780 // error here.
7781 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7782 m_errorMonitor->VerifyFound();
7783
7784 EndCommandBuffer();
7785}
7786
Chris Forbes6d624702016-09-07 13:57:05 +12007787TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7788 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7789 "called before the final subpass has been reached");
7790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7792 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007793
7794 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7796 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007799
7800 VkRenderPass rp;
7801 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7802 ASSERT_VK_SUCCESS(err);
7803
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007804 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007805
7806 VkFramebuffer fb;
7807 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7808 ASSERT_VK_SUCCESS(err);
7809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007810 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 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 +12007813
7814 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7815
7816 // Error here.
7817 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7818 m_errorMonitor->VerifyFound();
7819
7820 // Clean up.
7821 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7822 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7823}
7824
Karl Schultz9e66a292016-04-21 15:57:51 -06007825TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7826 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7828 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007829
7830 ASSERT_NO_FATAL_FAILURE(InitState());
7831 BeginCommandBuffer();
7832
7833 VkBufferMemoryBarrier buf_barrier = {};
7834 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7835 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7836 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7837 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7838 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7839 buf_barrier.buffer = VK_NULL_HANDLE;
7840 buf_barrier.offset = 0;
7841 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7843 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007844
7845 m_errorMonitor->VerifyFound();
7846}
7847
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007848TEST_F(VkLayerTest, InvalidBarriers) {
7849 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007852
7853 ASSERT_NO_FATAL_FAILURE(InitState());
7854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7855
7856 VkMemoryBarrier mem_barrier = {};
7857 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7858 mem_barrier.pNext = NULL;
7859 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7860 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7861 BeginCommandBuffer();
7862 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007863 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007864 &mem_barrier, 0, nullptr, 0, nullptr);
7865 m_errorMonitor->VerifyFound();
7866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007868 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 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 -06007870 ASSERT_TRUE(image.initialized());
7871 VkImageMemoryBarrier img_barrier = {};
7872 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7873 img_barrier.pNext = NULL;
7874 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7875 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7876 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7877 // New layout can't be UNDEFINED
7878 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7879 img_barrier.image = image.handle();
7880 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7881 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7882 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7883 img_barrier.subresourceRange.baseArrayLayer = 0;
7884 img_barrier.subresourceRange.baseMipLevel = 0;
7885 img_barrier.subresourceRange.layerCount = 1;
7886 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007887 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7888 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007889 m_errorMonitor->VerifyFound();
7890 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7891
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
7893 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007894 // baseArrayLayer + layerCount must be <= image's arrayLayers
7895 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007896 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7897 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007898 m_errorMonitor->VerifyFound();
7899 img_barrier.subresourceRange.baseArrayLayer = 0;
7900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007902 // baseMipLevel + levelCount must be <= image's mipLevels
7903 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007904 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7905 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007906 m_errorMonitor->VerifyFound();
7907 img_barrier.subresourceRange.baseMipLevel = 0;
7908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 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 -06007910 vk_testing::Buffer buffer;
7911 buffer.init(*m_device, 256);
7912 VkBufferMemoryBarrier buf_barrier = {};
7913 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7914 buf_barrier.pNext = NULL;
7915 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7916 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7917 buf_barrier.buffer = buffer.handle();
7918 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7919 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7920 buf_barrier.offset = 0;
7921 buf_barrier.size = VK_WHOLE_SIZE;
7922 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7924 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007925 m_errorMonitor->VerifyFound();
7926 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007929 buf_barrier.offset = 257;
7930 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007931 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7932 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007933 m_errorMonitor->VerifyFound();
7934 buf_barrier.offset = 0;
7935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007937 buf_barrier.size = 257;
7938 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007939 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7940 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007941 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007942
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007943 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
7945 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
7946 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007947 VkDepthStencilObj ds_image(m_device);
7948 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7949 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06007950 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7951 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007952 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06007953 // Use of COLOR aspect on DS image is error
7954 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007955 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7956 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007957 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007958 // Now test depth-only
7959 VkFormatProperties format_props;
7960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
7962 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
7963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
7964 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007965 VkDepthStencilObj d_image(m_device);
7966 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
7967 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007968 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06007969 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007970 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06007971 // Use of COLOR aspect on depth image is error
7972 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
7974 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007975 m_errorMonitor->VerifyFound();
7976 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
7978 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007979 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
7981 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007982 VkDepthStencilObj s_image(m_device);
7983 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
7984 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06007986 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007987 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06007988 // Use of COLOR aspect on depth image is error
7989 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
7991 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007992 m_errorMonitor->VerifyFound();
7993 }
7994 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
7996 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06007997 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007998 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 -06007999 ASSERT_TRUE(c_image.initialized());
8000 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8001 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8002 img_barrier.image = c_image.handle();
8003 // Set aspect to depth (non-color)
8004 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8006 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008007 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008008}
8009
Tony Barbour18ba25c2016-09-29 13:42:40 -06008010TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8011 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8012
8013 m_errorMonitor->SetDesiredFailureMsg(
8014 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8015 "must have required access bit");
8016 ASSERT_NO_FATAL_FAILURE(InitState());
8017 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008018 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06008019 ASSERT_TRUE(image.initialized());
8020
8021 VkImageMemoryBarrier barrier = {};
8022 VkImageSubresourceRange range;
8023 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8024 barrier.srcAccessMask = 0;
8025 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8026 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8027 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8028 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8029 barrier.image = image.handle();
8030 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8031 range.baseMipLevel = 0;
8032 range.levelCount = 1;
8033 range.baseArrayLayer = 0;
8034 range.layerCount = 1;
8035 barrier.subresourceRange = range;
8036 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8037 cmdbuf.BeginCommandBuffer();
8038 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8039 &barrier);
8040 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8041 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8042 barrier.srcAccessMask = 0;
8043 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8044 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8045 &barrier);
8046
8047 m_errorMonitor->VerifyFound();
8048}
8049
Karl Schultz6addd812016-02-02 17:17:23 -07008050TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008051 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008052 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008055
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008056 ASSERT_NO_FATAL_FAILURE(InitState());
8057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008058 uint32_t qfi = 0;
8059 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008060 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8061 buffCI.size = 1024;
8062 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8063 buffCI.queueFamilyIndexCount = 1;
8064 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008065
8066 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008067 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008068 ASSERT_VK_SUCCESS(err);
8069
8070 BeginCommandBuffer();
8071 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008072 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8073 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008074 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008076
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008077 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008078
Chia-I Wuf7458c52015-10-26 21:10:41 +08008079 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008080}
8081
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008082TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8083 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8085 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8086 "of the indices specified when the device was created, via the "
8087 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008088
8089 ASSERT_NO_FATAL_FAILURE(InitState());
8090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8091 VkBufferCreateInfo buffCI = {};
8092 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8093 buffCI.size = 1024;
8094 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8095 buffCI.queueFamilyIndexCount = 1;
8096 // Introduce failure by specifying invalid queue_family_index
8097 uint32_t qfi = 777;
8098 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008099 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008100
8101 VkBuffer ib;
8102 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8103
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008104 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008105 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008106}
8107
Karl Schultz6addd812016-02-02 17:17:23 -07008108TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008109TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008110 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008111
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008112 ASSERT_NO_FATAL_FAILURE(InitState());
8113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008114
Chris Forbesf29a84f2016-10-06 18:39:28 +13008115 // An empty primary command buffer
8116 VkCommandBufferObj cb(m_device, m_commandPool);
8117 cb.BeginCommandBuffer();
8118 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008119
Chris Forbesf29a84f2016-10-06 18:39:28 +13008120 m_commandBuffer->BeginCommandBuffer();
8121 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8122 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008123
Chris Forbesf29a84f2016-10-06 18:39:28 +13008124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8125 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008126 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008127}
8128
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008129TEST_F(VkLayerTest, DSUsageBitsErrors) {
8130 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8131 "that do not have correct usage bits sets.");
8132 VkResult err;
8133
8134 ASSERT_NO_FATAL_FAILURE(InitState());
8135 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8136 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8137 ds_type_count[i].type = VkDescriptorType(i);
8138 ds_type_count[i].descriptorCount = 1;
8139 }
8140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8142 ds_pool_ci.pNext = NULL;
8143 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8144 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8145 ds_pool_ci.pPoolSizes = ds_type_count;
8146
8147 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008149 ASSERT_VK_SUCCESS(err);
8150
8151 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008152 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008153 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8154 dsl_binding[i].binding = 0;
8155 dsl_binding[i].descriptorType = VkDescriptorType(i);
8156 dsl_binding[i].descriptorCount = 1;
8157 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8158 dsl_binding[i].pImmutableSamplers = NULL;
8159 }
8160
8161 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8162 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8163 ds_layout_ci.pNext = NULL;
8164 ds_layout_ci.bindingCount = 1;
8165 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8166 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8167 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008169 ASSERT_VK_SUCCESS(err);
8170 }
8171 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8172 VkDescriptorSetAllocateInfo alloc_info = {};
8173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8174 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8175 alloc_info.descriptorPool = ds_pool;
8176 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008178 ASSERT_VK_SUCCESS(err);
8179
8180 // Create a buffer & bufferView to be used for invalid updates
8181 VkBufferCreateInfo buff_ci = {};
8182 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8183 // This usage is not valid for any descriptor type
8184 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8185 buff_ci.size = 256;
8186 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8187 VkBuffer buffer;
8188 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8189 ASSERT_VK_SUCCESS(err);
8190
8191 VkBufferViewCreateInfo buff_view_ci = {};
8192 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8193 buff_view_ci.buffer = buffer;
8194 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8195 buff_view_ci.range = VK_WHOLE_SIZE;
8196 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008197 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008198 ASSERT_VK_SUCCESS(err);
8199
8200 // Create an image to be used for invalid updates
8201 VkImageCreateInfo image_ci = {};
8202 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8203 image_ci.imageType = VK_IMAGE_TYPE_2D;
8204 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8205 image_ci.extent.width = 64;
8206 image_ci.extent.height = 64;
8207 image_ci.extent.depth = 1;
8208 image_ci.mipLevels = 1;
8209 image_ci.arrayLayers = 1;
8210 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8211 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8212 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8213 // This usage is not valid for any descriptor type
8214 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8215 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8216 VkImage image;
8217 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8218 ASSERT_VK_SUCCESS(err);
8219 // Bind memory to image
8220 VkMemoryRequirements mem_reqs;
8221 VkDeviceMemory image_mem;
8222 bool pass;
8223 VkMemoryAllocateInfo mem_alloc = {};
8224 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8225 mem_alloc.pNext = NULL;
8226 mem_alloc.allocationSize = 0;
8227 mem_alloc.memoryTypeIndex = 0;
8228 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8229 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008230 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008231 ASSERT_TRUE(pass);
8232 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8233 ASSERT_VK_SUCCESS(err);
8234 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8235 ASSERT_VK_SUCCESS(err);
8236 // Now create view for image
8237 VkImageViewCreateInfo image_view_ci = {};
8238 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8239 image_view_ci.image = image;
8240 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8241 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8242 image_view_ci.subresourceRange.layerCount = 1;
8243 image_view_ci.subresourceRange.baseArrayLayer = 0;
8244 image_view_ci.subresourceRange.levelCount = 1;
8245 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8246 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008247 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008248 ASSERT_VK_SUCCESS(err);
8249
8250 VkDescriptorBufferInfo buff_info = {};
8251 buff_info.buffer = buffer;
8252 VkDescriptorImageInfo img_info = {};
8253 img_info.imageView = image_view;
8254 VkWriteDescriptorSet descriptor_write = {};
8255 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8256 descriptor_write.dstBinding = 0;
8257 descriptor_write.descriptorCount = 1;
8258 descriptor_write.pTexelBufferView = &buff_view;
8259 descriptor_write.pBufferInfo = &buff_info;
8260 descriptor_write.pImageInfo = &img_info;
8261
8262 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008263 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8264 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8265 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8266 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8267 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8268 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8269 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8270 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8271 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8272 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8273 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008274 // Start loop at 1 as SAMPLER desc type has no usage bit error
8275 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8276 descriptor_write.descriptorType = VkDescriptorType(i);
8277 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008281
8282 m_errorMonitor->VerifyFound();
8283 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8284 }
8285 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8286 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008287 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008288 vkDestroyImageView(m_device->device(), image_view, NULL);
8289 vkDestroyBuffer(m_device->device(), buffer, NULL);
8290 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8293}
8294
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008295TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008296 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8297 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8298 "1. offset value greater than buffer size\n"
8299 "2. range value of 0\n"
8300 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008301 VkResult err;
8302
8303 ASSERT_NO_FATAL_FAILURE(InitState());
8304 VkDescriptorPoolSize ds_type_count = {};
8305 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8306 ds_type_count.descriptorCount = 1;
8307
8308 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8309 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8310 ds_pool_ci.pNext = NULL;
8311 ds_pool_ci.maxSets = 1;
8312 ds_pool_ci.poolSizeCount = 1;
8313 ds_pool_ci.pPoolSizes = &ds_type_count;
8314
8315 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008317 ASSERT_VK_SUCCESS(err);
8318
8319 // Create layout with single uniform buffer descriptor
8320 VkDescriptorSetLayoutBinding dsl_binding = {};
8321 dsl_binding.binding = 0;
8322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8323 dsl_binding.descriptorCount = 1;
8324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8325 dsl_binding.pImmutableSamplers = NULL;
8326
8327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8329 ds_layout_ci.pNext = NULL;
8330 ds_layout_ci.bindingCount = 1;
8331 ds_layout_ci.pBindings = &dsl_binding;
8332 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008334 ASSERT_VK_SUCCESS(err);
8335
8336 VkDescriptorSet descriptor_set = {};
8337 VkDescriptorSetAllocateInfo alloc_info = {};
8338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8339 alloc_info.descriptorSetCount = 1;
8340 alloc_info.descriptorPool = ds_pool;
8341 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008343 ASSERT_VK_SUCCESS(err);
8344
8345 // Create a buffer to be used for invalid updates
8346 VkBufferCreateInfo buff_ci = {};
8347 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8348 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8349 buff_ci.size = 256;
8350 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8351 VkBuffer buffer;
8352 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8353 ASSERT_VK_SUCCESS(err);
8354 // Have to bind memory to buffer before descriptor update
8355 VkMemoryAllocateInfo mem_alloc = {};
8356 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8357 mem_alloc.pNext = NULL;
8358 mem_alloc.allocationSize = 256;
8359 mem_alloc.memoryTypeIndex = 0;
8360
8361 VkMemoryRequirements mem_reqs;
8362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008364 if (!pass) {
8365 vkDestroyBuffer(m_device->device(), buffer, NULL);
8366 return;
8367 }
8368
8369 VkDeviceMemory mem;
8370 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8371 ASSERT_VK_SUCCESS(err);
8372 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8373 ASSERT_VK_SUCCESS(err);
8374
8375 VkDescriptorBufferInfo buff_info = {};
8376 buff_info.buffer = buffer;
8377 // First make offset 1 larger than buffer size
8378 buff_info.offset = 257;
8379 buff_info.range = VK_WHOLE_SIZE;
8380 VkWriteDescriptorSet descriptor_write = {};
8381 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8382 descriptor_write.dstBinding = 0;
8383 descriptor_write.descriptorCount = 1;
8384 descriptor_write.pTexelBufferView = nullptr;
8385 descriptor_write.pBufferInfo = &buff_info;
8386 descriptor_write.pImageInfo = nullptr;
8387
8388 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8389 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008391
8392 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8393
8394 m_errorMonitor->VerifyFound();
8395 // Now cause error due to range of 0
8396 buff_info.offset = 0;
8397 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8399 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008400
8401 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8402
8403 m_errorMonitor->VerifyFound();
8404 // Now cause error due to range exceeding buffer size - offset
8405 buff_info.offset = 128;
8406 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " range is 200 which is greater than buffer size ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008408
8409 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8410
8411 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008412 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8414 vkDestroyBuffer(m_device->device(), buffer, NULL);
8415 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8417}
8418
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008419TEST_F(VkLayerTest, DSAspectBitsErrors) {
8420 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8421 // are set, but could expand this test to hit more cases.
8422 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8423 "that do not have correct aspect bits sets.");
8424 VkResult err;
8425
8426 ASSERT_NO_FATAL_FAILURE(InitState());
8427 VkDescriptorPoolSize ds_type_count = {};
8428 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8429 ds_type_count.descriptorCount = 1;
8430
8431 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8432 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8433 ds_pool_ci.pNext = NULL;
8434 ds_pool_ci.maxSets = 5;
8435 ds_pool_ci.poolSizeCount = 1;
8436 ds_pool_ci.pPoolSizes = &ds_type_count;
8437
8438 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008439 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008440 ASSERT_VK_SUCCESS(err);
8441
8442 VkDescriptorSetLayoutBinding dsl_binding = {};
8443 dsl_binding.binding = 0;
8444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8445 dsl_binding.descriptorCount = 1;
8446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8447 dsl_binding.pImmutableSamplers = NULL;
8448
8449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8451 ds_layout_ci.pNext = NULL;
8452 ds_layout_ci.bindingCount = 1;
8453 ds_layout_ci.pBindings = &dsl_binding;
8454 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008456 ASSERT_VK_SUCCESS(err);
8457
8458 VkDescriptorSet descriptor_set = {};
8459 VkDescriptorSetAllocateInfo alloc_info = {};
8460 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8461 alloc_info.descriptorSetCount = 1;
8462 alloc_info.descriptorPool = ds_pool;
8463 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008465 ASSERT_VK_SUCCESS(err);
8466
8467 // Create an image to be used for invalid updates
8468 VkImageCreateInfo image_ci = {};
8469 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8470 image_ci.imageType = VK_IMAGE_TYPE_2D;
8471 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8472 image_ci.extent.width = 64;
8473 image_ci.extent.height = 64;
8474 image_ci.extent.depth = 1;
8475 image_ci.mipLevels = 1;
8476 image_ci.arrayLayers = 1;
8477 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8478 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8479 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8480 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8481 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8482 VkImage image;
8483 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8484 ASSERT_VK_SUCCESS(err);
8485 // Bind memory to image
8486 VkMemoryRequirements mem_reqs;
8487 VkDeviceMemory image_mem;
8488 bool pass;
8489 VkMemoryAllocateInfo mem_alloc = {};
8490 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8491 mem_alloc.pNext = NULL;
8492 mem_alloc.allocationSize = 0;
8493 mem_alloc.memoryTypeIndex = 0;
8494 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8495 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008497 ASSERT_TRUE(pass);
8498 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8499 ASSERT_VK_SUCCESS(err);
8500 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8501 ASSERT_VK_SUCCESS(err);
8502 // Now create view for image
8503 VkImageViewCreateInfo image_view_ci = {};
8504 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8505 image_view_ci.image = image;
8506 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8507 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8508 image_view_ci.subresourceRange.layerCount = 1;
8509 image_view_ci.subresourceRange.baseArrayLayer = 0;
8510 image_view_ci.subresourceRange.levelCount = 1;
8511 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008513
8514 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008516 ASSERT_VK_SUCCESS(err);
8517
8518 VkDescriptorImageInfo img_info = {};
8519 img_info.imageView = image_view;
8520 VkWriteDescriptorSet descriptor_write = {};
8521 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8522 descriptor_write.dstBinding = 0;
8523 descriptor_write.descriptorCount = 1;
8524 descriptor_write.pTexelBufferView = NULL;
8525 descriptor_write.pBufferInfo = NULL;
8526 descriptor_write.pImageInfo = &img_info;
8527 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8528 descriptor_write.dstSet = descriptor_set;
8529 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8530 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008532
8533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8534
8535 m_errorMonitor->VerifyFound();
8536 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8537 vkDestroyImage(m_device->device(), image, NULL);
8538 vkFreeMemory(m_device->device(), image_mem, NULL);
8539 vkDestroyImageView(m_device->device(), image_view, NULL);
8540 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8541 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8542}
8543
Karl Schultz6addd812016-02-02 17:17:23 -07008544TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008545 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008546 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008547
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8549 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8550 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008551
Tobin Ehlis3b780662015-05-28 12:11:26 -06008552 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008553 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008554 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008555 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8556 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008557
8558 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008559 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8560 ds_pool_ci.pNext = NULL;
8561 ds_pool_ci.maxSets = 1;
8562 ds_pool_ci.poolSizeCount = 1;
8563 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008564
Tobin Ehlis3b780662015-05-28 12:11:26 -06008565 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008566 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008567 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008568 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008569 dsl_binding.binding = 0;
8570 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8571 dsl_binding.descriptorCount = 1;
8572 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8573 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008574
Tony Barboureb254902015-07-15 12:50:33 -06008575 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008576 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8577 ds_layout_ci.pNext = NULL;
8578 ds_layout_ci.bindingCount = 1;
8579 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008580
Tobin Ehlis3b780662015-05-28 12:11:26 -06008581 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008583 ASSERT_VK_SUCCESS(err);
8584
8585 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008586 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008587 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008588 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008589 alloc_info.descriptorPool = ds_pool;
8590 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008592 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008593
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008594 VkSamplerCreateInfo sampler_ci = {};
8595 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8596 sampler_ci.pNext = NULL;
8597 sampler_ci.magFilter = VK_FILTER_NEAREST;
8598 sampler_ci.minFilter = VK_FILTER_NEAREST;
8599 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8600 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8601 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8602 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8603 sampler_ci.mipLodBias = 1.0;
8604 sampler_ci.anisotropyEnable = VK_FALSE;
8605 sampler_ci.maxAnisotropy = 1;
8606 sampler_ci.compareEnable = VK_FALSE;
8607 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8608 sampler_ci.minLod = 1.0;
8609 sampler_ci.maxLod = 1.0;
8610 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8611 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8612 VkSampler sampler;
8613 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8614 ASSERT_VK_SUCCESS(err);
8615
8616 VkDescriptorImageInfo info = {};
8617 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008618
8619 VkWriteDescriptorSet descriptor_write;
8620 memset(&descriptor_write, 0, sizeof(descriptor_write));
8621 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008622 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008623 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008624 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008625 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008626 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008627
8628 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8629
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008630 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008631
Chia-I Wuf7458c52015-10-26 21:10:41 +08008632 vkDestroySampler(m_device->device(), sampler, NULL);
8633 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8634 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008635}
8636
Karl Schultz6addd812016-02-02 17:17:23 -07008637TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008638 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008639 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8642 " binding #0 with 1 total descriptors but update of 1 descriptors "
8643 "starting at binding offset of 0 combined with update array element "
8644 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008645
Tobin Ehlis3b780662015-05-28 12:11:26 -06008646 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008647 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008648 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008649 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8650 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008651
8652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8654 ds_pool_ci.pNext = NULL;
8655 ds_pool_ci.maxSets = 1;
8656 ds_pool_ci.poolSizeCount = 1;
8657 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008658
Tobin Ehlis3b780662015-05-28 12:11:26 -06008659 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008661 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008662
Tony Barboureb254902015-07-15 12:50:33 -06008663 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008664 dsl_binding.binding = 0;
8665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8666 dsl_binding.descriptorCount = 1;
8667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8668 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008669
8670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8672 ds_layout_ci.pNext = NULL;
8673 ds_layout_ci.bindingCount = 1;
8674 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008675
Tobin Ehlis3b780662015-05-28 12:11:26 -06008676 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008678 ASSERT_VK_SUCCESS(err);
8679
8680 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008681 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008683 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008684 alloc_info.descriptorPool = ds_pool;
8685 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008687 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008688
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008689 // Correctly update descriptor to avoid "NOT_UPDATED" error
8690 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008692 buff_info.offset = 0;
8693 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008694
8695 VkWriteDescriptorSet descriptor_write;
8696 memset(&descriptor_write, 0, sizeof(descriptor_write));
8697 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008698 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008700 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008701 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8702 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008703
8704 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8705
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008706 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008707
Chia-I Wuf7458c52015-10-26 21:10:41 +08008708 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8709 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008710}
8711
Karl Schultz6addd812016-02-02 17:17:23 -07008712TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8713 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8714 // index 2
8715 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008718
Tobin Ehlis3b780662015-05-28 12:11:26 -06008719 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008720 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008721 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008722 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8723 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008724
8725 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008726 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8727 ds_pool_ci.pNext = NULL;
8728 ds_pool_ci.maxSets = 1;
8729 ds_pool_ci.poolSizeCount = 1;
8730 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008731
Tobin Ehlis3b780662015-05-28 12:11:26 -06008732 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008733 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008734 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008735
Tony Barboureb254902015-07-15 12:50:33 -06008736 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008737 dsl_binding.binding = 0;
8738 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8739 dsl_binding.descriptorCount = 1;
8740 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8741 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008742
8743 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008744 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8745 ds_layout_ci.pNext = NULL;
8746 ds_layout_ci.bindingCount = 1;
8747 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008748 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008750 ASSERT_VK_SUCCESS(err);
8751
8752 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008753 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008754 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008755 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008756 alloc_info.descriptorPool = ds_pool;
8757 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008759 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008760
Tony Barboureb254902015-07-15 12:50:33 -06008761 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008762 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8763 sampler_ci.pNext = NULL;
8764 sampler_ci.magFilter = VK_FILTER_NEAREST;
8765 sampler_ci.minFilter = VK_FILTER_NEAREST;
8766 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8767 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8768 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8769 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8770 sampler_ci.mipLodBias = 1.0;
8771 sampler_ci.anisotropyEnable = VK_FALSE;
8772 sampler_ci.maxAnisotropy = 1;
8773 sampler_ci.compareEnable = VK_FALSE;
8774 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8775 sampler_ci.minLod = 1.0;
8776 sampler_ci.maxLod = 1.0;
8777 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8778 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008779
Tobin Ehlis3b780662015-05-28 12:11:26 -06008780 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008781 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008782 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008783
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008784 VkDescriptorImageInfo info = {};
8785 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008786
8787 VkWriteDescriptorSet descriptor_write;
8788 memset(&descriptor_write, 0, sizeof(descriptor_write));
8789 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008790 descriptor_write.dstSet = descriptorSet;
8791 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008792 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008793 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008794 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008795 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008796
8797 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8798
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008799 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008800
Chia-I Wuf7458c52015-10-26 21:10:41 +08008801 vkDestroySampler(m_device->device(), sampler, NULL);
8802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008804}
8805
Karl Schultz6addd812016-02-02 17:17:23 -07008806TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8807 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8808 // types
8809 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008811 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 -06008812
Tobin Ehlis3b780662015-05-28 12:11:26 -06008813 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008814
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008815 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008816 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8817 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008818
8819 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008820 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8821 ds_pool_ci.pNext = NULL;
8822 ds_pool_ci.maxSets = 1;
8823 ds_pool_ci.poolSizeCount = 1;
8824 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008825
Tobin Ehlis3b780662015-05-28 12:11:26 -06008826 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008827 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008828 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008829 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008830 dsl_binding.binding = 0;
8831 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8832 dsl_binding.descriptorCount = 1;
8833 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8834 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008835
Tony Barboureb254902015-07-15 12:50:33 -06008836 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008837 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8838 ds_layout_ci.pNext = NULL;
8839 ds_layout_ci.bindingCount = 1;
8840 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008841
Tobin Ehlis3b780662015-05-28 12:11:26 -06008842 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008843 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008844 ASSERT_VK_SUCCESS(err);
8845
8846 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008847 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008848 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008849 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008850 alloc_info.descriptorPool = ds_pool;
8851 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008852 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008853 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008854
Tony Barboureb254902015-07-15 12:50:33 -06008855 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008856 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8857 sampler_ci.pNext = NULL;
8858 sampler_ci.magFilter = VK_FILTER_NEAREST;
8859 sampler_ci.minFilter = VK_FILTER_NEAREST;
8860 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8861 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8862 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8863 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8864 sampler_ci.mipLodBias = 1.0;
8865 sampler_ci.anisotropyEnable = VK_FALSE;
8866 sampler_ci.maxAnisotropy = 1;
8867 sampler_ci.compareEnable = VK_FALSE;
8868 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8869 sampler_ci.minLod = 1.0;
8870 sampler_ci.maxLod = 1.0;
8871 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8872 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008873 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008874 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008875 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008876
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008877 VkDescriptorImageInfo info = {};
8878 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008879
8880 VkWriteDescriptorSet descriptor_write;
8881 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008883 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008884 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008885 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008886 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008887 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008888
8889 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008891 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008892
Chia-I Wuf7458c52015-10-26 21:10:41 +08008893 vkDestroySampler(m_device->device(), sampler, NULL);
8894 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8895 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008896}
8897
Karl Schultz6addd812016-02-02 17:17:23 -07008898TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008899 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008900 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8903 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008904
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008905 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008906 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8907 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008908 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008909 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8910 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008911
8912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8914 ds_pool_ci.pNext = NULL;
8915 ds_pool_ci.maxSets = 1;
8916 ds_pool_ci.poolSizeCount = 1;
8917 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008918
8919 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008920 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008921 ASSERT_VK_SUCCESS(err);
8922
8923 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008924 dsl_binding.binding = 0;
8925 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8926 dsl_binding.descriptorCount = 1;
8927 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8928 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008929
8930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8932 ds_layout_ci.pNext = NULL;
8933 ds_layout_ci.bindingCount = 1;
8934 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008935 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008937 ASSERT_VK_SUCCESS(err);
8938
8939 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008940 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008942 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008943 alloc_info.descriptorPool = ds_pool;
8944 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008946 ASSERT_VK_SUCCESS(err);
8947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008949
8950 VkDescriptorImageInfo descriptor_info;
8951 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8952 descriptor_info.sampler = sampler;
8953
8954 VkWriteDescriptorSet descriptor_write;
8955 memset(&descriptor_write, 0, sizeof(descriptor_write));
8956 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008957 descriptor_write.dstSet = descriptorSet;
8958 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008959 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008960 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8961 descriptor_write.pImageInfo = &descriptor_info;
8962
8963 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008965 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008966
Chia-I Wuf7458c52015-10-26 21:10:41 +08008967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008969}
8970
Karl Schultz6addd812016-02-02 17:17:23 -07008971TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8972 // Create a single combined Image/Sampler descriptor and send it an invalid
8973 // imageView
8974 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008975
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
8977 "image sampler descriptor failed due "
8978 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008979
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008980 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008981 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008982 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8983 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008984
8985 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008986 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8987 ds_pool_ci.pNext = NULL;
8988 ds_pool_ci.maxSets = 1;
8989 ds_pool_ci.poolSizeCount = 1;
8990 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008991
8992 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008993 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008994 ASSERT_VK_SUCCESS(err);
8995
8996 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008997 dsl_binding.binding = 0;
8998 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8999 dsl_binding.descriptorCount = 1;
9000 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9001 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009002
9003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9005 ds_layout_ci.pNext = NULL;
9006 ds_layout_ci.bindingCount = 1;
9007 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009008 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009010 ASSERT_VK_SUCCESS(err);
9011
9012 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009013 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009014 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009015 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009016 alloc_info.descriptorPool = ds_pool;
9017 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009019 ASSERT_VK_SUCCESS(err);
9020
9021 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009022 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9023 sampler_ci.pNext = NULL;
9024 sampler_ci.magFilter = VK_FILTER_NEAREST;
9025 sampler_ci.minFilter = VK_FILTER_NEAREST;
9026 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9027 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9028 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9029 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9030 sampler_ci.mipLodBias = 1.0;
9031 sampler_ci.anisotropyEnable = VK_FALSE;
9032 sampler_ci.maxAnisotropy = 1;
9033 sampler_ci.compareEnable = VK_FALSE;
9034 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9035 sampler_ci.minLod = 1.0;
9036 sampler_ci.maxLod = 1.0;
9037 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9038 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009039
9040 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009041 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009042 ASSERT_VK_SUCCESS(err);
9043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009044 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009045
9046 VkDescriptorImageInfo descriptor_info;
9047 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9048 descriptor_info.sampler = sampler;
9049 descriptor_info.imageView = view;
9050
9051 VkWriteDescriptorSet descriptor_write;
9052 memset(&descriptor_write, 0, sizeof(descriptor_write));
9053 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009054 descriptor_write.dstSet = descriptorSet;
9055 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009056 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009057 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9058 descriptor_write.pImageInfo = &descriptor_info;
9059
9060 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9061
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009062 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009063
Chia-I Wuf7458c52015-10-26 21:10:41 +08009064 vkDestroySampler(m_device->device(), sampler, NULL);
9065 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9066 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009067}
9068
Karl Schultz6addd812016-02-02 17:17:23 -07009069TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9070 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9071 // into the other
9072 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009073
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9075 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9076 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009077
Tobin Ehlis04356f92015-10-27 16:35:27 -06009078 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009079 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009080 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009081 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9082 ds_type_count[0].descriptorCount = 1;
9083 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9084 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009085
9086 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009087 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9088 ds_pool_ci.pNext = NULL;
9089 ds_pool_ci.maxSets = 1;
9090 ds_pool_ci.poolSizeCount = 2;
9091 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009092
9093 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009094 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009095 ASSERT_VK_SUCCESS(err);
9096 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009097 dsl_binding[0].binding = 0;
9098 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9099 dsl_binding[0].descriptorCount = 1;
9100 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9101 dsl_binding[0].pImmutableSamplers = NULL;
9102 dsl_binding[1].binding = 1;
9103 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9104 dsl_binding[1].descriptorCount = 1;
9105 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9106 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009107
9108 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009109 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9110 ds_layout_ci.pNext = NULL;
9111 ds_layout_ci.bindingCount = 2;
9112 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009113
9114 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009115 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009116 ASSERT_VK_SUCCESS(err);
9117
9118 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009119 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009120 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009121 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009122 alloc_info.descriptorPool = ds_pool;
9123 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009124 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009125 ASSERT_VK_SUCCESS(err);
9126
9127 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009128 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9129 sampler_ci.pNext = NULL;
9130 sampler_ci.magFilter = VK_FILTER_NEAREST;
9131 sampler_ci.minFilter = VK_FILTER_NEAREST;
9132 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9133 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9134 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9135 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9136 sampler_ci.mipLodBias = 1.0;
9137 sampler_ci.anisotropyEnable = VK_FALSE;
9138 sampler_ci.maxAnisotropy = 1;
9139 sampler_ci.compareEnable = VK_FALSE;
9140 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9141 sampler_ci.minLod = 1.0;
9142 sampler_ci.maxLod = 1.0;
9143 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9144 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009145
9146 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009147 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009148 ASSERT_VK_SUCCESS(err);
9149
9150 VkDescriptorImageInfo info = {};
9151 info.sampler = sampler;
9152
9153 VkWriteDescriptorSet descriptor_write;
9154 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9155 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009156 descriptor_write.dstSet = descriptorSet;
9157 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009158 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009159 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9160 descriptor_write.pImageInfo = &info;
9161 // This write update should succeed
9162 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9163 // Now perform a copy update that fails due to type mismatch
9164 VkCopyDescriptorSet copy_ds_update;
9165 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9166 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9167 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009168 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009169 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009170 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009171 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009172 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9173
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009174 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009175 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 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 -06009177 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9178 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9179 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009180 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009181 copy_ds_update.dstSet = descriptorSet;
9182 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009183 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009184 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9185
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009186 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009187
Tobin Ehlis04356f92015-10-27 16:35:27 -06009188 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9190 "update array offset of 0 and update of "
9191 "5 descriptors oversteps total number "
9192 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009193
Tobin Ehlis04356f92015-10-27 16:35:27 -06009194 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9195 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9196 copy_ds_update.srcSet = descriptorSet;
9197 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009198 copy_ds_update.dstSet = descriptorSet;
9199 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009200 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009201 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9202
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009203 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009204
Chia-I Wuf7458c52015-10-26 21:10:41 +08009205 vkDestroySampler(m_device->device(), sampler, NULL);
9206 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009208}
9209
Karl Schultz6addd812016-02-02 17:17:23 -07009210TEST_F(VkLayerTest, NumSamplesMismatch) {
9211 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9212 // sampleCount
9213 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009216
Tobin Ehlis3b780662015-05-28 12:11:26 -06009217 ASSERT_NO_FATAL_FAILURE(InitState());
9218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009219 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009220 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009221 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009222
9223 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009224 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9225 ds_pool_ci.pNext = NULL;
9226 ds_pool_ci.maxSets = 1;
9227 ds_pool_ci.poolSizeCount = 1;
9228 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009229
Tobin Ehlis3b780662015-05-28 12:11:26 -06009230 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009231 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009232 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009233
Tony Barboureb254902015-07-15 12:50:33 -06009234 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009235 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009236 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009237 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009238 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9239 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009240
Tony Barboureb254902015-07-15 12:50:33 -06009241 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9242 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9243 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009244 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009245 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009246
Tobin Ehlis3b780662015-05-28 12:11:26 -06009247 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009248 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009249 ASSERT_VK_SUCCESS(err);
9250
9251 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009252 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009253 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009254 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009255 alloc_info.descriptorPool = ds_pool;
9256 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009257 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009258 ASSERT_VK_SUCCESS(err);
9259
Tony Barboureb254902015-07-15 12:50:33 -06009260 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009261 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009262 pipe_ms_state_ci.pNext = NULL;
9263 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9264 pipe_ms_state_ci.sampleShadingEnable = 0;
9265 pipe_ms_state_ci.minSampleShading = 1.0;
9266 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009267
Tony Barboureb254902015-07-15 12:50:33 -06009268 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009269 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9270 pipeline_layout_ci.pNext = NULL;
9271 pipeline_layout_ci.setLayoutCount = 1;
9272 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009273
9274 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009275 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009276 ASSERT_VK_SUCCESS(err);
9277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009278 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9279 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9280 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009281 VkPipelineObj pipe(m_device);
9282 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009283 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009284 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009285 pipe.SetMSAA(&pipe_ms_state_ci);
9286 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009287
Tony Barbourfe3351b2015-07-28 10:17:20 -06009288 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009289 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009290
Mark Young29927482016-05-04 14:38:51 -06009291 // Render triangle (the error should trigger on the attempt to draw).
9292 Draw(3, 1, 0, 0);
9293
9294 // Finalize recording of the command buffer
9295 EndCommandBuffer();
9296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009297 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009298
Chia-I Wuf7458c52015-10-26 21:10:41 +08009299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009302}
Mark Young29927482016-05-04 14:38:51 -06009303
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009304TEST_F(VkLayerTest, RenderPassIncompatible) {
9305 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9306 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009307 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009308 VkResult err;
9309
9310 ASSERT_NO_FATAL_FAILURE(InitState());
9311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9312
9313 VkDescriptorSetLayoutBinding dsl_binding = {};
9314 dsl_binding.binding = 0;
9315 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9316 dsl_binding.descriptorCount = 1;
9317 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9318 dsl_binding.pImmutableSamplers = NULL;
9319
9320 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9321 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9322 ds_layout_ci.pNext = NULL;
9323 ds_layout_ci.bindingCount = 1;
9324 ds_layout_ci.pBindings = &dsl_binding;
9325
9326 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009328 ASSERT_VK_SUCCESS(err);
9329
9330 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9331 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9332 pipeline_layout_ci.pNext = NULL;
9333 pipeline_layout_ci.setLayoutCount = 1;
9334 pipeline_layout_ci.pSetLayouts = &ds_layout;
9335
9336 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009338 ASSERT_VK_SUCCESS(err);
9339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009340 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9341 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9342 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009343 // Create a renderpass that will be incompatible with default renderpass
9344 VkAttachmentReference attach = {};
9345 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9346 VkAttachmentReference color_att = {};
9347 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9348 VkSubpassDescription subpass = {};
9349 subpass.inputAttachmentCount = 1;
9350 subpass.pInputAttachments = &attach;
9351 subpass.colorAttachmentCount = 1;
9352 subpass.pColorAttachments = &color_att;
9353 VkRenderPassCreateInfo rpci = {};
9354 rpci.subpassCount = 1;
9355 rpci.pSubpasses = &subpass;
9356 rpci.attachmentCount = 1;
9357 VkAttachmentDescription attach_desc = {};
9358 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009359 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9360 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009361 rpci.pAttachments = &attach_desc;
9362 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9363 VkRenderPass rp;
9364 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9365 VkPipelineObj pipe(m_device);
9366 pipe.AddShader(&vs);
9367 pipe.AddShader(&fs);
9368 pipe.AddColorAttachment();
9369 VkViewport view_port = {};
9370 m_viewports.push_back(view_port);
9371 pipe.SetViewport(m_viewports);
9372 VkRect2D rect = {};
9373 m_scissors.push_back(rect);
9374 pipe.SetScissor(m_scissors);
9375 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9376
9377 VkCommandBufferInheritanceInfo cbii = {};
9378 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9379 cbii.renderPass = rp;
9380 cbii.subpass = 0;
9381 VkCommandBufferBeginInfo cbbi = {};
9382 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9383 cbbi.pInheritanceInfo = &cbii;
9384 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9385 VkRenderPassBeginInfo rpbi = {};
9386 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9387 rpbi.framebuffer = m_framebuffer;
9388 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9390 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009393 // Render triangle (the error should trigger on the attempt to draw).
9394 Draw(3, 1, 0, 0);
9395
9396 // Finalize recording of the command buffer
9397 EndCommandBuffer();
9398
9399 m_errorMonitor->VerifyFound();
9400
9401 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9402 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9403 vkDestroyRenderPass(m_device->device(), rp, NULL);
9404}
9405
Mark Youngc89c6312016-03-31 16:03:20 -06009406TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9407 // Create Pipeline where the number of blend attachments doesn't match the
9408 // number of color attachments. In this case, we don't add any color
9409 // blend attachments even though we have a color attachment.
9410 VkResult err;
9411
9412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009413 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009414
9415 ASSERT_NO_FATAL_FAILURE(InitState());
9416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9417 VkDescriptorPoolSize ds_type_count = {};
9418 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9419 ds_type_count.descriptorCount = 1;
9420
9421 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9422 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9423 ds_pool_ci.pNext = NULL;
9424 ds_pool_ci.maxSets = 1;
9425 ds_pool_ci.poolSizeCount = 1;
9426 ds_pool_ci.pPoolSizes = &ds_type_count;
9427
9428 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009429 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009430 ASSERT_VK_SUCCESS(err);
9431
9432 VkDescriptorSetLayoutBinding dsl_binding = {};
9433 dsl_binding.binding = 0;
9434 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9435 dsl_binding.descriptorCount = 1;
9436 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9437 dsl_binding.pImmutableSamplers = NULL;
9438
9439 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9440 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9441 ds_layout_ci.pNext = NULL;
9442 ds_layout_ci.bindingCount = 1;
9443 ds_layout_ci.pBindings = &dsl_binding;
9444
9445 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009447 ASSERT_VK_SUCCESS(err);
9448
9449 VkDescriptorSet descriptorSet;
9450 VkDescriptorSetAllocateInfo alloc_info = {};
9451 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9452 alloc_info.descriptorSetCount = 1;
9453 alloc_info.descriptorPool = ds_pool;
9454 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009455 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009456 ASSERT_VK_SUCCESS(err);
9457
9458 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009460 pipe_ms_state_ci.pNext = NULL;
9461 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9462 pipe_ms_state_ci.sampleShadingEnable = 0;
9463 pipe_ms_state_ci.minSampleShading = 1.0;
9464 pipe_ms_state_ci.pSampleMask = NULL;
9465
9466 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9467 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9468 pipeline_layout_ci.pNext = NULL;
9469 pipeline_layout_ci.setLayoutCount = 1;
9470 pipeline_layout_ci.pSetLayouts = &ds_layout;
9471
9472 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009473 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009474 ASSERT_VK_SUCCESS(err);
9475
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009476 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9477 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9478 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009479 VkPipelineObj pipe(m_device);
9480 pipe.AddShader(&vs);
9481 pipe.AddShader(&fs);
9482 pipe.SetMSAA(&pipe_ms_state_ci);
9483 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9484
9485 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009486 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009487
Mark Young29927482016-05-04 14:38:51 -06009488 // Render triangle (the error should trigger on the attempt to draw).
9489 Draw(3, 1, 0, 0);
9490
9491 // Finalize recording of the command buffer
9492 EndCommandBuffer();
9493
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009494 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009495
9496 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9497 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9498 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9499}
Mark Young29927482016-05-04 14:38:51 -06009500
Mark Muellerd4914412016-06-13 17:52:06 -06009501TEST_F(VkLayerTest, MissingClearAttachment) {
9502 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9503 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009504 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +12009506 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -06009507
9508 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9509 m_errorMonitor->VerifyFound();
9510}
9511
Karl Schultz6addd812016-02-02 17:17:23 -07009512TEST_F(VkLayerTest, ClearCmdNoDraw) {
9513 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9514 // to issuing a Draw
9515 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009518 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009519
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009520 ASSERT_NO_FATAL_FAILURE(InitState());
9521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009522
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009523 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009524 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9525 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009526
9527 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009528 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9529 ds_pool_ci.pNext = NULL;
9530 ds_pool_ci.maxSets = 1;
9531 ds_pool_ci.poolSizeCount = 1;
9532 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009533
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009534 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009535 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009536 ASSERT_VK_SUCCESS(err);
9537
Tony Barboureb254902015-07-15 12:50:33 -06009538 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009539 dsl_binding.binding = 0;
9540 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9541 dsl_binding.descriptorCount = 1;
9542 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9543 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009544
Tony Barboureb254902015-07-15 12:50:33 -06009545 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009546 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9547 ds_layout_ci.pNext = NULL;
9548 ds_layout_ci.bindingCount = 1;
9549 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009550
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009551 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009553 ASSERT_VK_SUCCESS(err);
9554
9555 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009556 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009557 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009558 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009559 alloc_info.descriptorPool = ds_pool;
9560 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009561 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009562 ASSERT_VK_SUCCESS(err);
9563
Tony Barboureb254902015-07-15 12:50:33 -06009564 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009565 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009566 pipe_ms_state_ci.pNext = NULL;
9567 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9568 pipe_ms_state_ci.sampleShadingEnable = 0;
9569 pipe_ms_state_ci.minSampleShading = 1.0;
9570 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009571
Tony Barboureb254902015-07-15 12:50:33 -06009572 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009573 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9574 pipeline_layout_ci.pNext = NULL;
9575 pipeline_layout_ci.setLayoutCount = 1;
9576 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009577
9578 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009580 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009583 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009584 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009586
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009587 VkPipelineObj pipe(m_device);
9588 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009589 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009590 pipe.SetMSAA(&pipe_ms_state_ci);
9591 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009592
9593 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009594
Karl Schultz6addd812016-02-02 17:17:23 -07009595 // Main thing we care about for this test is that the VkImage obj we're
9596 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009597 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009598 VkClearAttachment color_attachment;
9599 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9600 color_attachment.clearValue.color.float32[0] = 1.0;
9601 color_attachment.clearValue.color.float32[1] = 1.0;
9602 color_attachment.clearValue.color.float32[2] = 1.0;
9603 color_attachment.clearValue.color.float32[3] = 1.0;
9604 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009605 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009607 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009608
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009609 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009610
Chia-I Wuf7458c52015-10-26 21:10:41 +08009611 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9612 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9613 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009614}
9615
Karl Schultz6addd812016-02-02 17:17:23 -07009616TEST_F(VkLayerTest, VtxBufferBadIndex) {
9617 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9620 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009621
Tobin Ehlis502480b2015-06-24 15:53:07 -06009622 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009623 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009625
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009626 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009627 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9628 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009629
9630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9632 ds_pool_ci.pNext = NULL;
9633 ds_pool_ci.maxSets = 1;
9634 ds_pool_ci.poolSizeCount = 1;
9635 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009636
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009637 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009639 ASSERT_VK_SUCCESS(err);
9640
Tony Barboureb254902015-07-15 12:50:33 -06009641 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009642 dsl_binding.binding = 0;
9643 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9644 dsl_binding.descriptorCount = 1;
9645 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9646 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009647
Tony Barboureb254902015-07-15 12:50:33 -06009648 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009649 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9650 ds_layout_ci.pNext = NULL;
9651 ds_layout_ci.bindingCount = 1;
9652 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009653
Tobin Ehlis502480b2015-06-24 15:53:07 -06009654 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009656 ASSERT_VK_SUCCESS(err);
9657
9658 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009659 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009660 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009661 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009662 alloc_info.descriptorPool = ds_pool;
9663 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009664 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009665 ASSERT_VK_SUCCESS(err);
9666
Tony Barboureb254902015-07-15 12:50:33 -06009667 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009669 pipe_ms_state_ci.pNext = NULL;
9670 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9671 pipe_ms_state_ci.sampleShadingEnable = 0;
9672 pipe_ms_state_ci.minSampleShading = 1.0;
9673 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009674
Tony Barboureb254902015-07-15 12:50:33 -06009675 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009676 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9677 pipeline_layout_ci.pNext = NULL;
9678 pipeline_layout_ci.setLayoutCount = 1;
9679 pipeline_layout_ci.pSetLayouts = &ds_layout;
9680 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009682 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009683 ASSERT_VK_SUCCESS(err);
9684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009685 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9686 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9687 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009688 VkPipelineObj pipe(m_device);
9689 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009690 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009691 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009692 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009693 pipe.SetViewport(m_viewports);
9694 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009695 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009696
9697 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009698 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009699 // Don't care about actual data, just need to get to draw to flag error
9700 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009701 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009702 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009703 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009704
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009705 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009706
Chia-I Wuf7458c52015-10-26 21:10:41 +08009707 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9708 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9709 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009710}
Mark Muellerdfe37552016-07-07 14:47:42 -06009711
Mark Mueller2ee294f2016-08-04 12:59:48 -06009712TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9713 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9714 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009715 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009717 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9718 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009720 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9721 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009724
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009726 // The following test fails with recent NVidia drivers.
9727 // By the time core_validation is reached, the NVidia
9728 // driver has sanitized the invalid condition and core_validation
9729 // is not introduced to the failure condition. This is not the case
9730 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009731 // uint32_t count = static_cast<uint32_t>(~0);
9732 // VkPhysicalDevice physical_device;
9733 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9734 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009737 float queue_priority = 0.0;
9738
9739 VkDeviceQueueCreateInfo queue_create_info = {};
9740 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9741 queue_create_info.queueCount = 1;
9742 queue_create_info.pQueuePriorities = &queue_priority;
9743 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9744
9745 VkPhysicalDeviceFeatures features = m_device->phy().features();
9746 VkDevice testDevice;
9747 VkDeviceCreateInfo device_create_info = {};
9748 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9749 device_create_info.queueCreateInfoCount = 1;
9750 device_create_info.pQueueCreateInfos = &queue_create_info;
9751 device_create_info.pEnabledFeatures = &features;
9752 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9753 m_errorMonitor->VerifyFound();
9754
9755 queue_create_info.queueFamilyIndex = 1;
9756
9757 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9758 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9759 for (unsigned i = 0; i < feature_count; i++) {
9760 if (VK_FALSE == feature_array[i]) {
9761 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009763 device_create_info.pEnabledFeatures = &features;
9764 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9765 m_errorMonitor->VerifyFound();
9766 break;
9767 }
9768 }
9769}
9770
9771TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9772 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9773 "End a command buffer with a query still in progress.");
9774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009775 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9776 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9777 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009778
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009782
9783 ASSERT_NO_FATAL_FAILURE(InitState());
9784
9785 VkEvent event;
9786 VkEventCreateInfo event_create_info{};
9787 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9788 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9789
Mark Mueller2ee294f2016-08-04 12:59:48 -06009790 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009791 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009792
9793 BeginCommandBuffer();
9794
9795 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 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 -06009797 ASSERT_TRUE(image.initialized());
9798 VkImageMemoryBarrier img_barrier = {};
9799 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9800 img_barrier.pNext = NULL;
9801 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9802 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9803 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9804 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9805 img_barrier.image = image.handle();
9806 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009807
9808 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9809 // that layer validation catches the case when it is not.
9810 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009811 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9812 img_barrier.subresourceRange.baseArrayLayer = 0;
9813 img_barrier.subresourceRange.baseMipLevel = 0;
9814 img_barrier.subresourceRange.layerCount = 1;
9815 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9817 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009818 m_errorMonitor->VerifyFound();
9819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009821
9822 VkQueryPool query_pool;
9823 VkQueryPoolCreateInfo query_pool_create_info = {};
9824 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9825 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9826 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009830 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9831
9832 vkEndCommandBuffer(m_commandBuffer->handle());
9833 m_errorMonitor->VerifyFound();
9834
9835 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9836 vkDestroyEvent(m_device->device(), event, nullptr);
9837}
9838
Mark Muellerdfe37552016-07-07 14:47:42 -06009839TEST_F(VkLayerTest, VertexBufferInvalid) {
9840 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9841 "delete a buffer twice, use an invalid offset for each "
9842 "buffer type, and attempt to bind a null buffer");
9843
9844 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9845 "using deleted buffer ";
9846 const char *double_destroy_message = "Cannot free buffer 0x";
9847 const char *invalid_offset_message = "vkBindBufferMemory(): "
9848 "memoryOffset is 0x";
9849 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9850 "storage memoryOffset "
9851 "is 0x";
9852 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9853 "texel memoryOffset "
9854 "is 0x";
9855 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9856 "uniform memoryOffset "
9857 "is 0x";
9858 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9859 " to Bind Obj(0x";
9860 const char *free_invalid_buffer_message = "Request to delete memory "
9861 "object 0x";
9862
9863 ASSERT_NO_FATAL_FAILURE(InitState());
9864 ASSERT_NO_FATAL_FAILURE(InitViewport());
9865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9866
9867 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -06009869 pipe_ms_state_ci.pNext = NULL;
9870 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9871 pipe_ms_state_ci.sampleShadingEnable = 0;
9872 pipe_ms_state_ci.minSampleShading = 1.0;
9873 pipe_ms_state_ci.pSampleMask = nullptr;
9874
9875 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9876 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9877 VkPipelineLayout pipeline_layout;
9878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009879 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -06009880 ASSERT_VK_SUCCESS(err);
9881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009882 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9883 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -06009884 VkPipelineObj pipe(m_device);
9885 pipe.AddShader(&vs);
9886 pipe.AddShader(&fs);
9887 pipe.AddColorAttachment();
9888 pipe.SetMSAA(&pipe_ms_state_ci);
9889 pipe.SetViewport(m_viewports);
9890 pipe.SetScissor(m_scissors);
9891 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9892
9893 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -06009895
9896 {
9897 // Create and bind a vertex buffer in a reduced scope, which will cause
9898 // it to be deleted upon leaving this scope
9899 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -06009901 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
9902 draw_verticies.AddVertexInputToPipe(pipe);
9903 }
9904
9905 Draw(1, 0, 0, 0);
9906
9907 EndCommandBuffer();
9908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -06009910 QueueCommandBuffer(false);
9911 m_errorMonitor->VerifyFound();
9912
9913 {
9914 // Create and bind a vertex buffer in a reduced scope, and delete it
9915 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
9917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -06009918 buffer_test.TestDoubleDestroy();
9919 }
9920 m_errorMonitor->VerifyFound();
9921
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009923 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
9925 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
9926 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009927 m_errorMonitor->VerifyFound();
9928 }
9929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
9931 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009932 // Create and bind a memory buffer with an invalid offset again,
9933 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
9935 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
9936 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009937 m_errorMonitor->VerifyFound();
9938 }
9939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009941 // Create and bind a memory buffer with an invalid offset again, but
9942 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
9944 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
9945 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009946 m_errorMonitor->VerifyFound();
9947 }
9948
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -06009950 // Create and bind a memory buffer with an invalid offset again, but
9951 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
9953 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
9954 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009955 m_errorMonitor->VerifyFound();
9956 }
9957
9958 {
9959 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
9961 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
9962 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009963 m_errorMonitor->VerifyFound();
9964 }
9965
9966 {
9967 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
9969 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
9970 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -06009971 }
9972 m_errorMonitor->VerifyFound();
9973
9974 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9975}
9976
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009977// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9978TEST_F(VkLayerTest, InvalidImageLayout) {
9979 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009980 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9981 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009982 // 3 in ValidateCmdBufImageLayouts
9983 // * -1 Attempt to submit cmd buf w/ deleted image
9984 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9985 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9987 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009988
9989 ASSERT_NO_FATAL_FAILURE(InitState());
9990 // Create src & dst images to use for copy operations
9991 VkImage src_image;
9992 VkImage dst_image;
9993
9994 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9995 const int32_t tex_width = 32;
9996 const int32_t tex_height = 32;
9997
9998 VkImageCreateInfo image_create_info = {};
9999 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10000 image_create_info.pNext = NULL;
10001 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10002 image_create_info.format = tex_format;
10003 image_create_info.extent.width = tex_width;
10004 image_create_info.extent.height = tex_height;
10005 image_create_info.extent.depth = 1;
10006 image_create_info.mipLevels = 1;
10007 image_create_info.arrayLayers = 4;
10008 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10009 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10010 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10011 image_create_info.flags = 0;
10012
10013 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10014 ASSERT_VK_SUCCESS(err);
10015 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10016 ASSERT_VK_SUCCESS(err);
10017
10018 BeginCommandBuffer();
10019 VkImageCopy copyRegion;
10020 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10021 copyRegion.srcSubresource.mipLevel = 0;
10022 copyRegion.srcSubresource.baseArrayLayer = 0;
10023 copyRegion.srcSubresource.layerCount = 1;
10024 copyRegion.srcOffset.x = 0;
10025 copyRegion.srcOffset.y = 0;
10026 copyRegion.srcOffset.z = 0;
10027 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10028 copyRegion.dstSubresource.mipLevel = 0;
10029 copyRegion.dstSubresource.baseArrayLayer = 0;
10030 copyRegion.dstSubresource.layerCount = 1;
10031 copyRegion.dstOffset.x = 0;
10032 copyRegion.dstOffset.y = 0;
10033 copyRegion.dstOffset.z = 0;
10034 copyRegion.extent.width = 1;
10035 copyRegion.extent.height = 1;
10036 copyRegion.extent.depth = 1;
10037 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10038 m_errorMonitor->VerifyFound();
10039 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10041 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10042 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010043 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10044 m_errorMonitor->VerifyFound();
10045 // Final src error is due to bad layout type
10046 m_errorMonitor->SetDesiredFailureMsg(
10047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10048 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10049 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10050 m_errorMonitor->VerifyFound();
10051 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10053 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010054 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10055 m_errorMonitor->VerifyFound();
10056 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10058 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10059 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010060 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10061 m_errorMonitor->VerifyFound();
10062 m_errorMonitor->SetDesiredFailureMsg(
10063 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10064 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10065 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10066 m_errorMonitor->VerifyFound();
10067 // Now cause error due to bad image layout transition in PipelineBarrier
10068 VkImageMemoryBarrier image_barrier[1] = {};
10069 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10070 image_barrier[0].image = src_image;
10071 image_barrier[0].subresourceRange.layerCount = 2;
10072 image_barrier[0].subresourceRange.levelCount = 2;
10073 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10075 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10076 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10077 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10078 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010079 m_errorMonitor->VerifyFound();
10080
10081 // Finally some layout errors at RenderPass create time
10082 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10083 VkAttachmentReference attach = {};
10084 // perf warning for GENERAL layout w/ non-DS input attachment
10085 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10086 VkSubpassDescription subpass = {};
10087 subpass.inputAttachmentCount = 1;
10088 subpass.pInputAttachments = &attach;
10089 VkRenderPassCreateInfo rpci = {};
10090 rpci.subpassCount = 1;
10091 rpci.pSubpasses = &subpass;
10092 rpci.attachmentCount = 1;
10093 VkAttachmentDescription attach_desc = {};
10094 attach_desc.format = VK_FORMAT_UNDEFINED;
10095 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010097 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10099 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10101 m_errorMonitor->VerifyFound();
10102 // error w/ non-general layout
10103 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10104
10105 m_errorMonitor->SetDesiredFailureMsg(
10106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10107 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10108 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10109 m_errorMonitor->VerifyFound();
10110 subpass.inputAttachmentCount = 0;
10111 subpass.colorAttachmentCount = 1;
10112 subpass.pColorAttachments = &attach;
10113 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10114 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10116 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010117 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10118 m_errorMonitor->VerifyFound();
10119 // error w/ non-color opt or GENERAL layout for color attachment
10120 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10121 m_errorMonitor->SetDesiredFailureMsg(
10122 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10123 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10124 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10125 m_errorMonitor->VerifyFound();
10126 subpass.colorAttachmentCount = 0;
10127 subpass.pDepthStencilAttachment = &attach;
10128 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10129 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10131 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010132 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10133 m_errorMonitor->VerifyFound();
10134 // error w/ non-ds opt or GENERAL layout for color attachment
10135 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10137 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10138 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010139 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10140 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010141 // For this error we need a valid renderpass so create default one
10142 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10143 attach.attachment = 0;
10144 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10145 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10146 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10147 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10148 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10149 // Can't do a CLEAR load on READ_ONLY initialLayout
10150 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10151 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10152 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10154 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10155 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010156 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10157 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010158
10159 vkDestroyImage(m_device->device(), src_image, NULL);
10160 vkDestroyImage(m_device->device(), dst_image, NULL);
10161}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010162
Tobin Ehlise0936662016-10-11 08:10:51 -060010163TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10164 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10165 VkResult err;
10166
10167 ASSERT_NO_FATAL_FAILURE(InitState());
10168
10169 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10170 VkImageTiling tiling;
10171 VkFormatProperties format_properties;
10172 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10173 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10174 tiling = VK_IMAGE_TILING_LINEAR;
10175 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10176 tiling = VK_IMAGE_TILING_OPTIMAL;
10177 } else {
10178 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10179 "skipped.\n");
10180 return;
10181 }
10182
10183 VkDescriptorPoolSize ds_type = {};
10184 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10185 ds_type.descriptorCount = 1;
10186
10187 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10188 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10189 ds_pool_ci.maxSets = 1;
10190 ds_pool_ci.poolSizeCount = 1;
10191 ds_pool_ci.pPoolSizes = &ds_type;
10192 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10193
10194 VkDescriptorPool ds_pool;
10195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10196 ASSERT_VK_SUCCESS(err);
10197
10198 VkDescriptorSetLayoutBinding dsl_binding = {};
10199 dsl_binding.binding = 0;
10200 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10201 dsl_binding.descriptorCount = 1;
10202 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10203 dsl_binding.pImmutableSamplers = NULL;
10204
10205 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10206 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10207 ds_layout_ci.pNext = NULL;
10208 ds_layout_ci.bindingCount = 1;
10209 ds_layout_ci.pBindings = &dsl_binding;
10210
10211 VkDescriptorSetLayout ds_layout;
10212 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10213 ASSERT_VK_SUCCESS(err);
10214
10215 VkDescriptorSetAllocateInfo alloc_info = {};
10216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10217 alloc_info.descriptorSetCount = 1;
10218 alloc_info.descriptorPool = ds_pool;
10219 alloc_info.pSetLayouts = &ds_layout;
10220 VkDescriptorSet descriptor_set;
10221 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10222 ASSERT_VK_SUCCESS(err);
10223
10224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10226 pipeline_layout_ci.pNext = NULL;
10227 pipeline_layout_ci.setLayoutCount = 1;
10228 pipeline_layout_ci.pSetLayouts = &ds_layout;
10229 VkPipelineLayout pipeline_layout;
10230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10231 ASSERT_VK_SUCCESS(err);
10232
10233 VkImageObj image(m_device);
10234 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10235 ASSERT_TRUE(image.initialized());
10236 VkImageView view = image.targetView(tex_format);
10237
10238 VkDescriptorImageInfo image_info = {};
10239 image_info.imageView = view;
10240 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10241
10242 VkWriteDescriptorSet descriptor_write = {};
10243 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10244 descriptor_write.dstSet = descriptor_set;
10245 descriptor_write.dstBinding = 0;
10246 descriptor_write.descriptorCount = 1;
10247 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10248 descriptor_write.pImageInfo = &image_info;
10249
10250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10251 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10252 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10253 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10254 m_errorMonitor->VerifyFound();
10255
10256 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10257 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10258 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10259 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10260}
10261
Mark Mueller93b938f2016-08-18 10:27:40 -060010262TEST_F(VkLayerTest, SimultaneousUse) {
10263 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10264 "in primary and secondary command buffers.");
10265
10266 ASSERT_NO_FATAL_FAILURE(InitState());
10267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10268
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010269 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010270 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10271 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010272
10273 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010274 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010275 command_buffer_allocate_info.commandPool = m_commandPool;
10276 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10277 command_buffer_allocate_info.commandBufferCount = 1;
10278
10279 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010280 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010281 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10282 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010283 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010284 command_buffer_inheritance_info.renderPass = m_renderPass;
10285 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10286 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010287 command_buffer_begin_info.flags =
10288 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010289 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10290
10291 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010292 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10293 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010294 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010295 vkEndCommandBuffer(secondary_command_buffer);
10296
Mark Mueller93b938f2016-08-18 10:27:40 -060010297 VkSubmitInfo submit_info = {};
10298 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10299 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010301 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010302
Mark Mueller4042b652016-09-05 22:52:21 -060010303 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10306 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010307 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010308 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10309 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010310
10311 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010312 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10313
Mark Mueller4042b652016-09-05 22:52:21 -060010314 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010315 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010316 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10319 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010320 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010321 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10322 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010323}
10324
Mark Mueller917f6bc2016-08-30 10:57:19 -060010325TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10326 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10327 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010328 "Delete objects that are inuse. Call VkQueueSubmit "
10329 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010330
10331 ASSERT_NO_FATAL_FAILURE(InitState());
10332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10335 const char *cannot_delete_event_message = "Cannot delete event 0x";
10336 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10337 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010338
10339 BeginCommandBuffer();
10340
10341 VkEvent event;
10342 VkEventCreateInfo event_create_info = {};
10343 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10344 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010345 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010346
Mark Muellerc8d441e2016-08-23 17:36:00 -060010347 EndCommandBuffer();
10348 vkDestroyEvent(m_device->device(), event, nullptr);
10349
10350 VkSubmitInfo submit_info = {};
10351 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10352 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010353 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010355 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10356 m_errorMonitor->VerifyFound();
10357
10358 m_errorMonitor->SetDesiredFailureMsg(0, "");
10359 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10360
10361 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10362
Mark Mueller917f6bc2016-08-30 10:57:19 -060010363 VkSemaphoreCreateInfo semaphore_create_info = {};
10364 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10365 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010366 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010367 VkFenceCreateInfo fence_create_info = {};
10368 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10369 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010371
10372 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010373 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010374 descriptor_pool_type_count.descriptorCount = 1;
10375
10376 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10377 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10378 descriptor_pool_create_info.maxSets = 1;
10379 descriptor_pool_create_info.poolSizeCount = 1;
10380 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010382
10383 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010384 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010385
10386 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010387 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010388 descriptorset_layout_binding.descriptorCount = 1;
10389 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10390
10391 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010392 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010393 descriptorset_layout_create_info.bindingCount = 1;
10394 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10395
10396 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 ASSERT_VK_SUCCESS(
10398 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010399
10400 VkDescriptorSet descriptorset;
10401 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010403 descriptorset_allocate_info.descriptorSetCount = 1;
10404 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10405 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010407
Mark Mueller4042b652016-09-05 22:52:21 -060010408 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10409
10410 VkDescriptorBufferInfo buffer_info = {};
10411 buffer_info.buffer = buffer_test.GetBuffer();
10412 buffer_info.offset = 0;
10413 buffer_info.range = 1024;
10414
10415 VkWriteDescriptorSet write_descriptor_set = {};
10416 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10417 write_descriptor_set.dstSet = descriptorset;
10418 write_descriptor_set.descriptorCount = 1;
10419 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10420 write_descriptor_set.pBufferInfo = &buffer_info;
10421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010424 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10425 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010426
10427 VkPipelineObj pipe(m_device);
10428 pipe.AddColorAttachment();
10429 pipe.AddShader(&vs);
10430 pipe.AddShader(&fs);
10431
10432 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010433 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010434 pipeline_layout_create_info.setLayoutCount = 1;
10435 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10436
10437 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010439
10440 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10441
Mark Muellerc8d441e2016-08-23 17:36:00 -060010442 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010445 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10446 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10447 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010448
Mark Muellerc8d441e2016-08-23 17:36:00 -060010449 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010450
Mark Mueller917f6bc2016-08-30 10:57:19 -060010451 submit_info.signalSemaphoreCount = 1;
10452 submit_info.pSignalSemaphores = &semaphore;
10453 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010456 vkDestroyEvent(m_device->device(), event, nullptr);
10457 m_errorMonitor->VerifyFound();
10458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010460 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10461 m_errorMonitor->VerifyFound();
10462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010464 vkDestroyFence(m_device->device(), fence, nullptr);
10465 m_errorMonitor->VerifyFound();
10466
Tobin Ehlis122207b2016-09-01 08:50:06 -070010467 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010468 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10469 vkDestroyFence(m_device->device(), fence, nullptr);
10470 vkDestroyEvent(m_device->device(), event, nullptr);
10471 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010472 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010473 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10474}
10475
Tobin Ehlis2adda372016-09-01 08:51:06 -070010476TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10477 TEST_DESCRIPTION("Delete in-use query pool.");
10478
10479 ASSERT_NO_FATAL_FAILURE(InitState());
10480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10481
10482 VkQueryPool query_pool;
10483 VkQueryPoolCreateInfo query_pool_ci{};
10484 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10485 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10486 query_pool_ci.queryCount = 1;
10487 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10488 BeginCommandBuffer();
10489 // Reset query pool to create binding with cmd buffer
10490 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10491
10492 EndCommandBuffer();
10493
10494 VkSubmitInfo submit_info = {};
10495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10496 submit_info.commandBufferCount = 1;
10497 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10498 // Submit cmd buffer and then destroy query pool while in-flight
10499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010502 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10503 m_errorMonitor->VerifyFound();
10504
10505 vkQueueWaitIdle(m_device->m_queue);
10506 // Now that cmd buffer done we can safely destroy query_pool
10507 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10508}
10509
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010510TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10511 TEST_DESCRIPTION("Delete in-use pipeline.");
10512
10513 ASSERT_NO_FATAL_FAILURE(InitState());
10514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10515
10516 // Empty pipeline layout used for binding PSO
10517 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10518 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10519 pipeline_layout_ci.setLayoutCount = 0;
10520 pipeline_layout_ci.pSetLayouts = NULL;
10521
10522 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010523 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010524 ASSERT_VK_SUCCESS(err);
10525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010527 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10529 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010530 // Store pipeline handle so we can actually delete it before test finishes
10531 VkPipeline delete_this_pipeline;
10532 { // Scope pipeline so it will be auto-deleted
10533 VkPipelineObj pipe(m_device);
10534 pipe.AddShader(&vs);
10535 pipe.AddShader(&fs);
10536 pipe.AddColorAttachment();
10537 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10538 delete_this_pipeline = pipe.handle();
10539
10540 BeginCommandBuffer();
10541 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010542 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010543
10544 EndCommandBuffer();
10545
10546 VkSubmitInfo submit_info = {};
10547 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10548 submit_info.commandBufferCount = 1;
10549 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10550 // Submit cmd buffer and then pipeline destroyed while in-flight
10551 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10552 } // Pipeline deletion triggered here
10553 m_errorMonitor->VerifyFound();
10554 // Make sure queue finished and then actually delete pipeline
10555 vkQueueWaitIdle(m_device->m_queue);
10556 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10557 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10558}
10559
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010560TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10561 TEST_DESCRIPTION("Delete in-use imageView.");
10562
10563 ASSERT_NO_FATAL_FAILURE(InitState());
10564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10565
10566 VkDescriptorPoolSize ds_type_count;
10567 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10568 ds_type_count.descriptorCount = 1;
10569
10570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10572 ds_pool_ci.maxSets = 1;
10573 ds_pool_ci.poolSizeCount = 1;
10574 ds_pool_ci.pPoolSizes = &ds_type_count;
10575
10576 VkDescriptorPool ds_pool;
10577 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10578 ASSERT_VK_SUCCESS(err);
10579
10580 VkSamplerCreateInfo sampler_ci = {};
10581 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10582 sampler_ci.pNext = NULL;
10583 sampler_ci.magFilter = VK_FILTER_NEAREST;
10584 sampler_ci.minFilter = VK_FILTER_NEAREST;
10585 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10586 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10587 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10588 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10589 sampler_ci.mipLodBias = 1.0;
10590 sampler_ci.anisotropyEnable = VK_FALSE;
10591 sampler_ci.maxAnisotropy = 1;
10592 sampler_ci.compareEnable = VK_FALSE;
10593 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10594 sampler_ci.minLod = 1.0;
10595 sampler_ci.maxLod = 1.0;
10596 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10597 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10598 VkSampler sampler;
10599
10600 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10601 ASSERT_VK_SUCCESS(err);
10602
10603 VkDescriptorSetLayoutBinding layout_binding;
10604 layout_binding.binding = 0;
10605 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10606 layout_binding.descriptorCount = 1;
10607 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10608 layout_binding.pImmutableSamplers = NULL;
10609
10610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10612 ds_layout_ci.bindingCount = 1;
10613 ds_layout_ci.pBindings = &layout_binding;
10614 VkDescriptorSetLayout ds_layout;
10615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10616 ASSERT_VK_SUCCESS(err);
10617
10618 VkDescriptorSetAllocateInfo alloc_info = {};
10619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10620 alloc_info.descriptorSetCount = 1;
10621 alloc_info.descriptorPool = ds_pool;
10622 alloc_info.pSetLayouts = &ds_layout;
10623 VkDescriptorSet descriptor_set;
10624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10625 ASSERT_VK_SUCCESS(err);
10626
10627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10629 pipeline_layout_ci.pNext = NULL;
10630 pipeline_layout_ci.setLayoutCount = 1;
10631 pipeline_layout_ci.pSetLayouts = &ds_layout;
10632
10633 VkPipelineLayout pipeline_layout;
10634 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10635 ASSERT_VK_SUCCESS(err);
10636
10637 VkImageObj image(m_device);
10638 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10639 ASSERT_TRUE(image.initialized());
10640
10641 VkImageView view;
10642 VkImageViewCreateInfo ivci = {};
10643 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10644 ivci.image = image.handle();
10645 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10646 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10647 ivci.subresourceRange.layerCount = 1;
10648 ivci.subresourceRange.baseMipLevel = 0;
10649 ivci.subresourceRange.levelCount = 1;
10650 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10651
10652 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10653 ASSERT_VK_SUCCESS(err);
10654
10655 VkDescriptorImageInfo image_info{};
10656 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10657 image_info.imageView = view;
10658 image_info.sampler = sampler;
10659
10660 VkWriteDescriptorSet descriptor_write = {};
10661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10662 descriptor_write.dstSet = descriptor_set;
10663 descriptor_write.dstBinding = 0;
10664 descriptor_write.descriptorCount = 1;
10665 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10666 descriptor_write.pImageInfo = &image_info;
10667
10668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10669
10670 // Create PSO to use the sampler
10671 char const *vsSource = "#version 450\n"
10672 "\n"
10673 "out gl_PerVertex { \n"
10674 " vec4 gl_Position;\n"
10675 "};\n"
10676 "void main(){\n"
10677 " gl_Position = vec4(1);\n"
10678 "}\n";
10679 char const *fsSource = "#version 450\n"
10680 "\n"
10681 "layout(set=0, binding=0) uniform sampler2D s;\n"
10682 "layout(location=0) out vec4 x;\n"
10683 "void main(){\n"
10684 " x = texture(s, vec2(1));\n"
10685 "}\n";
10686 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10688 VkPipelineObj pipe(m_device);
10689 pipe.AddShader(&vs);
10690 pipe.AddShader(&fs);
10691 pipe.AddColorAttachment();
10692 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10693
10694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10695
10696 BeginCommandBuffer();
10697 // Bind pipeline to cmd buffer
10698 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10700 &descriptor_set, 0, nullptr);
10701 Draw(1, 0, 0, 0);
10702 EndCommandBuffer();
10703 // Submit cmd buffer then destroy sampler
10704 VkSubmitInfo submit_info = {};
10705 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10706 submit_info.commandBufferCount = 1;
10707 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10708 // Submit cmd buffer and then destroy imageView while in-flight
10709 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10710
10711 vkDestroyImageView(m_device->device(), view, nullptr);
10712 m_errorMonitor->VerifyFound();
10713 vkQueueWaitIdle(m_device->m_queue);
10714 // Now we can actually destroy imageView
10715 vkDestroyImageView(m_device->device(), view, NULL);
10716 vkDestroySampler(m_device->device(), sampler, nullptr);
10717 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10718 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10720}
10721
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010722TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10723 TEST_DESCRIPTION("Delete in-use bufferView.");
10724
10725 ASSERT_NO_FATAL_FAILURE(InitState());
10726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10727
10728 VkDescriptorPoolSize ds_type_count;
10729 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10730 ds_type_count.descriptorCount = 1;
10731
10732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10734 ds_pool_ci.maxSets = 1;
10735 ds_pool_ci.poolSizeCount = 1;
10736 ds_pool_ci.pPoolSizes = &ds_type_count;
10737
10738 VkDescriptorPool ds_pool;
10739 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10740 ASSERT_VK_SUCCESS(err);
10741
10742 VkDescriptorSetLayoutBinding layout_binding;
10743 layout_binding.binding = 0;
10744 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10745 layout_binding.descriptorCount = 1;
10746 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10747 layout_binding.pImmutableSamplers = NULL;
10748
10749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10751 ds_layout_ci.bindingCount = 1;
10752 ds_layout_ci.pBindings = &layout_binding;
10753 VkDescriptorSetLayout ds_layout;
10754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10755 ASSERT_VK_SUCCESS(err);
10756
10757 VkDescriptorSetAllocateInfo alloc_info = {};
10758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10759 alloc_info.descriptorSetCount = 1;
10760 alloc_info.descriptorPool = ds_pool;
10761 alloc_info.pSetLayouts = &ds_layout;
10762 VkDescriptorSet descriptor_set;
10763 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10764 ASSERT_VK_SUCCESS(err);
10765
10766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10768 pipeline_layout_ci.pNext = NULL;
10769 pipeline_layout_ci.setLayoutCount = 1;
10770 pipeline_layout_ci.pSetLayouts = &ds_layout;
10771
10772 VkPipelineLayout pipeline_layout;
10773 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10774 ASSERT_VK_SUCCESS(err);
10775
10776 VkBuffer buffer;
10777 uint32_t queue_family_index = 0;
10778 VkBufferCreateInfo buffer_create_info = {};
10779 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10780 buffer_create_info.size = 1024;
10781 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10782 buffer_create_info.queueFamilyIndexCount = 1;
10783 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10784
10785 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10786 ASSERT_VK_SUCCESS(err);
10787
10788 VkMemoryRequirements memory_reqs;
10789 VkDeviceMemory buffer_memory;
10790
10791 VkMemoryAllocateInfo memory_info = {};
10792 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10793 memory_info.allocationSize = 0;
10794 memory_info.memoryTypeIndex = 0;
10795
10796 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10797 memory_info.allocationSize = memory_reqs.size;
10798 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10799 ASSERT_TRUE(pass);
10800
10801 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10802 ASSERT_VK_SUCCESS(err);
10803 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10804 ASSERT_VK_SUCCESS(err);
10805
10806 VkBufferView view;
10807 VkBufferViewCreateInfo bvci = {};
10808 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10809 bvci.buffer = buffer;
10810 bvci.format = VK_FORMAT_R8_UNORM;
10811 bvci.range = VK_WHOLE_SIZE;
10812
10813 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10814 ASSERT_VK_SUCCESS(err);
10815
10816 VkWriteDescriptorSet descriptor_write = {};
10817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10818 descriptor_write.dstSet = descriptor_set;
10819 descriptor_write.dstBinding = 0;
10820 descriptor_write.descriptorCount = 1;
10821 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10822 descriptor_write.pTexelBufferView = &view;
10823
10824 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10825
10826 char const *vsSource = "#version 450\n"
10827 "\n"
10828 "out gl_PerVertex { \n"
10829 " vec4 gl_Position;\n"
10830 "};\n"
10831 "void main(){\n"
10832 " gl_Position = vec4(1);\n"
10833 "}\n";
10834 char const *fsSource = "#version 450\n"
10835 "\n"
10836 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10837 "layout(location=0) out vec4 x;\n"
10838 "void main(){\n"
10839 " x = imageLoad(s, 0);\n"
10840 "}\n";
10841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10843 VkPipelineObj pipe(m_device);
10844 pipe.AddShader(&vs);
10845 pipe.AddShader(&fs);
10846 pipe.AddColorAttachment();
10847 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10848
10849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10850
10851 BeginCommandBuffer();
10852 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10853 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10854 VkRect2D scissor = {{0, 0}, {16, 16}};
10855 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10856 // Bind pipeline to cmd buffer
10857 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10858 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10859 &descriptor_set, 0, nullptr);
10860 Draw(1, 0, 0, 0);
10861 EndCommandBuffer();
10862
10863 VkSubmitInfo submit_info = {};
10864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10865 submit_info.commandBufferCount = 1;
10866 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10867 // Submit cmd buffer and then destroy bufferView while in-flight
10868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10869
10870 vkDestroyBufferView(m_device->device(), view, nullptr);
10871 m_errorMonitor->VerifyFound();
10872 vkQueueWaitIdle(m_device->m_queue);
10873 // Now we can actually destroy bufferView
10874 vkDestroyBufferView(m_device->device(), view, NULL);
10875 vkDestroyBuffer(m_device->device(), buffer, NULL);
10876 vkFreeMemory(m_device->device(), buffer_memory, NULL);
10877 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10878 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10879 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10880}
10881
Tobin Ehlis209532e2016-09-07 13:52:18 -060010882TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
10883 TEST_DESCRIPTION("Delete in-use sampler.");
10884
10885 ASSERT_NO_FATAL_FAILURE(InitState());
10886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10887
10888 VkDescriptorPoolSize ds_type_count;
10889 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10890 ds_type_count.descriptorCount = 1;
10891
10892 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10893 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10894 ds_pool_ci.maxSets = 1;
10895 ds_pool_ci.poolSizeCount = 1;
10896 ds_pool_ci.pPoolSizes = &ds_type_count;
10897
10898 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010899 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010900 ASSERT_VK_SUCCESS(err);
10901
10902 VkSamplerCreateInfo sampler_ci = {};
10903 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10904 sampler_ci.pNext = NULL;
10905 sampler_ci.magFilter = VK_FILTER_NEAREST;
10906 sampler_ci.minFilter = VK_FILTER_NEAREST;
10907 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10908 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10909 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10910 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10911 sampler_ci.mipLodBias = 1.0;
10912 sampler_ci.anisotropyEnable = VK_FALSE;
10913 sampler_ci.maxAnisotropy = 1;
10914 sampler_ci.compareEnable = VK_FALSE;
10915 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10916 sampler_ci.minLod = 1.0;
10917 sampler_ci.maxLod = 1.0;
10918 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10919 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10920 VkSampler sampler;
10921
10922 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10923 ASSERT_VK_SUCCESS(err);
10924
10925 VkDescriptorSetLayoutBinding layout_binding;
10926 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060010927 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060010928 layout_binding.descriptorCount = 1;
10929 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10930 layout_binding.pImmutableSamplers = NULL;
10931
10932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10934 ds_layout_ci.bindingCount = 1;
10935 ds_layout_ci.pBindings = &layout_binding;
10936 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010938 ASSERT_VK_SUCCESS(err);
10939
10940 VkDescriptorSetAllocateInfo alloc_info = {};
10941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10942 alloc_info.descriptorSetCount = 1;
10943 alloc_info.descriptorPool = ds_pool;
10944 alloc_info.pSetLayouts = &ds_layout;
10945 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010947 ASSERT_VK_SUCCESS(err);
10948
10949 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10950 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10951 pipeline_layout_ci.pNext = NULL;
10952 pipeline_layout_ci.setLayoutCount = 1;
10953 pipeline_layout_ci.pSetLayouts = &ds_layout;
10954
10955 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010956 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060010957 ASSERT_VK_SUCCESS(err);
10958
10959 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010960 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 -060010961 ASSERT_TRUE(image.initialized());
10962
10963 VkImageView view;
10964 VkImageViewCreateInfo ivci = {};
10965 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10966 ivci.image = image.handle();
10967 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10968 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10969 ivci.subresourceRange.layerCount = 1;
10970 ivci.subresourceRange.baseMipLevel = 0;
10971 ivci.subresourceRange.levelCount = 1;
10972 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10973
10974 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10975 ASSERT_VK_SUCCESS(err);
10976
10977 VkDescriptorImageInfo image_info{};
10978 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10979 image_info.imageView = view;
10980 image_info.sampler = sampler;
10981
10982 VkWriteDescriptorSet descriptor_write = {};
10983 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10984 descriptor_write.dstSet = descriptor_set;
10985 descriptor_write.dstBinding = 0;
10986 descriptor_write.descriptorCount = 1;
10987 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10988 descriptor_write.pImageInfo = &image_info;
10989
10990 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10991
10992 // Create PSO to use the sampler
10993 char const *vsSource = "#version 450\n"
10994 "\n"
10995 "out gl_PerVertex { \n"
10996 " vec4 gl_Position;\n"
10997 "};\n"
10998 "void main(){\n"
10999 " gl_Position = vec4(1);\n"
11000 "}\n";
11001 char const *fsSource = "#version 450\n"
11002 "\n"
11003 "layout(set=0, binding=0) uniform sampler2D s;\n"
11004 "layout(location=0) out vec4 x;\n"
11005 "void main(){\n"
11006 " x = texture(s, vec2(1));\n"
11007 "}\n";
11008 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11009 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11010 VkPipelineObj pipe(m_device);
11011 pipe.AddShader(&vs);
11012 pipe.AddShader(&fs);
11013 pipe.AddColorAttachment();
11014 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011017
11018 BeginCommandBuffer();
11019 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011020 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11021 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11022 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011023 Draw(1, 0, 0, 0);
11024 EndCommandBuffer();
11025 // Submit cmd buffer then destroy sampler
11026 VkSubmitInfo submit_info = {};
11027 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11028 submit_info.commandBufferCount = 1;
11029 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11030 // Submit cmd buffer and then destroy sampler while in-flight
11031 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11032
11033 vkDestroySampler(m_device->device(), sampler, nullptr);
11034 m_errorMonitor->VerifyFound();
11035 vkQueueWaitIdle(m_device->m_queue);
11036 // Now we can actually destroy sampler
11037 vkDestroySampler(m_device->device(), sampler, nullptr);
11038 vkDestroyImageView(m_device->device(), view, NULL);
11039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11040 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11041 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11042}
11043
Mark Mueller1cd9f412016-08-25 13:23:52 -060011044TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011045 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011046 "signaled but not waited on by the queue. Wait on a "
11047 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011048
11049 ASSERT_NO_FATAL_FAILURE(InitState());
11050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011052 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11053 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11054 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011055
11056 BeginCommandBuffer();
11057 EndCommandBuffer();
11058
11059 VkSemaphoreCreateInfo semaphore_create_info = {};
11060 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11061 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011062 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011063 VkSubmitInfo submit_info = {};
11064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11065 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011066 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011067 submit_info.signalSemaphoreCount = 1;
11068 submit_info.pSignalSemaphores = &semaphore;
11069 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11070 m_errorMonitor->SetDesiredFailureMsg(0, "");
11071 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11072 BeginCommandBuffer();
11073 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011075 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11076 m_errorMonitor->VerifyFound();
11077
Mark Mueller1cd9f412016-08-25 13:23:52 -060011078 VkFenceCreateInfo fence_create_info = {};
11079 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11080 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011081 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011084 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11085 m_errorMonitor->VerifyFound();
11086
Mark Mueller4042b652016-09-05 22:52:21 -060011087 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011088 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011089 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11090}
11091
Tobin Ehlis4af23302016-07-19 10:50:30 -060011092TEST_F(VkLayerTest, FramebufferIncompatible) {
11093 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11094 "that does not match the framebuffer for the active "
11095 "renderpass.");
11096 ASSERT_NO_FATAL_FAILURE(InitState());
11097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11098
11099 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 VkAttachmentDescription attachment = {0,
11101 VK_FORMAT_B8G8R8A8_UNORM,
11102 VK_SAMPLE_COUNT_1_BIT,
11103 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11104 VK_ATTACHMENT_STORE_OP_STORE,
11105 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11106 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11107 VK_IMAGE_LAYOUT_UNDEFINED,
11108 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011110 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011112 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011114 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011115
11116 VkRenderPass rp;
11117 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11118 ASSERT_VK_SUCCESS(err);
11119
11120 // A compatible framebuffer.
11121 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011122 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 -060011123 ASSERT_TRUE(image.initialized());
11124
11125 VkImageViewCreateInfo ivci = {
11126 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11127 nullptr,
11128 0,
11129 image.handle(),
11130 VK_IMAGE_VIEW_TYPE_2D,
11131 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011132 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11133 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011134 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11135 };
11136 VkImageView view;
11137 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11138 ASSERT_VK_SUCCESS(err);
11139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011140 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011141 VkFramebuffer fb;
11142 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11143 ASSERT_VK_SUCCESS(err);
11144
11145 VkCommandBufferAllocateInfo cbai = {};
11146 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11147 cbai.commandPool = m_commandPool;
11148 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11149 cbai.commandBufferCount = 1;
11150
11151 VkCommandBuffer sec_cb;
11152 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11153 ASSERT_VK_SUCCESS(err);
11154 VkCommandBufferBeginInfo cbbi = {};
11155 VkCommandBufferInheritanceInfo cbii = {};
11156 cbii.renderPass = renderPass();
11157 cbii.framebuffer = fb;
11158 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11159 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011160 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 -060011161 cbbi.pInheritanceInfo = &cbii;
11162 vkBeginCommandBuffer(sec_cb, &cbbi);
11163 vkEndCommandBuffer(sec_cb);
11164
Chris Forbes3400bc52016-09-13 18:10:34 +120011165 VkCommandBufferBeginInfo cbbi2 = {
11166 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11167 0, nullptr
11168 };
11169 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11170 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011173 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011174 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11175 m_errorMonitor->VerifyFound();
11176 // Cleanup
11177 vkDestroyImageView(m_device->device(), view, NULL);
11178 vkDestroyRenderPass(m_device->device(), rp, NULL);
11179 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11180}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011181
11182TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11183 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11184 "invalid value. If logicOp is not available, attempt to "
11185 "use it and verify that we see the correct error.");
11186 ASSERT_NO_FATAL_FAILURE(InitState());
11187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11188
11189 auto features = m_device->phy().features();
11190 // Set the expected error depending on whether or not logicOp available
11191 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11193 "enabled, logicOpEnable must be "
11194 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011195 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011197 }
11198 // Create a pipeline using logicOp
11199 VkResult err;
11200
11201 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11202 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11203
11204 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011205 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011206 ASSERT_VK_SUCCESS(err);
11207
11208 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11209 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11210 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011212 vp_state_ci.pViewports = &vp;
11213 vp_state_ci.scissorCount = 1;
11214 VkRect2D scissors = {}; // Dummy scissors to point to
11215 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011216
11217 VkPipelineShaderStageCreateInfo shaderStages[2];
11218 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11221 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011222 shaderStages[0] = vs.GetStageCreateInfo();
11223 shaderStages[1] = fs.GetStageCreateInfo();
11224
11225 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11226 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11227
11228 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11229 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11230 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11231
11232 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11233 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011234 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011235
11236 VkPipelineColorBlendAttachmentState att = {};
11237 att.blendEnable = VK_FALSE;
11238 att.colorWriteMask = 0xf;
11239
11240 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11241 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11242 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11243 cb_ci.logicOpEnable = VK_TRUE;
11244 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11245 cb_ci.attachmentCount = 1;
11246 cb_ci.pAttachments = &att;
11247
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011248 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11249 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11250 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11251
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011252 VkGraphicsPipelineCreateInfo gp_ci = {};
11253 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11254 gp_ci.stageCount = 2;
11255 gp_ci.pStages = shaderStages;
11256 gp_ci.pVertexInputState = &vi_ci;
11257 gp_ci.pInputAssemblyState = &ia_ci;
11258 gp_ci.pViewportState = &vp_state_ci;
11259 gp_ci.pRasterizationState = &rs_ci;
11260 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011261 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011262 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11263 gp_ci.layout = pipeline_layout;
11264 gp_ci.renderPass = renderPass();
11265
11266 VkPipelineCacheCreateInfo pc_ci = {};
11267 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11268
11269 VkPipeline pipeline;
11270 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011272 ASSERT_VK_SUCCESS(err);
11273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011274 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011275 m_errorMonitor->VerifyFound();
11276 if (VK_SUCCESS == err) {
11277 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11278 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011279 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11281}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011282#endif // DRAW_STATE_TESTS
11283
Tobin Ehlis0788f522015-05-26 16:11:58 -060011284#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011285#if GTEST_IS_THREADSAFE
11286struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011287 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011288 VkEvent event;
11289 bool bailout;
11290};
11291
Karl Schultz6addd812016-02-02 17:17:23 -070011292extern "C" void *AddToCommandBuffer(void *arg) {
11293 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011294
Mike Stroyana6d14942016-07-13 15:10:05 -060011295 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011297 if (data->bailout) {
11298 break;
11299 }
11300 }
11301 return NULL;
11302}
11303
Karl Schultz6addd812016-02-02 17:17:23 -070011304TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011305 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011308
Mike Stroyanaccf7692015-05-12 16:00:45 -060011309 ASSERT_NO_FATAL_FAILURE(InitState());
11310 ASSERT_NO_FATAL_FAILURE(InitViewport());
11311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11312
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011313 // Calls AllocateCommandBuffers
11314 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011315
11316 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011317 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011318
11319 VkEventCreateInfo event_info;
11320 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011321 VkResult err;
11322
11323 memset(&event_info, 0, sizeof(event_info));
11324 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11325
Chia-I Wuf7458c52015-10-26 21:10:41 +080011326 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011327 ASSERT_VK_SUCCESS(err);
11328
Mike Stroyanaccf7692015-05-12 16:00:45 -060011329 err = vkResetEvent(device(), event);
11330 ASSERT_VK_SUCCESS(err);
11331
11332 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011333 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011334 data.event = event;
11335 data.bailout = false;
11336 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011337
11338 // First do some correct operations using multiple threads.
11339 // Add many entries to command buffer from another thread.
11340 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11341 // Make non-conflicting calls from this thread at the same time.
11342 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011343 uint32_t count;
11344 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011345 }
11346 test_platform_thread_join(thread, NULL);
11347
11348 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011349 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011350 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011351 // Add many entries to command buffer from this thread at the same time.
11352 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011353
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011354 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011355 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011356
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011357 m_errorMonitor->SetBailout(NULL);
11358
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011359 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011360
Chia-I Wuf7458c52015-10-26 21:10:41 +080011361 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011362}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011363#endif // GTEST_IS_THREADSAFE
11364#endif // THREADING_TESTS
11365
Chris Forbes9f7ff632015-05-25 11:13:08 +120011366#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011367TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011368 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11369 "with an impossible code size");
11370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011372
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011373 ASSERT_NO_FATAL_FAILURE(InitState());
11374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11375
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011376 VkShaderModule module;
11377 VkShaderModuleCreateInfo moduleCreateInfo;
11378 struct icd_spv_header spv;
11379
11380 spv.magic = ICD_SPV_MAGIC;
11381 spv.version = ICD_SPV_VERSION;
11382 spv.gen_magic = 0;
11383
11384 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11385 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011386 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011387 moduleCreateInfo.codeSize = 4;
11388 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011389 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011391 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011392}
11393
Karl Schultz6addd812016-02-02 17:17:23 -070011394TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011395 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11396 "with a bad magic number");
11397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011399
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011400 ASSERT_NO_FATAL_FAILURE(InitState());
11401 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11402
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011403 VkShaderModule module;
11404 VkShaderModuleCreateInfo moduleCreateInfo;
11405 struct icd_spv_header spv;
11406
11407 spv.magic = ~ICD_SPV_MAGIC;
11408 spv.version = ICD_SPV_VERSION;
11409 spv.gen_magic = 0;
11410
11411 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11412 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011413 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011414 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11415 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011416 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011417
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011418 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011419}
11420
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011421#if 0
11422// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011423TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011425 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011426
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011427 ASSERT_NO_FATAL_FAILURE(InitState());
11428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11429
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011430 VkShaderModule module;
11431 VkShaderModuleCreateInfo moduleCreateInfo;
11432 struct icd_spv_header spv;
11433
11434 spv.magic = ICD_SPV_MAGIC;
11435 spv.version = ~ICD_SPV_VERSION;
11436 spv.gen_magic = 0;
11437
11438 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11439 moduleCreateInfo.pNext = NULL;
11440
Karl Schultz6addd812016-02-02 17:17:23 -070011441 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011442 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11443 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011444 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011446 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011447}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011448#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011449
Karl Schultz6addd812016-02-02 17:17:23 -070011450TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011451 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11452 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011454
Chris Forbes9f7ff632015-05-25 11:13:08 +120011455 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011458 char const *vsSource = "#version 450\n"
11459 "\n"
11460 "layout(location=0) out float x;\n"
11461 "out gl_PerVertex {\n"
11462 " vec4 gl_Position;\n"
11463 "};\n"
11464 "void main(){\n"
11465 " gl_Position = vec4(1);\n"
11466 " x = 0;\n"
11467 "}\n";
11468 char const *fsSource = "#version 450\n"
11469 "\n"
11470 "layout(location=0) out vec4 color;\n"
11471 "void main(){\n"
11472 " color = vec4(1);\n"
11473 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011474
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011475 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011477
11478 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011479 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011480 pipe.AddShader(&vs);
11481 pipe.AddShader(&fs);
11482
Chris Forbes9f7ff632015-05-25 11:13:08 +120011483 VkDescriptorSetObj descriptorSet(m_device);
11484 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011485 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011486
Tony Barbour5781e8f2015-08-04 16:23:11 -060011487 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011488
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011489 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011490}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011491
Mark Mueller098c9cb2016-09-08 09:01:57 -060011492TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11493 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11494
11495 ASSERT_NO_FATAL_FAILURE(InitState());
11496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11497
11498 const char *bad_specialization_message =
11499 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11500
11501 char const *vsSource =
11502 "#version 450\n"
11503 "\n"
11504 "out gl_PerVertex {\n"
11505 " vec4 gl_Position;\n"
11506 "};\n"
11507 "void main(){\n"
11508 " gl_Position = vec4(1);\n"
11509 "}\n";
11510
11511 char const *fsSource =
11512 "#version 450\n"
11513 "\n"
11514 "layout (constant_id = 0) const float r = 0.0f;\n"
11515 "layout(location = 0) out vec4 uFragColor;\n"
11516 "void main(){\n"
11517 " uFragColor = vec4(r,1,0,1);\n"
11518 "}\n";
11519
11520 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11521 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11522
11523 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11524 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11525
11526 VkPipelineLayout pipeline_layout;
11527 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11528
11529 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11530 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11531 vp_state_create_info.viewportCount = 1;
11532 VkViewport viewport = {};
11533 vp_state_create_info.pViewports = &viewport;
11534 vp_state_create_info.scissorCount = 1;
11535 VkRect2D scissors = {};
11536 vp_state_create_info.pScissors = &scissors;
11537
11538 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11539
11540 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11541 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11542 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11543 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11544
11545 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11546 vs.GetStageCreateInfo(),
11547 fs.GetStageCreateInfo()
11548 };
11549
11550 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11551 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11552
11553 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11554 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11555 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11556
11557 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11558 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11559 rasterization_state_create_info.pNext = nullptr;
11560 rasterization_state_create_info.lineWidth = 1.0f;
11561 rasterization_state_create_info.rasterizerDiscardEnable = true;
11562
11563 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11564 color_blend_attachment_state.blendEnable = VK_FALSE;
11565 color_blend_attachment_state.colorWriteMask = 0xf;
11566
11567 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11568 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11569 color_blend_state_create_info.attachmentCount = 1;
11570 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11571
11572 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11573 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11574 graphicspipe_create_info.stageCount = 2;
11575 graphicspipe_create_info.pStages = shader_stage_create_info;
11576 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11577 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11578 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11579 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11580 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11581 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11582 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11583 graphicspipe_create_info.layout = pipeline_layout;
11584 graphicspipe_create_info.renderPass = renderPass();
11585
11586 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11587 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11588
11589 VkPipelineCache pipelineCache;
11590 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11591
11592 // This structure maps constant ids to data locations.
11593 const VkSpecializationMapEntry entry =
11594 // id, offset, size
11595 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11596
11597 uint32_t data = 1;
11598
11599 // Set up the info describing spec map and data
11600 const VkSpecializationInfo specialization_info = {
11601 1,
11602 &entry,
11603 1 * sizeof(float),
11604 &data,
11605 };
11606 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11607
11608 VkPipeline pipeline;
11609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11610 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11611 m_errorMonitor->VerifyFound();
11612
11613 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11614 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11615}
11616
11617TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11618 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11619
11620 ASSERT_NO_FATAL_FAILURE(InitState());
11621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11622
11623 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11624
11625 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11626 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11627 descriptor_pool_type_count[0].descriptorCount = 1;
11628 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11629 descriptor_pool_type_count[1].descriptorCount = 1;
11630
11631 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11632 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11633 descriptor_pool_create_info.maxSets = 1;
11634 descriptor_pool_create_info.poolSizeCount = 2;
11635 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11636 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11637
11638 VkDescriptorPool descriptorset_pool;
11639 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11640
11641 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11642 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11643 descriptorset_layout_binding.descriptorCount = 1;
11644 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11645
11646 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11647 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11648 descriptorset_layout_create_info.bindingCount = 1;
11649 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11650
11651 VkDescriptorSetLayout descriptorset_layout;
11652 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11653
11654 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11655 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11656 descriptorset_allocate_info.descriptorSetCount = 1;
11657 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11658 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11659 VkDescriptorSet descriptorset;
11660 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11661
11662 // Challenge core_validation with a non uniform buffer type.
11663 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11664
Mark Mueller098c9cb2016-09-08 09:01:57 -060011665 char const *vsSource =
11666 "#version 450\n"
11667 "\n"
11668 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11669 " mat4 mvp;\n"
11670 "} ubuf;\n"
11671 "out gl_PerVertex {\n"
11672 " vec4 gl_Position;\n"
11673 "};\n"
11674 "void main(){\n"
11675 " gl_Position = ubuf.mvp * vec4(1);\n"
11676 "}\n";
11677
11678 char const *fsSource =
11679 "#version 450\n"
11680 "\n"
11681 "layout(location = 0) out vec4 uFragColor;\n"
11682 "void main(){\n"
11683 " uFragColor = vec4(0,1,0,1);\n"
11684 "}\n";
11685
11686 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11688
11689 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11690 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11691 pipeline_layout_create_info.setLayoutCount = 1;
11692 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11693
11694 VkPipelineLayout pipeline_layout;
11695 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11696
11697 VkPipelineObj pipe(m_device);
11698 pipe.AddColorAttachment();
11699 pipe.AddShader(&vs);
11700 pipe.AddShader(&fs);
11701
11702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11703 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11704 m_errorMonitor->VerifyFound();
11705
11706 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11707 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11708 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11709}
11710
11711TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11712 TEST_DESCRIPTION(
11713 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11714
11715 ASSERT_NO_FATAL_FAILURE(InitState());
11716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11717
11718 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11719
11720 VkDescriptorPoolSize descriptor_pool_type_count = {};
11721 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11722 descriptor_pool_type_count.descriptorCount = 1;
11723
11724 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11725 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11726 descriptor_pool_create_info.maxSets = 1;
11727 descriptor_pool_create_info.poolSizeCount = 1;
11728 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11729 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11730
11731 VkDescriptorPool descriptorset_pool;
11732 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11733
11734 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11735 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11736 descriptorset_layout_binding.descriptorCount = 1;
11737 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11738 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11739
11740 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11741 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11742 descriptorset_layout_create_info.bindingCount = 1;
11743 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11744
11745 VkDescriptorSetLayout descriptorset_layout;
11746 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11747 nullptr, &descriptorset_layout));
11748
11749 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11750 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11751 descriptorset_allocate_info.descriptorSetCount = 1;
11752 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11753 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11754 VkDescriptorSet descriptorset;
11755 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11756
11757 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11758
Mark Mueller098c9cb2016-09-08 09:01:57 -060011759 char const *vsSource =
11760 "#version 450\n"
11761 "\n"
11762 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11763 " mat4 mvp;\n"
11764 "} ubuf;\n"
11765 "out gl_PerVertex {\n"
11766 " vec4 gl_Position;\n"
11767 "};\n"
11768 "void main(){\n"
11769 " gl_Position = ubuf.mvp * vec4(1);\n"
11770 "}\n";
11771
11772 char const *fsSource =
11773 "#version 450\n"
11774 "\n"
11775 "layout(location = 0) out vec4 uFragColor;\n"
11776 "void main(){\n"
11777 " uFragColor = vec4(0,1,0,1);\n"
11778 "}\n";
11779
11780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11782
11783 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11784 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11785 pipeline_layout_create_info.setLayoutCount = 1;
11786 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11787
11788 VkPipelineLayout pipeline_layout;
11789 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11790
11791 VkPipelineObj pipe(m_device);
11792 pipe.AddColorAttachment();
11793 pipe.AddShader(&vs);
11794 pipe.AddShader(&fs);
11795
11796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11797 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11798 m_errorMonitor->VerifyFound();
11799
11800 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11801 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11802 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11803}
11804
11805TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11806 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11807 "accessible from the current shader stage.");
11808
11809 ASSERT_NO_FATAL_FAILURE(InitState());
11810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11811
11812 const char *push_constant_not_accessible_message =
11813 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11814
11815 char const *vsSource =
11816 "#version 450\n"
11817 "\n"
11818 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11819 "out gl_PerVertex {\n"
11820 " vec4 gl_Position;\n"
11821 "};\n"
11822 "void main(){\n"
11823 " gl_Position = vec4(consts.x);\n"
11824 "}\n";
11825
11826 char const *fsSource =
11827 "#version 450\n"
11828 "\n"
11829 "layout(location = 0) out vec4 uFragColor;\n"
11830 "void main(){\n"
11831 " uFragColor = vec4(0,1,0,1);\n"
11832 "}\n";
11833
11834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11836
11837 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11838 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11839
11840 // Set up a push constant range
11841 VkPushConstantRange push_constant_ranges = {};
11842 // Set to the wrong stage to challenge core_validation
11843 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11844 push_constant_ranges.size = 4;
11845
11846 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11847 pipeline_layout_create_info.pushConstantRangeCount = 1;
11848
11849 VkPipelineLayout pipeline_layout;
11850 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11851
11852 VkPipelineObj pipe(m_device);
11853 pipe.AddColorAttachment();
11854 pipe.AddShader(&vs);
11855 pipe.AddShader(&fs);
11856
11857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11858 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11859 m_errorMonitor->VerifyFound();
11860
11861 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11862}
11863
11864TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11865 TEST_DESCRIPTION(
11866 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11867
11868 ASSERT_NO_FATAL_FAILURE(InitState());
11869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11870
11871 const char *feature_not_enabled_message =
11872 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
11873
11874 // Some awkward steps are required to test with custom device features.
11875 std::vector<const char *> device_extension_names;
11876 auto features = m_device->phy().features();
11877 // Disable support for 64 bit floats
11878 features.shaderFloat64 = false;
11879 // The sacrificial device object
11880 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11881
11882 char const *vsSource = "#version 450\n"
11883 "\n"
11884 "out gl_PerVertex {\n"
11885 " vec4 gl_Position;\n"
11886 "};\n"
11887 "void main(){\n"
11888 " gl_Position = vec4(1);\n"
11889 "}\n";
11890 char const *fsSource = "#version 450\n"
11891 "\n"
11892 "layout(location=0) out vec4 color;\n"
11893 "void main(){\n"
11894 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
11895 " color = vec4(green);\n"
11896 "}\n";
11897
11898 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11899 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11900
11901 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060011902
11903 VkPipelineObj pipe(&test_device);
11904 pipe.AddColorAttachment();
11905 pipe.AddShader(&vs);
11906 pipe.AddShader(&fs);
11907
11908 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11909 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11910 VkPipelineLayout pipeline_layout;
11911 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11912
11913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
11914 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
11915 m_errorMonitor->VerifyFound();
11916
11917 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
11918}
11919
11920TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
11921 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
11922
11923 ASSERT_NO_FATAL_FAILURE(InitState());
11924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11925
11926 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
11927
11928 char const *vsSource = "#version 450\n"
11929 "\n"
11930 "out gl_PerVertex {\n"
11931 " vec4 gl_Position;\n"
11932 "};\n"
11933 "layout(xfb_buffer = 1) out;"
11934 "void main(){\n"
11935 " gl_Position = vec4(1);\n"
11936 "}\n";
11937 char const *fsSource = "#version 450\n"
11938 "\n"
11939 "layout(location=0) out vec4 color;\n"
11940 "void main(){\n"
11941 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
11942 " color = vec4(green);\n"
11943 "}\n";
11944
11945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11947
11948 VkPipelineObj pipe(m_device);
11949 pipe.AddColorAttachment();
11950 pipe.AddShader(&vs);
11951 pipe.AddShader(&fs);
11952
11953 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11954 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11955 VkPipelineLayout pipeline_layout;
11956 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11957
11958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
11959 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11960 m_errorMonitor->VerifyFound();
11961
11962 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11963}
11964
Karl Schultz6addd812016-02-02 17:17:23 -070011965TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011966 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
11967 "which is not present in the outputs of the previous stage");
11968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011970
Chris Forbes59cb88d2015-05-25 11:13:13 +120011971 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120011973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 char const *vsSource = "#version 450\n"
11975 "\n"
11976 "out gl_PerVertex {\n"
11977 " vec4 gl_Position;\n"
11978 "};\n"
11979 "void main(){\n"
11980 " gl_Position = vec4(1);\n"
11981 "}\n";
11982 char const *fsSource = "#version 450\n"
11983 "\n"
11984 "layout(location=0) in float x;\n"
11985 "layout(location=0) out vec4 color;\n"
11986 "void main(){\n"
11987 " color = vec4(x);\n"
11988 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120011989
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011990 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11991 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120011992
11993 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011994 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120011995 pipe.AddShader(&vs);
11996 pipe.AddShader(&fs);
11997
Chris Forbes59cb88d2015-05-25 11:13:13 +120011998 VkDescriptorSetObj descriptorSet(m_device);
11999 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012000 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012001
Tony Barbour5781e8f2015-08-04 16:23:11 -060012002 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012003
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012004 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012005}
12006
Karl Schultz6addd812016-02-02 17:17:23 -070012007TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012008 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12009 "within an interace block, which is not present in the outputs "
12010 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012012
12013 ASSERT_NO_FATAL_FAILURE(InitState());
12014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012016 char const *vsSource = "#version 450\n"
12017 "\n"
12018 "out gl_PerVertex {\n"
12019 " vec4 gl_Position;\n"
12020 "};\n"
12021 "void main(){\n"
12022 " gl_Position = vec4(1);\n"
12023 "}\n";
12024 char const *fsSource = "#version 450\n"
12025 "\n"
12026 "in block { layout(location=0) float x; } ins;\n"
12027 "layout(location=0) out vec4 color;\n"
12028 "void main(){\n"
12029 " color = vec4(ins.x);\n"
12030 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012031
12032 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12033 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12034
12035 VkPipelineObj pipe(m_device);
12036 pipe.AddColorAttachment();
12037 pipe.AddShader(&vs);
12038 pipe.AddShader(&fs);
12039
12040 VkDescriptorSetObj descriptorSet(m_device);
12041 descriptorSet.AppendDummy();
12042 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12043
12044 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12045
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012046 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012047}
12048
Karl Schultz6addd812016-02-02 17:17:23 -070012049TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012050 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012051 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12053 "output arr[2] of float32' vs 'ptr to "
12054 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012055
12056 ASSERT_NO_FATAL_FAILURE(InitState());
12057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012059 char const *vsSource = "#version 450\n"
12060 "\n"
12061 "layout(location=0) out float x[2];\n"
12062 "out gl_PerVertex {\n"
12063 " vec4 gl_Position;\n"
12064 "};\n"
12065 "void main(){\n"
12066 " x[0] = 0; x[1] = 0;\n"
12067 " gl_Position = vec4(1);\n"
12068 "}\n";
12069 char const *fsSource = "#version 450\n"
12070 "\n"
12071 "layout(location=0) in float x[3];\n"
12072 "layout(location=0) out vec4 color;\n"
12073 "void main(){\n"
12074 " color = vec4(x[0] + x[1] + x[2]);\n"
12075 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012076
12077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12079
12080 VkPipelineObj pipe(m_device);
12081 pipe.AddColorAttachment();
12082 pipe.AddShader(&vs);
12083 pipe.AddShader(&fs);
12084
12085 VkDescriptorSetObj descriptorSet(m_device);
12086 descriptorSet.AppendDummy();
12087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12088
12089 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12090
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012091 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012092}
12093
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012094
Karl Schultz6addd812016-02-02 17:17:23 -070012095TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012096 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012097 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012099
Chris Forbesb56af562015-05-25 11:13:17 +120012100 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012103 char const *vsSource = "#version 450\n"
12104 "\n"
12105 "layout(location=0) out int x;\n"
12106 "out gl_PerVertex {\n"
12107 " vec4 gl_Position;\n"
12108 "};\n"
12109 "void main(){\n"
12110 " x = 0;\n"
12111 " gl_Position = vec4(1);\n"
12112 "}\n";
12113 char const *fsSource = "#version 450\n"
12114 "\n"
12115 "layout(location=0) in float x;\n" /* VS writes int */
12116 "layout(location=0) out vec4 color;\n"
12117 "void main(){\n"
12118 " color = vec4(x);\n"
12119 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012120
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012123
12124 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012125 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012126 pipe.AddShader(&vs);
12127 pipe.AddShader(&fs);
12128
Chris Forbesb56af562015-05-25 11:13:17 +120012129 VkDescriptorSetObj descriptorSet(m_device);
12130 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012132
Tony Barbour5781e8f2015-08-04 16:23:11 -060012133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012135 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012136}
12137
Karl Schultz6addd812016-02-02 17:17:23 -070012138TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012139 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012140 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012141 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012143
12144 ASSERT_NO_FATAL_FAILURE(InitState());
12145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012147 char const *vsSource = "#version 450\n"
12148 "\n"
12149 "out block { layout(location=0) int x; } outs;\n"
12150 "out gl_PerVertex {\n"
12151 " vec4 gl_Position;\n"
12152 "};\n"
12153 "void main(){\n"
12154 " outs.x = 0;\n"
12155 " gl_Position = vec4(1);\n"
12156 "}\n";
12157 char const *fsSource = "#version 450\n"
12158 "\n"
12159 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12160 "layout(location=0) out vec4 color;\n"
12161 "void main(){\n"
12162 " color = vec4(ins.x);\n"
12163 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012164
12165 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12166 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12167
12168 VkPipelineObj pipe(m_device);
12169 pipe.AddColorAttachment();
12170 pipe.AddShader(&vs);
12171 pipe.AddShader(&fs);
12172
12173 VkDescriptorSetObj descriptorSet(m_device);
12174 descriptorSet.AppendDummy();
12175 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12176
12177 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12178
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012179 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012180}
12181
12182TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012183 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012184 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012185 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012186 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 +130012187
12188 ASSERT_NO_FATAL_FAILURE(InitState());
12189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 char const *vsSource = "#version 450\n"
12192 "\n"
12193 "out block { layout(location=1) float x; } outs;\n"
12194 "out gl_PerVertex {\n"
12195 " vec4 gl_Position;\n"
12196 "};\n"
12197 "void main(){\n"
12198 " outs.x = 0;\n"
12199 " gl_Position = vec4(1);\n"
12200 "}\n";
12201 char const *fsSource = "#version 450\n"
12202 "\n"
12203 "in block { layout(location=0) float x; } ins;\n"
12204 "layout(location=0) out vec4 color;\n"
12205 "void main(){\n"
12206 " color = vec4(ins.x);\n"
12207 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012208
12209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12211
12212 VkPipelineObj pipe(m_device);
12213 pipe.AddColorAttachment();
12214 pipe.AddShader(&vs);
12215 pipe.AddShader(&fs);
12216
12217 VkDescriptorSetObj descriptorSet(m_device);
12218 descriptorSet.AppendDummy();
12219 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12220
12221 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12222
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012223 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012224}
12225
12226TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012227 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012228 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012229 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012230 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 +130012231
12232 ASSERT_NO_FATAL_FAILURE(InitState());
12233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012235 char const *vsSource = "#version 450\n"
12236 "\n"
12237 "out block { layout(location=0, component=0) float x; } outs;\n"
12238 "out gl_PerVertex {\n"
12239 " vec4 gl_Position;\n"
12240 "};\n"
12241 "void main(){\n"
12242 " outs.x = 0;\n"
12243 " gl_Position = vec4(1);\n"
12244 "}\n";
12245 char const *fsSource = "#version 450\n"
12246 "\n"
12247 "in block { layout(location=0, component=1) float x; } ins;\n"
12248 "layout(location=0) out vec4 color;\n"
12249 "void main(){\n"
12250 " color = vec4(ins.x);\n"
12251 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012252
12253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12255
12256 VkPipelineObj pipe(m_device);
12257 pipe.AddColorAttachment();
12258 pipe.AddShader(&vs);
12259 pipe.AddShader(&fs);
12260
12261 VkDescriptorSetObj descriptorSet(m_device);
12262 descriptorSet.AppendDummy();
12263 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12264
12265 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12266
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012267 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012268}
12269
Karl Schultz6addd812016-02-02 17:17:23 -070012270TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012271 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12272 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012274
Chris Forbesde136e02015-05-25 11:13:28 +120012275 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012277
12278 VkVertexInputBindingDescription input_binding;
12279 memset(&input_binding, 0, sizeof(input_binding));
12280
12281 VkVertexInputAttributeDescription input_attrib;
12282 memset(&input_attrib, 0, sizeof(input_attrib));
12283 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012285 char const *vsSource = "#version 450\n"
12286 "\n"
12287 "out gl_PerVertex {\n"
12288 " vec4 gl_Position;\n"
12289 "};\n"
12290 "void main(){\n"
12291 " gl_Position = vec4(1);\n"
12292 "}\n";
12293 char const *fsSource = "#version 450\n"
12294 "\n"
12295 "layout(location=0) out vec4 color;\n"
12296 "void main(){\n"
12297 " color = vec4(1);\n"
12298 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012299
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012300 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12301 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012302
12303 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012304 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012305 pipe.AddShader(&vs);
12306 pipe.AddShader(&fs);
12307
12308 pipe.AddVertexInputBindings(&input_binding, 1);
12309 pipe.AddVertexInputAttribs(&input_attrib, 1);
12310
Chris Forbesde136e02015-05-25 11:13:28 +120012311 VkDescriptorSetObj descriptorSet(m_device);
12312 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012313 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012314
Tony Barbour5781e8f2015-08-04 16:23:11 -060012315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012317 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012318}
12319
Karl Schultz6addd812016-02-02 17:17:23 -070012320TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012321 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12322 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012324
12325 ASSERT_NO_FATAL_FAILURE(InitState());
12326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12327
12328 VkVertexInputBindingDescription input_binding;
12329 memset(&input_binding, 0, sizeof(input_binding));
12330
12331 VkVertexInputAttributeDescription input_attrib;
12332 memset(&input_attrib, 0, sizeof(input_attrib));
12333 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012335 char const *vsSource = "#version 450\n"
12336 "\n"
12337 "layout(location=1) in float x;\n"
12338 "out gl_PerVertex {\n"
12339 " vec4 gl_Position;\n"
12340 "};\n"
12341 "void main(){\n"
12342 " gl_Position = vec4(x);\n"
12343 "}\n";
12344 char const *fsSource = "#version 450\n"
12345 "\n"
12346 "layout(location=0) out vec4 color;\n"
12347 "void main(){\n"
12348 " color = vec4(1);\n"
12349 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012350
12351 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12352 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12353
12354 VkPipelineObj pipe(m_device);
12355 pipe.AddColorAttachment();
12356 pipe.AddShader(&vs);
12357 pipe.AddShader(&fs);
12358
12359 pipe.AddVertexInputBindings(&input_binding, 1);
12360 pipe.AddVertexInputAttribs(&input_attrib, 1);
12361
12362 VkDescriptorSetObj descriptorSet(m_device);
12363 descriptorSet.AppendDummy();
12364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12365
12366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012368 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012369}
12370
Karl Schultz6addd812016-02-02 17:17:23 -070012371TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012372 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012373 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012375
Chris Forbes62e8e502015-05-25 11:13:29 +120012376 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012379 char const *vsSource = "#version 450\n"
12380 "\n"
12381 "layout(location=0) in vec4 x;\n" /* not provided */
12382 "out gl_PerVertex {\n"
12383 " vec4 gl_Position;\n"
12384 "};\n"
12385 "void main(){\n"
12386 " gl_Position = x;\n"
12387 "}\n";
12388 char const *fsSource = "#version 450\n"
12389 "\n"
12390 "layout(location=0) out vec4 color;\n"
12391 "void main(){\n"
12392 " color = vec4(1);\n"
12393 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012394
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012395 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12396 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012397
12398 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012399 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012400 pipe.AddShader(&vs);
12401 pipe.AddShader(&fs);
12402
Chris Forbes62e8e502015-05-25 11:13:29 +120012403 VkDescriptorSetObj descriptorSet(m_device);
12404 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012405 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012406
Tony Barbour5781e8f2015-08-04 16:23:11 -060012407 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012408
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012409 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012410}
12411
Karl Schultz6addd812016-02-02 17:17:23 -070012412TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012413 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12414 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012415 "vertex shader input that consumes it");
12416 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 -060012417
Chris Forbesc97d98e2015-05-25 11:13:31 +120012418 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012420
12421 VkVertexInputBindingDescription input_binding;
12422 memset(&input_binding, 0, sizeof(input_binding));
12423
12424 VkVertexInputAttributeDescription input_attrib;
12425 memset(&input_attrib, 0, sizeof(input_attrib));
12426 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012428 char const *vsSource = "#version 450\n"
12429 "\n"
12430 "layout(location=0) in int x;\n" /* attrib provided float */
12431 "out gl_PerVertex {\n"
12432 " vec4 gl_Position;\n"
12433 "};\n"
12434 "void main(){\n"
12435 " gl_Position = vec4(x);\n"
12436 "}\n";
12437 char const *fsSource = "#version 450\n"
12438 "\n"
12439 "layout(location=0) out vec4 color;\n"
12440 "void main(){\n"
12441 " color = vec4(1);\n"
12442 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012443
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012444 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12445 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012446
12447 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012448 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012449 pipe.AddShader(&vs);
12450 pipe.AddShader(&fs);
12451
12452 pipe.AddVertexInputBindings(&input_binding, 1);
12453 pipe.AddVertexInputAttribs(&input_attrib, 1);
12454
Chris Forbesc97d98e2015-05-25 11:13:31 +120012455 VkDescriptorSetObj descriptorSet(m_device);
12456 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012457 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012458
Tony Barbour5781e8f2015-08-04 16:23:11 -060012459 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012460
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012461 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012462}
12463
Chris Forbesc68b43c2016-04-06 11:18:47 +120012464TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012465 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12466 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12468 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012469
12470 ASSERT_NO_FATAL_FAILURE(InitState());
12471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12472
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012473 char const *vsSource = "#version 450\n"
12474 "\n"
12475 "out gl_PerVertex {\n"
12476 " vec4 gl_Position;\n"
12477 "};\n"
12478 "void main(){\n"
12479 " gl_Position = vec4(1);\n"
12480 "}\n";
12481 char const *fsSource = "#version 450\n"
12482 "\n"
12483 "layout(location=0) out vec4 color;\n"
12484 "void main(){\n"
12485 " color = vec4(1);\n"
12486 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012487
12488 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12489 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12490
12491 VkPipelineObj pipe(m_device);
12492 pipe.AddColorAttachment();
12493 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012494 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012495 pipe.AddShader(&fs);
12496
12497 VkDescriptorSetObj descriptorSet(m_device);
12498 descriptorSet.AppendDummy();
12499 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12500
12501 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12502
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012503 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012504}
12505
Chris Forbes82ff92a2016-09-09 10:50:24 +120012506TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12508 "No entrypoint found named `foo`");
12509
12510 ASSERT_NO_FATAL_FAILURE(InitState());
12511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12512
12513 char const *vsSource = "#version 450\n"
12514 "out gl_PerVertex {\n"
12515 " vec4 gl_Position;\n"
12516 "};\n"
12517 "void main(){\n"
12518 " gl_Position = vec4(0);\n"
12519 "}\n";
12520 char const *fsSource = "#version 450\n"
12521 "\n"
12522 "layout(location=0) out vec4 color;\n"
12523 "void main(){\n"
12524 " color = vec4(1);\n"
12525 "}\n";
12526
12527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12529
12530 VkPipelineObj pipe(m_device);
12531 pipe.AddColorAttachment();
12532 pipe.AddShader(&vs);
12533 pipe.AddShader(&fs);
12534
12535 VkDescriptorSetObj descriptorSet(m_device);
12536 descriptorSet.AppendDummy();
12537 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12538
12539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12540
12541 m_errorMonitor->VerifyFound();
12542}
12543
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012544TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12545 m_errorMonitor->SetDesiredFailureMsg(
12546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12547 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12548 "uses a depth/stencil attachment");
12549
12550 ASSERT_NO_FATAL_FAILURE(InitState());
12551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12552
12553 char const *vsSource = "#version 450\n"
12554 "void main(){ gl_Position = vec4(0); }\n";
12555 char const *fsSource = "#version 450\n"
12556 "\n"
12557 "layout(location=0) out vec4 color;\n"
12558 "void main(){\n"
12559 " color = vec4(1);\n"
12560 "}\n";
12561
12562 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12563 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12564
12565 VkPipelineObj pipe(m_device);
12566 pipe.AddColorAttachment();
12567 pipe.AddShader(&vs);
12568 pipe.AddShader(&fs);
12569
12570 VkDescriptorSetObj descriptorSet(m_device);
12571 descriptorSet.AppendDummy();
12572 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12573
12574 VkAttachmentDescription attachments[] = {
12575 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12576 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12577 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12578 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12579 },
12580 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12581 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12582 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12583 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12584 },
12585 };
12586 VkAttachmentReference refs[] = {
12587 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12588 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12589 };
12590 VkSubpassDescription subpass = {
12591 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12592 1, &refs[0], nullptr, &refs[1],
12593 0, nullptr
12594 };
12595 VkRenderPassCreateInfo rpci = {
12596 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12597 0, 2, attachments, 1, &subpass, 0, nullptr
12598 };
12599 VkRenderPass rp;
12600 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12601 ASSERT_VK_SUCCESS(err);
12602
12603 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12604
12605 m_errorMonitor->VerifyFound();
12606
12607 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12608}
12609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012610TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012611 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12612 "the TCS without the patch decoration, but consumed in the TES "
12613 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12615 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012616
12617 ASSERT_NO_FATAL_FAILURE(InitState());
12618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12619
Chris Forbesc1e852d2016-04-04 19:26:42 +120012620 if (!m_device->phy().features().tessellationShader) {
12621 printf("Device does not support tessellation shaders; skipped.\n");
12622 return;
12623 }
12624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012625 char const *vsSource = "#version 450\n"
12626 "void main(){}\n";
12627 char const *tcsSource = "#version 450\n"
12628 "layout(location=0) out int x[];\n"
12629 "layout(vertices=3) out;\n"
12630 "void main(){\n"
12631 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12632 " gl_TessLevelInner[0] = 1;\n"
12633 " x[gl_InvocationID] = gl_InvocationID;\n"
12634 "}\n";
12635 char const *tesSource = "#version 450\n"
12636 "layout(triangles, equal_spacing, cw) in;\n"
12637 "layout(location=0) patch in int x;\n"
12638 "out gl_PerVertex { vec4 gl_Position; };\n"
12639 "void main(){\n"
12640 " gl_Position.xyz = gl_TessCoord;\n"
12641 " gl_Position.w = x;\n"
12642 "}\n";
12643 char const *fsSource = "#version 450\n"
12644 "layout(location=0) out vec4 color;\n"
12645 "void main(){\n"
12646 " color = vec4(1);\n"
12647 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012648
12649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12650 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12651 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012654 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12655 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012657 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012658
12659 VkPipelineObj pipe(m_device);
12660 pipe.SetInputAssembly(&iasci);
12661 pipe.SetTessellation(&tsci);
12662 pipe.AddColorAttachment();
12663 pipe.AddShader(&vs);
12664 pipe.AddShader(&tcs);
12665 pipe.AddShader(&tes);
12666 pipe.AddShader(&fs);
12667
12668 VkDescriptorSetObj descriptorSet(m_device);
12669 descriptorSet.AppendDummy();
12670 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12671
12672 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12673
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012674 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012675}
12676
Karl Schultz6addd812016-02-02 17:17:23 -070012677TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012678 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12679 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12681 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012682
Chris Forbes280ba2c2015-06-12 11:16:41 +120012683 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012685
12686 /* Two binding descriptions for binding 0 */
12687 VkVertexInputBindingDescription input_bindings[2];
12688 memset(input_bindings, 0, sizeof(input_bindings));
12689
12690 VkVertexInputAttributeDescription input_attrib;
12691 memset(&input_attrib, 0, sizeof(input_attrib));
12692 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012694 char const *vsSource = "#version 450\n"
12695 "\n"
12696 "layout(location=0) in float x;\n" /* attrib provided float */
12697 "out gl_PerVertex {\n"
12698 " vec4 gl_Position;\n"
12699 "};\n"
12700 "void main(){\n"
12701 " gl_Position = vec4(x);\n"
12702 "}\n";
12703 char const *fsSource = "#version 450\n"
12704 "\n"
12705 "layout(location=0) out vec4 color;\n"
12706 "void main(){\n"
12707 " color = vec4(1);\n"
12708 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012709
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012710 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12711 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012712
12713 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012714 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012715 pipe.AddShader(&vs);
12716 pipe.AddShader(&fs);
12717
12718 pipe.AddVertexInputBindings(input_bindings, 2);
12719 pipe.AddVertexInputAttribs(&input_attrib, 1);
12720
Chris Forbes280ba2c2015-06-12 11:16:41 +120012721 VkDescriptorSetObj descriptorSet(m_device);
12722 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012723 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012724
Tony Barbour5781e8f2015-08-04 16:23:11 -060012725 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012726
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012727 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012728}
Chris Forbes8f68b562015-05-25 11:13:32 +120012729
Karl Schultz6addd812016-02-02 17:17:23 -070012730TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012731 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012732 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012734
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012735 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012737 char const *vsSource = "#version 450\n"
12738 "\n"
12739 "out gl_PerVertex {\n"
12740 " vec4 gl_Position;\n"
12741 "};\n"
12742 "void main(){\n"
12743 " gl_Position = vec4(1);\n"
12744 "}\n";
12745 char const *fsSource = "#version 450\n"
12746 "\n"
12747 "void main(){\n"
12748 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012749
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012750 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12751 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012752
12753 VkPipelineObj pipe(m_device);
12754 pipe.AddShader(&vs);
12755 pipe.AddShader(&fs);
12756
Chia-I Wu08accc62015-07-07 11:50:03 +080012757 /* set up CB 0, not written */
12758 pipe.AddColorAttachment();
12759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012760
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012761 VkDescriptorSetObj descriptorSet(m_device);
12762 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012763 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012764
Tony Barbour5781e8f2015-08-04 16:23:11 -060012765 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012766
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012767 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012768}
12769
Karl Schultz6addd812016-02-02 17:17:23 -070012770TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012771 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012772 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012774 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012775
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012776 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012778 char const *vsSource = "#version 450\n"
12779 "\n"
12780 "out gl_PerVertex {\n"
12781 " vec4 gl_Position;\n"
12782 "};\n"
12783 "void main(){\n"
12784 " gl_Position = vec4(1);\n"
12785 "}\n";
12786 char const *fsSource = "#version 450\n"
12787 "\n"
12788 "layout(location=0) out vec4 x;\n"
12789 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12790 "void main(){\n"
12791 " x = vec4(1);\n"
12792 " y = vec4(1);\n"
12793 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012794
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012795 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12796 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012797
12798 VkPipelineObj pipe(m_device);
12799 pipe.AddShader(&vs);
12800 pipe.AddShader(&fs);
12801
Chia-I Wu08accc62015-07-07 11:50:03 +080012802 /* set up CB 0, not written */
12803 pipe.AddColorAttachment();
12804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012805 /* FS writes CB 1, but we don't configure it */
12806
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012807 VkDescriptorSetObj descriptorSet(m_device);
12808 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012809 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012810
Tony Barbour5781e8f2015-08-04 16:23:11 -060012811 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012812
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012813 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012814}
12815
Karl Schultz6addd812016-02-02 17:17:23 -070012816TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012817 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012818 "type of an fragment shader output variable, and the format of the corresponding attachment");
12819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012820
Chris Forbesa36d69e2015-05-25 11:13:44 +120012821 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 char const *vsSource = "#version 450\n"
12824 "\n"
12825 "out gl_PerVertex {\n"
12826 " vec4 gl_Position;\n"
12827 "};\n"
12828 "void main(){\n"
12829 " gl_Position = vec4(1);\n"
12830 "}\n";
12831 char const *fsSource = "#version 450\n"
12832 "\n"
12833 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12834 "void main(){\n"
12835 " x = ivec4(1);\n"
12836 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012837
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012840
12841 VkPipelineObj pipe(m_device);
12842 pipe.AddShader(&vs);
12843 pipe.AddShader(&fs);
12844
Chia-I Wu08accc62015-07-07 11:50:03 +080012845 /* set up CB 0; type is UNORM by default */
12846 pipe.AddColorAttachment();
12847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012848
Chris Forbesa36d69e2015-05-25 11:13:44 +120012849 VkDescriptorSetObj descriptorSet(m_device);
12850 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012852
Tony Barbour5781e8f2015-08-04 16:23:11 -060012853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012855 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012856}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012857
Karl Schultz6addd812016-02-02 17:17:23 -070012858TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012859 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12860 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012862
Chris Forbes556c76c2015-08-14 12:04:59 +120012863 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 char const *vsSource = "#version 450\n"
12866 "\n"
12867 "out gl_PerVertex {\n"
12868 " vec4 gl_Position;\n"
12869 "};\n"
12870 "void main(){\n"
12871 " gl_Position = vec4(1);\n"
12872 "}\n";
12873 char const *fsSource = "#version 450\n"
12874 "\n"
12875 "layout(location=0) out vec4 x;\n"
12876 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
12877 "void main(){\n"
12878 " x = vec4(bar.y);\n"
12879 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120012880
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012881 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120012883
Chris Forbes556c76c2015-08-14 12:04:59 +120012884 VkPipelineObj pipe(m_device);
12885 pipe.AddShader(&vs);
12886 pipe.AddShader(&fs);
12887
12888 /* set up CB 0; type is UNORM by default */
12889 pipe.AddColorAttachment();
12890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12891
12892 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012893 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120012894
12895 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12896
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012897 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120012898}
12899
Chris Forbes5c59e902016-02-26 16:56:09 +130012900TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012901 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
12902 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130012904
12905 ASSERT_NO_FATAL_FAILURE(InitState());
12906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012907 char const *vsSource = "#version 450\n"
12908 "\n"
12909 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12910 "out gl_PerVertex {\n"
12911 " vec4 gl_Position;\n"
12912 "};\n"
12913 "void main(){\n"
12914 " gl_Position = vec4(consts.x);\n"
12915 "}\n";
12916 char const *fsSource = "#version 450\n"
12917 "\n"
12918 "layout(location=0) out vec4 x;\n"
12919 "void main(){\n"
12920 " x = vec4(1);\n"
12921 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130012922
12923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12925
12926 VkPipelineObj pipe(m_device);
12927 pipe.AddShader(&vs);
12928 pipe.AddShader(&fs);
12929
12930 /* set up CB 0; type is UNORM by default */
12931 pipe.AddColorAttachment();
12932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12933
12934 VkDescriptorSetObj descriptorSet(m_device);
12935 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12936
12937 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12938
12939 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012940 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130012941}
12942
Chris Forbes3fb17902016-08-22 14:57:55 +120012943TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
12944 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
12945 "which is not included in the subpass description");
12946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12947 "consumes input attachment index 0 but not provided in subpass");
12948
12949 ASSERT_NO_FATAL_FAILURE(InitState());
12950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 char const *vsSource = "#version 450\n"
12952 "\n"
12953 "out gl_PerVertex {\n"
12954 " vec4 gl_Position;\n"
12955 "};\n"
12956 "void main(){\n"
12957 " gl_Position = vec4(1);\n"
12958 "}\n";
12959 char const *fsSource = "#version 450\n"
12960 "\n"
12961 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
12962 "layout(location=0) out vec4 color;\n"
12963 "void main() {\n"
12964 " color = subpassLoad(x);\n"
12965 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120012966
12967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12969
12970 VkPipelineObj pipe(m_device);
12971 pipe.AddShader(&vs);
12972 pipe.AddShader(&fs);
12973 pipe.AddColorAttachment();
12974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012976 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
12977 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120012978 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012979 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120012980 ASSERT_VK_SUCCESS(err);
12981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012982 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120012983 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012984 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120012985 ASSERT_VK_SUCCESS(err);
12986
12987 // error here.
12988 pipe.CreateVKPipeline(pl, renderPass());
12989
12990 m_errorMonitor->VerifyFound();
12991
12992 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
12993 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
12994}
12995
Chris Forbes5a9a0472016-08-22 16:02:09 +120012996TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
12997 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
12998 "with a format having a different fundamental type");
12999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13000 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13001
13002 ASSERT_NO_FATAL_FAILURE(InitState());
13003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013004 char const *vsSource = "#version 450\n"
13005 "\n"
13006 "out gl_PerVertex {\n"
13007 " vec4 gl_Position;\n"
13008 "};\n"
13009 "void main(){\n"
13010 " gl_Position = vec4(1);\n"
13011 "}\n";
13012 char const *fsSource = "#version 450\n"
13013 "\n"
13014 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13015 "layout(location=0) out vec4 color;\n"
13016 "void main() {\n"
13017 " color = subpassLoad(x);\n"
13018 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013019
13020 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13021 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13022
13023 VkPipelineObj pipe(m_device);
13024 pipe.AddShader(&vs);
13025 pipe.AddShader(&fs);
13026 pipe.AddColorAttachment();
13027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013029 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13030 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013031 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013032 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013033 ASSERT_VK_SUCCESS(err);
13034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013035 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013036 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013037 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013038 ASSERT_VK_SUCCESS(err);
13039
13040 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013041 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13042 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13043 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13044 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13045 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 +120013046 };
13047 VkAttachmentReference color = {
13048 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13049 };
13050 VkAttachmentReference input = {
13051 1, VK_IMAGE_LAYOUT_GENERAL,
13052 };
13053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013054 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013056 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013057 VkRenderPass rp;
13058 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13059 ASSERT_VK_SUCCESS(err);
13060
13061 // error here.
13062 pipe.CreateVKPipeline(pl, rp);
13063
13064 m_errorMonitor->VerifyFound();
13065
13066 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13067 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13068 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13069}
13070
Chris Forbes541f7b02016-08-22 15:30:27 +120013071TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13072 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13073 "which is not included in the subpass description -- array case");
13074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13075 "consumes input attachment index 1 but not provided in subpass");
13076
13077 ASSERT_NO_FATAL_FAILURE(InitState());
13078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013079 char const *vsSource = "#version 450\n"
13080 "\n"
13081 "out gl_PerVertex {\n"
13082 " vec4 gl_Position;\n"
13083 "};\n"
13084 "void main(){\n"
13085 " gl_Position = vec4(1);\n"
13086 "}\n";
13087 char const *fsSource = "#version 450\n"
13088 "\n"
13089 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13090 "layout(location=0) out vec4 color;\n"
13091 "void main() {\n"
13092 " color = subpassLoad(xs[1]);\n"
13093 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013094
13095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13097
13098 VkPipelineObj pipe(m_device);
13099 pipe.AddShader(&vs);
13100 pipe.AddShader(&fs);
13101 pipe.AddColorAttachment();
13102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013104 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13105 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013106 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013107 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013108 ASSERT_VK_SUCCESS(err);
13109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013110 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013111 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013112 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013113 ASSERT_VK_SUCCESS(err);
13114
13115 // error here.
13116 pipe.CreateVKPipeline(pl, renderPass());
13117
13118 m_errorMonitor->VerifyFound();
13119
13120 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13121 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13122}
13123
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013124TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013125 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13126 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013128
13129 ASSERT_NO_FATAL_FAILURE(InitState());
13130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013131 char const *csSource = "#version 450\n"
13132 "\n"
13133 "layout(local_size_x=1) in;\n"
13134 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13135 "void main(){\n"
13136 " x = vec4(1);\n"
13137 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013138
13139 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13140
13141 VkDescriptorSetObj descriptorSet(m_device);
13142 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013144 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13145 nullptr,
13146 0,
13147 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13148 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13149 descriptorSet.GetPipelineLayout(),
13150 VK_NULL_HANDLE,
13151 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013152
13153 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013154 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013155
13156 m_errorMonitor->VerifyFound();
13157
13158 if (err == VK_SUCCESS) {
13159 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13160 }
13161}
13162
Chris Forbes22a9b092016-07-19 14:34:05 +120013163TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013164 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13165 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13167 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013168
13169 ASSERT_NO_FATAL_FAILURE(InitState());
13170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013171 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13172 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013173 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013174 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013175 ASSERT_VK_SUCCESS(err);
13176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013177 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013178 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013180 ASSERT_VK_SUCCESS(err);
13181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013182 char const *csSource = "#version 450\n"
13183 "\n"
13184 "layout(local_size_x=1) in;\n"
13185 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13186 "void main() {\n"
13187 " x.x = 1.0f;\n"
13188 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013189 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013191 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13192 nullptr,
13193 0,
13194 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13195 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13196 pl,
13197 VK_NULL_HANDLE,
13198 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013199
13200 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013201 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013202
13203 m_errorMonitor->VerifyFound();
13204
13205 if (err == VK_SUCCESS) {
13206 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13207 }
13208
13209 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13210 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13211}
13212
Chris Forbes50020592016-07-27 13:52:41 +120013213TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13214 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13215 "does not match the dimensionality declared in the shader");
13216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013217 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 +120013218
13219 ASSERT_NO_FATAL_FAILURE(InitState());
13220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013222 char const *vsSource = "#version 450\n"
13223 "\n"
13224 "out gl_PerVertex { vec4 gl_Position; };\n"
13225 "void main() { gl_Position = vec4(0); }\n";
13226 char const *fsSource = "#version 450\n"
13227 "\n"
13228 "layout(set=0, binding=0) uniform sampler3D s;\n"
13229 "layout(location=0) out vec4 color;\n"
13230 "void main() {\n"
13231 " color = texture(s, vec3(0));\n"
13232 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013233 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13234 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13235
13236 VkPipelineObj pipe(m_device);
13237 pipe.AddShader(&vs);
13238 pipe.AddShader(&fs);
13239 pipe.AddColorAttachment();
13240
13241 VkTextureObj texture(m_device, nullptr);
13242 VkSamplerObj sampler(m_device);
13243
13244 VkDescriptorSetObj descriptorSet(m_device);
13245 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13246 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13247
13248 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13249 ASSERT_VK_SUCCESS(err);
13250
13251 BeginCommandBuffer();
13252
13253 m_commandBuffer->BindPipeline(pipe);
13254 m_commandBuffer->BindDescriptorSet(descriptorSet);
13255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013256 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013257 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013258 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013259 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13260
13261 // error produced here.
13262 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13263
13264 m_errorMonitor->VerifyFound();
13265
13266 EndCommandBuffer();
13267}
13268
Chris Forbes5533bfc2016-07-27 14:12:34 +120013269TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13270 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13271 "are consumed via singlesample images types in the shader, or vice versa.");
13272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013274
13275 ASSERT_NO_FATAL_FAILURE(InitState());
13276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 char const *vsSource = "#version 450\n"
13279 "\n"
13280 "out gl_PerVertex { vec4 gl_Position; };\n"
13281 "void main() { gl_Position = vec4(0); }\n";
13282 char const *fsSource = "#version 450\n"
13283 "\n"
13284 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13285 "layout(location=0) out vec4 color;\n"
13286 "void main() {\n"
13287 " color = texelFetch(s, ivec2(0), 0);\n"
13288 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013289 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13290 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13291
13292 VkPipelineObj pipe(m_device);
13293 pipe.AddShader(&vs);
13294 pipe.AddShader(&fs);
13295 pipe.AddColorAttachment();
13296
13297 VkTextureObj texture(m_device, nullptr);
13298 VkSamplerObj sampler(m_device);
13299
13300 VkDescriptorSetObj descriptorSet(m_device);
13301 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13302 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13303
13304 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13305 ASSERT_VK_SUCCESS(err);
13306
13307 BeginCommandBuffer();
13308
13309 m_commandBuffer->BindPipeline(pipe);
13310 m_commandBuffer->BindDescriptorSet(descriptorSet);
13311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013312 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013313 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013314 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013315 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13316
13317 // error produced here.
13318 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13319
13320 m_errorMonitor->VerifyFound();
13321
13322 EndCommandBuffer();
13323}
13324
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013325#endif // SHADER_CHECKER_TESTS
13326
13327#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013328TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013330
13331 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013332
13333 // Create an image
13334 VkImage image;
13335
Karl Schultz6addd812016-02-02 17:17:23 -070013336 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13337 const int32_t tex_width = 32;
13338 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013339
13340 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13342 image_create_info.pNext = NULL;
13343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13344 image_create_info.format = tex_format;
13345 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013346 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013347 image_create_info.extent.depth = 1;
13348 image_create_info.mipLevels = 1;
13349 image_create_info.arrayLayers = 1;
13350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13351 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13352 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13353 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013354
13355 // Introduce error by sending down a bogus width extent
13356 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013357 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013358
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013359 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013360}
13361
Mark Youngc48c4c12016-04-11 14:26:49 -060013362TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13364 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013365
13366 ASSERT_NO_FATAL_FAILURE(InitState());
13367
13368 // Create an image
13369 VkImage image;
13370
13371 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13372 const int32_t tex_width = 32;
13373 const int32_t tex_height = 32;
13374
13375 VkImageCreateInfo image_create_info = {};
13376 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13377 image_create_info.pNext = NULL;
13378 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13379 image_create_info.format = tex_format;
13380 image_create_info.extent.width = tex_width;
13381 image_create_info.extent.height = tex_height;
13382 image_create_info.extent.depth = 1;
13383 image_create_info.mipLevels = 1;
13384 image_create_info.arrayLayers = 1;
13385 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13386 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13387 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13388 image_create_info.flags = 0;
13389
13390 // Introduce error by sending down a bogus width extent
13391 image_create_info.extent.width = 0;
13392 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13393
13394 m_errorMonitor->VerifyFound();
13395}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013396#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013397
Tobin Ehliscde08892015-09-22 10:11:37 -060013398#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013399TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13400 TEST_DESCRIPTION("Create a render pass with an attachment description "
13401 "format set to VK_FORMAT_UNDEFINED");
13402
13403 ASSERT_NO_FATAL_FAILURE(InitState());
13404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013407
13408 VkAttachmentReference color_attach = {};
13409 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13410 color_attach.attachment = 0;
13411 VkSubpassDescription subpass = {};
13412 subpass.colorAttachmentCount = 1;
13413 subpass.pColorAttachments = &color_attach;
13414
13415 VkRenderPassCreateInfo rpci = {};
13416 rpci.subpassCount = 1;
13417 rpci.pSubpasses = &subpass;
13418 rpci.attachmentCount = 1;
13419 VkAttachmentDescription attach_desc = {};
13420 attach_desc.format = VK_FORMAT_UNDEFINED;
13421 rpci.pAttachments = &attach_desc;
13422 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13423 VkRenderPass rp;
13424 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13425
13426 m_errorMonitor->VerifyFound();
13427
13428 if (result == VK_SUCCESS) {
13429 vkDestroyRenderPass(m_device->device(), rp, NULL);
13430 }
13431}
13432
Karl Schultz6addd812016-02-02 17:17:23 -070013433TEST_F(VkLayerTest, InvalidImageView) {
13434 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013437
Tobin Ehliscde08892015-09-22 10:11:37 -060013438 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013439
Mike Stroyana3082432015-09-25 13:39:21 -060013440 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013441 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013442
Karl Schultz6addd812016-02-02 17:17:23 -070013443 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13444 const int32_t tex_width = 32;
13445 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013446
13447 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013448 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13449 image_create_info.pNext = NULL;
13450 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13451 image_create_info.format = tex_format;
13452 image_create_info.extent.width = tex_width;
13453 image_create_info.extent.height = tex_height;
13454 image_create_info.extent.depth = 1;
13455 image_create_info.mipLevels = 1;
13456 image_create_info.arrayLayers = 1;
13457 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13458 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13459 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13460 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013461
Chia-I Wuf7458c52015-10-26 21:10:41 +080013462 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013463 ASSERT_VK_SUCCESS(err);
13464
13465 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013466 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13467 image_view_create_info.image = image;
13468 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13469 image_view_create_info.format = tex_format;
13470 image_view_create_info.subresourceRange.layerCount = 1;
13471 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13472 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013473 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013474
13475 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013476 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013477
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013478 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013479 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013480}
Mike Stroyana3082432015-09-25 13:39:21 -060013481
Mark Youngd339ba32016-05-30 13:28:35 -060013482TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13483 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013485 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013486
13487 ASSERT_NO_FATAL_FAILURE(InitState());
13488
13489 // Create an image and try to create a view with no memory backing the image
13490 VkImage image;
13491
13492 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13493 const int32_t tex_width = 32;
13494 const int32_t tex_height = 32;
13495
13496 VkImageCreateInfo image_create_info = {};
13497 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13498 image_create_info.pNext = NULL;
13499 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13500 image_create_info.format = tex_format;
13501 image_create_info.extent.width = tex_width;
13502 image_create_info.extent.height = tex_height;
13503 image_create_info.extent.depth = 1;
13504 image_create_info.mipLevels = 1;
13505 image_create_info.arrayLayers = 1;
13506 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13507 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13508 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13509 image_create_info.flags = 0;
13510
13511 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13512 ASSERT_VK_SUCCESS(err);
13513
13514 VkImageViewCreateInfo image_view_create_info = {};
13515 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13516 image_view_create_info.image = image;
13517 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13518 image_view_create_info.format = tex_format;
13519 image_view_create_info.subresourceRange.layerCount = 1;
13520 image_view_create_info.subresourceRange.baseMipLevel = 0;
13521 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013522 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013523
13524 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013525 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013526
13527 m_errorMonitor->VerifyFound();
13528 vkDestroyImage(m_device->device(), image, NULL);
13529 // If last error is success, it still created the view, so delete it.
13530 if (err == VK_SUCCESS) {
13531 vkDestroyImageView(m_device->device(), view, NULL);
13532 }
Mark Youngd339ba32016-05-30 13:28:35 -060013533}
13534
Karl Schultz6addd812016-02-02 17:17:23 -070013535TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013536 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
13537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
13538 "formats must have ONLY the "
13539 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013540
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013541 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013542
Karl Schultz6addd812016-02-02 17:17:23 -070013543 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013544 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013545 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013546 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013547
13548 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013549 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013550 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013551 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13552 image_view_create_info.format = tex_format;
13553 image_view_create_info.subresourceRange.baseMipLevel = 0;
13554 image_view_create_info.subresourceRange.levelCount = 1;
13555 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013556 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013557
13558 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013559 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013560
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013561 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013562}
13563
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013564TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013565 VkResult err;
13566 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13569 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013570
Mike Stroyana3082432015-09-25 13:39:21 -060013571 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013572
13573 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013574 VkImage srcImage;
13575 VkImage dstImage;
13576 VkDeviceMemory srcMem;
13577 VkDeviceMemory destMem;
13578 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013579
13580 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013581 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13582 image_create_info.pNext = NULL;
13583 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13584 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13585 image_create_info.extent.width = 32;
13586 image_create_info.extent.height = 32;
13587 image_create_info.extent.depth = 1;
13588 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013589 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013590 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13591 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13593 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013595 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013596 ASSERT_VK_SUCCESS(err);
13597
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013598 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013599 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013600 ASSERT_VK_SUCCESS(err);
13601
13602 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013603 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013604 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13605 memAlloc.pNext = NULL;
13606 memAlloc.allocationSize = 0;
13607 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013608
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013609 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013610 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013611 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013612 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013613 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013614 ASSERT_VK_SUCCESS(err);
13615
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013616 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013617 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013618 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013619 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013620 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013621 ASSERT_VK_SUCCESS(err);
13622
13623 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13624 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013625 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013626 ASSERT_VK_SUCCESS(err);
13627
13628 BeginCommandBuffer();
13629 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013630 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013631 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013632 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013633 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013634 copyRegion.srcOffset.x = 0;
13635 copyRegion.srcOffset.y = 0;
13636 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013637 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013638 copyRegion.dstSubresource.mipLevel = 0;
13639 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013640 // Introduce failure by forcing the dst layerCount to differ from src
13641 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013642 copyRegion.dstOffset.x = 0;
13643 copyRegion.dstOffset.y = 0;
13644 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013645 copyRegion.extent.width = 1;
13646 copyRegion.extent.height = 1;
13647 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013648 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013649 EndCommandBuffer();
13650
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013651 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013652
Chia-I Wuf7458c52015-10-26 21:10:41 +080013653 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013654 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013655 vkFreeMemory(m_device->device(), srcMem, NULL);
13656 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013657}
13658
Tony Barbourd6673642016-05-05 14:46:39 -060013659TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13660
13661 TEST_DESCRIPTION("Creating images with unsuported formats ");
13662
13663 ASSERT_NO_FATAL_FAILURE(InitState());
13664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13665 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013666 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 -060013667 VK_IMAGE_TILING_OPTIMAL, 0);
13668 ASSERT_TRUE(image.initialized());
13669
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013670 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13671 VkImageCreateInfo image_create_info;
13672 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13673 image_create_info.pNext = NULL;
13674 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13675 image_create_info.format = VK_FORMAT_UNDEFINED;
13676 image_create_info.extent.width = 32;
13677 image_create_info.extent.height = 32;
13678 image_create_info.extent.depth = 1;
13679 image_create_info.mipLevels = 1;
13680 image_create_info.arrayLayers = 1;
13681 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13682 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13683 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13684 image_create_info.flags = 0;
13685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13687 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013688
13689 VkImage localImage;
13690 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13691 m_errorMonitor->VerifyFound();
13692
Tony Barbourd6673642016-05-05 14:46:39 -060013693 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013694 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013695 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13696 VkFormat format = static_cast<VkFormat>(f);
13697 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013698 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013699 unsupported = format;
13700 break;
13701 }
13702 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013703
Tony Barbourd6673642016-05-05 14:46:39 -060013704 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013705 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013707
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013708 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013709 m_errorMonitor->VerifyFound();
13710 }
13711}
13712
13713TEST_F(VkLayerTest, ImageLayerViewTests) {
13714 VkResult ret;
13715 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13716
13717 ASSERT_NO_FATAL_FAILURE(InitState());
13718
13719 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013720 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 -060013721 VK_IMAGE_TILING_OPTIMAL, 0);
13722 ASSERT_TRUE(image.initialized());
13723
13724 VkImageView imgView;
13725 VkImageViewCreateInfo imgViewInfo = {};
13726 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13727 imgViewInfo.image = image.handle();
13728 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13729 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13730 imgViewInfo.subresourceRange.layerCount = 1;
13731 imgViewInfo.subresourceRange.baseMipLevel = 0;
13732 imgViewInfo.subresourceRange.levelCount = 1;
13733 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13734
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013736 // View can't have baseMipLevel >= image's mipLevels - Expect
13737 // VIEW_CREATE_ERROR
13738 imgViewInfo.subresourceRange.baseMipLevel = 1;
13739 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13740 m_errorMonitor->VerifyFound();
13741 imgViewInfo.subresourceRange.baseMipLevel = 0;
13742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013744 // View can't have baseArrayLayer >= image's arraySize - Expect
13745 // VIEW_CREATE_ERROR
13746 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13747 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13748 m_errorMonitor->VerifyFound();
13749 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13752 "pCreateInfo->subresourceRange."
13753 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013754 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13755 imgViewInfo.subresourceRange.levelCount = 0;
13756 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13757 m_errorMonitor->VerifyFound();
13758 imgViewInfo.subresourceRange.levelCount = 1;
13759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13761 "pCreateInfo->subresourceRange."
13762 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013763 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13764 imgViewInfo.subresourceRange.layerCount = 0;
13765 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13766 m_errorMonitor->VerifyFound();
13767 imgViewInfo.subresourceRange.layerCount = 1;
13768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060013770 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13771 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13772 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13773 m_errorMonitor->VerifyFound();
13774 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13777 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13778 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013779 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13780 // VIEW_CREATE_ERROR
13781 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13782 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13783 m_errorMonitor->VerifyFound();
13784 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13787 "differing formats but they must be "
13788 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060013789 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13790 // VIEW_CREATE_ERROR
13791 VkImageCreateInfo mutImgInfo = image.create_info();
13792 VkImage mutImage;
13793 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013794 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013795 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13796 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13797 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13798 ASSERT_VK_SUCCESS(ret);
13799 imgViewInfo.image = mutImage;
13800 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13801 m_errorMonitor->VerifyFound();
13802 imgViewInfo.image = image.handle();
13803 vkDestroyImage(m_device->handle(), mutImage, NULL);
13804}
13805
13806TEST_F(VkLayerTest, MiscImageLayerTests) {
13807
13808 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13809
13810 ASSERT_NO_FATAL_FAILURE(InitState());
13811
13812 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 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 -060013814 VK_IMAGE_TILING_OPTIMAL, 0);
13815 ASSERT_TRUE(image.initialized());
13816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013818 vk_testing::Buffer buffer;
13819 VkMemoryPropertyFlags reqs = 0;
13820 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13821 VkBufferImageCopy region = {};
13822 region.bufferRowLength = 128;
13823 region.bufferImageHeight = 128;
13824 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13825 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13826 region.imageSubresource.layerCount = 0;
13827 region.imageExtent.height = 4;
13828 region.imageExtent.width = 4;
13829 region.imageExtent.depth = 1;
13830 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013831 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13832 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013833 m_errorMonitor->VerifyFound();
13834 region.imageSubresource.layerCount = 1;
13835
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013836 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13837 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13838 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13840 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13841 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013842 m_errorMonitor->VerifyFound();
13843
13844 // BufferOffset must be a multiple of 4
13845 // Introduce failure by setting bufferOffset to a value not divisible by 4
13846 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13848 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13849 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013850 m_errorMonitor->VerifyFound();
13851
13852 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13853 region.bufferOffset = 0;
13854 region.imageExtent.height = 128;
13855 region.imageExtent.width = 128;
13856 // Introduce failure by setting bufferRowLength > 0 but less than width
13857 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13859 "must be zero or greater-than-or-equal-to imageExtent.width");
13860 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13861 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013862 m_errorMonitor->VerifyFound();
13863
13864 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
13865 region.bufferRowLength = 128;
13866 // Introduce failure by setting bufferRowHeight > 0 but less than height
13867 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13869 "must be zero or greater-than-or-equal-to imageExtent.height");
13870 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13871 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013872 m_errorMonitor->VerifyFound();
13873
13874 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
13876 "specify only COLOR or DEPTH or "
13877 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060013878 // Expect MISMATCHED_IMAGE_ASPECT
13879 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013880 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13881 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013882 m_errorMonitor->VerifyFound();
13883 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13886 "If the format of srcImage is a depth, stencil, depth stencil or "
13887 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060013888 // Expect INVALID_FILTER
13889 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013890 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060013891 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013892 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060013893 VkImageBlit blitRegion = {};
13894 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13895 blitRegion.srcSubresource.baseArrayLayer = 0;
13896 blitRegion.srcSubresource.layerCount = 1;
13897 blitRegion.srcSubresource.mipLevel = 0;
13898 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13899 blitRegion.dstSubresource.baseArrayLayer = 0;
13900 blitRegion.dstSubresource.layerCount = 1;
13901 blitRegion.dstSubresource.mipLevel = 0;
13902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013903 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
13904 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060013905 m_errorMonitor->VerifyFound();
13906
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060013907 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
13909 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
13910 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060013911 m_errorMonitor->VerifyFound();
13912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060013914 VkImageMemoryBarrier img_barrier;
13915 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
13916 img_barrier.pNext = NULL;
13917 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
13918 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
13919 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
13920 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
13921 img_barrier.image = image.handle();
13922 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
13923 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
13924 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13925 img_barrier.subresourceRange.baseArrayLayer = 0;
13926 img_barrier.subresourceRange.baseMipLevel = 0;
13927 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
13928 img_barrier.subresourceRange.layerCount = 0;
13929 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013930 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
13931 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060013932 m_errorMonitor->VerifyFound();
13933 img_barrier.subresourceRange.layerCount = 1;
13934}
13935
13936TEST_F(VkLayerTest, ImageFormatLimits) {
13937
13938 TEST_DESCRIPTION("Exceed the limits of image format ");
13939
Cody Northropc31a84f2016-08-22 10:41:47 -060013940 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060013942 VkImageCreateInfo image_create_info = {};
13943 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13944 image_create_info.pNext = NULL;
13945 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13946 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13947 image_create_info.extent.width = 32;
13948 image_create_info.extent.height = 32;
13949 image_create_info.extent.depth = 1;
13950 image_create_info.mipLevels = 1;
13951 image_create_info.arrayLayers = 1;
13952 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13953 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13954 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13955 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
13956 image_create_info.flags = 0;
13957
13958 VkImage nullImg;
13959 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013960 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
13961 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060013962 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
13963 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13964 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13965 m_errorMonitor->VerifyFound();
13966 image_create_info.extent.depth = 1;
13967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060013969 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
13970 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13971 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13972 m_errorMonitor->VerifyFound();
13973 image_create_info.mipLevels = 1;
13974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060013976 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
13977 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13978 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13979 m_errorMonitor->VerifyFound();
13980 image_create_info.arrayLayers = 1;
13981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060013983 int samples = imgFmtProps.sampleCounts >> 1;
13984 image_create_info.samples = (VkSampleCountFlagBits)samples;
13985 // Expect INVALID_FORMAT_LIMITS_VIOLATION
13986 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13987 m_errorMonitor->VerifyFound();
13988 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
13991 "VK_IMAGE_LAYOUT_UNDEFINED or "
13992 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060013993 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
13994 // Expect INVALID_LAYOUT
13995 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
13996 m_errorMonitor->VerifyFound();
13997 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
13998}
13999
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014000TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14001
14002 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014004
14005 ASSERT_NO_FATAL_FAILURE(InitState());
14006
14007 VkImageObj src_image(m_device);
14008 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14009 VkImageObj dst_image(m_device);
14010 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14011
14012 BeginCommandBuffer();
14013 VkImageCopy copy_region;
14014 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14015 copy_region.srcSubresource.mipLevel = 0;
14016 copy_region.srcSubresource.baseArrayLayer = 0;
14017 copy_region.srcSubresource.layerCount = 0;
14018 copy_region.srcOffset.x = 0;
14019 copy_region.srcOffset.y = 0;
14020 copy_region.srcOffset.z = 0;
14021 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14022 copy_region.dstSubresource.mipLevel = 0;
14023 copy_region.dstSubresource.baseArrayLayer = 0;
14024 copy_region.dstSubresource.layerCount = 0;
14025 copy_region.dstOffset.x = 0;
14026 copy_region.dstOffset.y = 0;
14027 copy_region.dstOffset.z = 0;
14028 copy_region.extent.width = 64;
14029 copy_region.extent.height = 64;
14030 copy_region.extent.depth = 1;
14031 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14032 &copy_region);
14033 EndCommandBuffer();
14034
14035 m_errorMonitor->VerifyFound();
14036}
14037
14038TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14039
14040 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014042
14043 ASSERT_NO_FATAL_FAILURE(InitState());
14044
14045 VkImageObj src_image(m_device);
14046 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14047 VkImageObj dst_image(m_device);
14048 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14049
14050 BeginCommandBuffer();
14051 VkImageCopy copy_region;
14052 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14053 copy_region.srcSubresource.mipLevel = 0;
14054 copy_region.srcSubresource.baseArrayLayer = 0;
14055 copy_region.srcSubresource.layerCount = 0;
14056 copy_region.srcOffset.x = 0;
14057 copy_region.srcOffset.y = 0;
14058 copy_region.srcOffset.z = 0;
14059 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14060 copy_region.dstSubresource.mipLevel = 0;
14061 copy_region.dstSubresource.baseArrayLayer = 0;
14062 copy_region.dstSubresource.layerCount = 0;
14063 copy_region.dstOffset.x = 0;
14064 copy_region.dstOffset.y = 0;
14065 copy_region.dstOffset.z = 0;
14066 copy_region.extent.width = 64;
14067 copy_region.extent.height = 64;
14068 copy_region.extent.depth = 1;
14069 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14070 &copy_region);
14071 EndCommandBuffer();
14072
14073 m_errorMonitor->VerifyFound();
14074}
14075
Karl Schultz6addd812016-02-02 17:17:23 -070014076TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014077 VkResult err;
14078 bool pass;
14079
14080 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14082 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014083
14084 ASSERT_NO_FATAL_FAILURE(InitState());
14085
14086 // Create two images of different types and try to copy between them
14087 VkImage srcImage;
14088 VkImage dstImage;
14089 VkDeviceMemory srcMem;
14090 VkDeviceMemory destMem;
14091 VkMemoryRequirements memReqs;
14092
14093 VkImageCreateInfo image_create_info = {};
14094 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14095 image_create_info.pNext = NULL;
14096 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14097 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14098 image_create_info.extent.width = 32;
14099 image_create_info.extent.height = 32;
14100 image_create_info.extent.depth = 1;
14101 image_create_info.mipLevels = 1;
14102 image_create_info.arrayLayers = 1;
14103 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14104 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14105 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14106 image_create_info.flags = 0;
14107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014108 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014109 ASSERT_VK_SUCCESS(err);
14110
14111 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14112 // Introduce failure by creating second image with a different-sized format.
14113 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014116 ASSERT_VK_SUCCESS(err);
14117
14118 // Allocate memory
14119 VkMemoryAllocateInfo memAlloc = {};
14120 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14121 memAlloc.pNext = NULL;
14122 memAlloc.allocationSize = 0;
14123 memAlloc.memoryTypeIndex = 0;
14124
14125 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14126 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014127 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014128 ASSERT_TRUE(pass);
14129 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14130 ASSERT_VK_SUCCESS(err);
14131
14132 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14133 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014135 ASSERT_TRUE(pass);
14136 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14137 ASSERT_VK_SUCCESS(err);
14138
14139 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14140 ASSERT_VK_SUCCESS(err);
14141 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14142 ASSERT_VK_SUCCESS(err);
14143
14144 BeginCommandBuffer();
14145 VkImageCopy copyRegion;
14146 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14147 copyRegion.srcSubresource.mipLevel = 0;
14148 copyRegion.srcSubresource.baseArrayLayer = 0;
14149 copyRegion.srcSubresource.layerCount = 0;
14150 copyRegion.srcOffset.x = 0;
14151 copyRegion.srcOffset.y = 0;
14152 copyRegion.srcOffset.z = 0;
14153 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14154 copyRegion.dstSubresource.mipLevel = 0;
14155 copyRegion.dstSubresource.baseArrayLayer = 0;
14156 copyRegion.dstSubresource.layerCount = 0;
14157 copyRegion.dstOffset.x = 0;
14158 copyRegion.dstOffset.y = 0;
14159 copyRegion.dstOffset.z = 0;
14160 copyRegion.extent.width = 1;
14161 copyRegion.extent.height = 1;
14162 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014163 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014164 EndCommandBuffer();
14165
14166 m_errorMonitor->VerifyFound();
14167
14168 vkDestroyImage(m_device->device(), srcImage, NULL);
14169 vkDestroyImage(m_device->device(), dstImage, NULL);
14170 vkFreeMemory(m_device->device(), srcMem, NULL);
14171 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014172}
14173
Karl Schultz6addd812016-02-02 17:17:23 -070014174TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14175 VkResult err;
14176 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014177
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014178 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14180 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014181
Mike Stroyana3082432015-09-25 13:39:21 -060014182 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014183
14184 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014185 VkImage srcImage;
14186 VkImage dstImage;
14187 VkDeviceMemory srcMem;
14188 VkDeviceMemory destMem;
14189 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014190
14191 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14193 image_create_info.pNext = NULL;
14194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14195 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14196 image_create_info.extent.width = 32;
14197 image_create_info.extent.height = 32;
14198 image_create_info.extent.depth = 1;
14199 image_create_info.mipLevels = 1;
14200 image_create_info.arrayLayers = 1;
14201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14203 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14204 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014206 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014207 ASSERT_VK_SUCCESS(err);
14208
Karl Schultzbdb75952016-04-19 11:36:49 -060014209 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14210
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014211 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014212 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014213 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014214 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014216 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014217 ASSERT_VK_SUCCESS(err);
14218
14219 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014220 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014221 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14222 memAlloc.pNext = NULL;
14223 memAlloc.allocationSize = 0;
14224 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014225
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014226 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014227 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014229 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014230 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014231 ASSERT_VK_SUCCESS(err);
14232
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014233 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014234 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014235 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014236 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014237 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014238 ASSERT_VK_SUCCESS(err);
14239
14240 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14241 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014242 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014243 ASSERT_VK_SUCCESS(err);
14244
14245 BeginCommandBuffer();
14246 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014247 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014248 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014249 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014250 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014251 copyRegion.srcOffset.x = 0;
14252 copyRegion.srcOffset.y = 0;
14253 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014254 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014255 copyRegion.dstSubresource.mipLevel = 0;
14256 copyRegion.dstSubresource.baseArrayLayer = 0;
14257 copyRegion.dstSubresource.layerCount = 0;
14258 copyRegion.dstOffset.x = 0;
14259 copyRegion.dstOffset.y = 0;
14260 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014261 copyRegion.extent.width = 1;
14262 copyRegion.extent.height = 1;
14263 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014264 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014265 EndCommandBuffer();
14266
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014267 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014268
Chia-I Wuf7458c52015-10-26 21:10:41 +080014269 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014270 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014271 vkFreeMemory(m_device->device(), srcMem, NULL);
14272 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014273}
14274
Karl Schultz6addd812016-02-02 17:17:23 -070014275TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14276 VkResult err;
14277 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14280 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014281
Mike Stroyana3082432015-09-25 13:39:21 -060014282 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014283
14284 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014285 VkImage srcImage;
14286 VkImage dstImage;
14287 VkDeviceMemory srcMem;
14288 VkDeviceMemory destMem;
14289 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014290
14291 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014292 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14293 image_create_info.pNext = NULL;
14294 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14295 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14296 image_create_info.extent.width = 32;
14297 image_create_info.extent.height = 1;
14298 image_create_info.extent.depth = 1;
14299 image_create_info.mipLevels = 1;
14300 image_create_info.arrayLayers = 1;
14301 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14302 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14303 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14304 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014306 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014307 ASSERT_VK_SUCCESS(err);
14308
Karl Schultz6addd812016-02-02 17:17:23 -070014309 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014312 ASSERT_VK_SUCCESS(err);
14313
14314 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014315 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014316 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14317 memAlloc.pNext = NULL;
14318 memAlloc.allocationSize = 0;
14319 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014320
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014321 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014322 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014323 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014324 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014325 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014326 ASSERT_VK_SUCCESS(err);
14327
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014328 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014329 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014331 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014332 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014333 ASSERT_VK_SUCCESS(err);
14334
14335 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14336 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014337 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014338 ASSERT_VK_SUCCESS(err);
14339
14340 BeginCommandBuffer();
14341 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014342 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14343 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014344 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014345 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014346 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014347 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014348 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014349 resolveRegion.srcOffset.x = 0;
14350 resolveRegion.srcOffset.y = 0;
14351 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014352 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014353 resolveRegion.dstSubresource.mipLevel = 0;
14354 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014355 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014356 resolveRegion.dstOffset.x = 0;
14357 resolveRegion.dstOffset.y = 0;
14358 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014359 resolveRegion.extent.width = 1;
14360 resolveRegion.extent.height = 1;
14361 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014362 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014363 EndCommandBuffer();
14364
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014365 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014366
Chia-I Wuf7458c52015-10-26 21:10:41 +080014367 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014368 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014369 vkFreeMemory(m_device->device(), srcMem, NULL);
14370 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014371}
14372
Karl Schultz6addd812016-02-02 17:17:23 -070014373TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14374 VkResult err;
14375 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14378 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014379
Mike Stroyana3082432015-09-25 13:39:21 -060014380 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014381
Chris Forbesa7530692016-05-08 12:35:39 +120014382 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014383 VkImage srcImage;
14384 VkImage dstImage;
14385 VkDeviceMemory srcMem;
14386 VkDeviceMemory destMem;
14387 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014388
14389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14391 image_create_info.pNext = NULL;
14392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14393 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14394 image_create_info.extent.width = 32;
14395 image_create_info.extent.height = 1;
14396 image_create_info.extent.depth = 1;
14397 image_create_info.mipLevels = 1;
14398 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014399 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014400 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14401 // Note: Some implementations expect color attachment usage for any
14402 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014403 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014404 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014406 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014407 ASSERT_VK_SUCCESS(err);
14408
Karl Schultz6addd812016-02-02 17:17:23 -070014409 // Note: Some implementations expect color attachment usage for any
14410 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014411 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014413 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014414 ASSERT_VK_SUCCESS(err);
14415
14416 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014417 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014418 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14419 memAlloc.pNext = NULL;
14420 memAlloc.allocationSize = 0;
14421 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014422
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014423 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014424 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014425 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014426 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014427 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014428 ASSERT_VK_SUCCESS(err);
14429
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014430 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014431 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014432 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014433 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014434 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014435 ASSERT_VK_SUCCESS(err);
14436
14437 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14438 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014439 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014440 ASSERT_VK_SUCCESS(err);
14441
14442 BeginCommandBuffer();
14443 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014444 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14445 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014446 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014447 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014448 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014449 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014450 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014451 resolveRegion.srcOffset.x = 0;
14452 resolveRegion.srcOffset.y = 0;
14453 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014454 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014455 resolveRegion.dstSubresource.mipLevel = 0;
14456 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014457 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014458 resolveRegion.dstOffset.x = 0;
14459 resolveRegion.dstOffset.y = 0;
14460 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014461 resolveRegion.extent.width = 1;
14462 resolveRegion.extent.height = 1;
14463 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014464 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014465 EndCommandBuffer();
14466
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014467 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014468
Chia-I Wuf7458c52015-10-26 21:10:41 +080014469 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014470 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014471 vkFreeMemory(m_device->device(), srcMem, NULL);
14472 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014473}
14474
Karl Schultz6addd812016-02-02 17:17:23 -070014475TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14476 VkResult err;
14477 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14480 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014481
Mike Stroyana3082432015-09-25 13:39:21 -060014482 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014483
14484 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014485 VkImage srcImage;
14486 VkImage dstImage;
14487 VkDeviceMemory srcMem;
14488 VkDeviceMemory destMem;
14489 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014490
14491 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014492 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14493 image_create_info.pNext = NULL;
14494 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14495 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14496 image_create_info.extent.width = 32;
14497 image_create_info.extent.height = 1;
14498 image_create_info.extent.depth = 1;
14499 image_create_info.mipLevels = 1;
14500 image_create_info.arrayLayers = 1;
14501 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14502 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14503 // Note: Some implementations expect color attachment usage for any
14504 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014505 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014506 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014508 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014509 ASSERT_VK_SUCCESS(err);
14510
Karl Schultz6addd812016-02-02 17:17:23 -070014511 // Set format to something other than source image
14512 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14513 // Note: Some implementations expect color attachment usage for any
14514 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014515 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014516 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014518 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014519 ASSERT_VK_SUCCESS(err);
14520
14521 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014522 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014523 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14524 memAlloc.pNext = NULL;
14525 memAlloc.allocationSize = 0;
14526 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014527
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014528 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014529 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014530 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014531 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014532 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014533 ASSERT_VK_SUCCESS(err);
14534
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014535 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014536 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014537 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014538 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014539 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014540 ASSERT_VK_SUCCESS(err);
14541
14542 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14543 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014544 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014545 ASSERT_VK_SUCCESS(err);
14546
14547 BeginCommandBuffer();
14548 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014549 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14550 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014551 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014552 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014553 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014554 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014555 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014556 resolveRegion.srcOffset.x = 0;
14557 resolveRegion.srcOffset.y = 0;
14558 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014559 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014560 resolveRegion.dstSubresource.mipLevel = 0;
14561 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014562 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014563 resolveRegion.dstOffset.x = 0;
14564 resolveRegion.dstOffset.y = 0;
14565 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014566 resolveRegion.extent.width = 1;
14567 resolveRegion.extent.height = 1;
14568 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014570 EndCommandBuffer();
14571
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014572 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014573
Chia-I Wuf7458c52015-10-26 21:10:41 +080014574 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014575 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014576 vkFreeMemory(m_device->device(), srcMem, NULL);
14577 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014578}
14579
Karl Schultz6addd812016-02-02 17:17:23 -070014580TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14581 VkResult err;
14582 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14585 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014586
Mike Stroyana3082432015-09-25 13:39:21 -060014587 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014588
14589 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014590 VkImage srcImage;
14591 VkImage dstImage;
14592 VkDeviceMemory srcMem;
14593 VkDeviceMemory destMem;
14594 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014595
14596 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014597 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14598 image_create_info.pNext = NULL;
14599 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14600 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14601 image_create_info.extent.width = 32;
14602 image_create_info.extent.height = 1;
14603 image_create_info.extent.depth = 1;
14604 image_create_info.mipLevels = 1;
14605 image_create_info.arrayLayers = 1;
14606 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14607 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14608 // Note: Some implementations expect color attachment usage for any
14609 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014610 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014611 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014613 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014614 ASSERT_VK_SUCCESS(err);
14615
Karl Schultz6addd812016-02-02 17:17:23 -070014616 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14617 // Note: Some implementations expect color attachment usage for any
14618 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014619 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014620 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014622 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014623 ASSERT_VK_SUCCESS(err);
14624
14625 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014626 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014627 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14628 memAlloc.pNext = NULL;
14629 memAlloc.allocationSize = 0;
14630 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014631
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014632 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014633 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014635 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014636 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014637 ASSERT_VK_SUCCESS(err);
14638
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014639 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014640 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014641 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014642 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014643 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014644 ASSERT_VK_SUCCESS(err);
14645
14646 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14647 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014648 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014649 ASSERT_VK_SUCCESS(err);
14650
14651 BeginCommandBuffer();
14652 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014653 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14654 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014655 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014656 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014657 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014658 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014659 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014660 resolveRegion.srcOffset.x = 0;
14661 resolveRegion.srcOffset.y = 0;
14662 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014663 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014664 resolveRegion.dstSubresource.mipLevel = 0;
14665 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014666 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014667 resolveRegion.dstOffset.x = 0;
14668 resolveRegion.dstOffset.y = 0;
14669 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014670 resolveRegion.extent.width = 1;
14671 resolveRegion.extent.height = 1;
14672 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014674 EndCommandBuffer();
14675
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014676 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014677
Chia-I Wuf7458c52015-10-26 21:10:41 +080014678 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014679 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014680 vkFreeMemory(m_device->device(), srcMem, NULL);
14681 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014682}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014683
Karl Schultz6addd812016-02-02 17:17:23 -070014684TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014685 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014686 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14687 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014688 // The image format check comes 2nd in validation so we trigger it first,
14689 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014690 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14693 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014694
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014695 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014696
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014697 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014698 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14699 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014700
14701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14703 ds_pool_ci.pNext = NULL;
14704 ds_pool_ci.maxSets = 1;
14705 ds_pool_ci.poolSizeCount = 1;
14706 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014707
14708 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014710 ASSERT_VK_SUCCESS(err);
14711
14712 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014713 dsl_binding.binding = 0;
14714 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14715 dsl_binding.descriptorCount = 1;
14716 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14717 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014718
14719 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014720 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14721 ds_layout_ci.pNext = NULL;
14722 ds_layout_ci.bindingCount = 1;
14723 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014724 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014725 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014726 ASSERT_VK_SUCCESS(err);
14727
14728 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014729 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014730 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014731 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014732 alloc_info.descriptorPool = ds_pool;
14733 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014734 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014735 ASSERT_VK_SUCCESS(err);
14736
Karl Schultz6addd812016-02-02 17:17:23 -070014737 VkImage image_bad;
14738 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014739 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014740 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014741 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014742 const int32_t tex_width = 32;
14743 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014744
14745 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14747 image_create_info.pNext = NULL;
14748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14749 image_create_info.format = tex_format_bad;
14750 image_create_info.extent.width = tex_width;
14751 image_create_info.extent.height = tex_height;
14752 image_create_info.extent.depth = 1;
14753 image_create_info.mipLevels = 1;
14754 image_create_info.arrayLayers = 1;
14755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014758 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014760 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014761 ASSERT_VK_SUCCESS(err);
14762 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014763 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14764 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014765 ASSERT_VK_SUCCESS(err);
14766
14767 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014768 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14769 image_view_create_info.image = image_bad;
14770 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14771 image_view_create_info.format = tex_format_bad;
14772 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14773 image_view_create_info.subresourceRange.baseMipLevel = 0;
14774 image_view_create_info.subresourceRange.layerCount = 1;
14775 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014776 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014777
14778 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014781 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014782
Chia-I Wuf7458c52015-10-26 21:10:41 +080014783 vkDestroyImage(m_device->device(), image_bad, NULL);
14784 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14786 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014787}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014788
14789TEST_F(VkLayerTest, ClearImageErrors) {
14790 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14791 "ClearDepthStencilImage with a color image.");
14792
14793 ASSERT_NO_FATAL_FAILURE(InitState());
14794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14795
14796 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14797 BeginCommandBuffer();
14798 m_commandBuffer->EndRenderPass();
14799
14800 // Color image
14801 VkClearColorValue clear_color;
14802 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14803 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14804 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14805 const int32_t img_width = 32;
14806 const int32_t img_height = 32;
14807 VkImageCreateInfo image_create_info = {};
14808 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14809 image_create_info.pNext = NULL;
14810 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14811 image_create_info.format = color_format;
14812 image_create_info.extent.width = img_width;
14813 image_create_info.extent.height = img_height;
14814 image_create_info.extent.depth = 1;
14815 image_create_info.mipLevels = 1;
14816 image_create_info.arrayLayers = 1;
14817 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14818 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14819 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14820
14821 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014822 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014824 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014825
14826 // Depth/Stencil image
14827 VkClearDepthStencilValue clear_value = {0};
14828 reqs = 0; // don't need HOST_VISIBLE DS image
14829 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14830 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14831 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14832 ds_image_create_info.extent.width = 64;
14833 ds_image_create_info.extent.height = 64;
14834 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14835 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14836
14837 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014838 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014840 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 -060014841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014845 &color_range);
14846
14847 m_errorMonitor->VerifyFound();
14848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14850 "image created without "
14851 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014854 &color_range);
14855
14856 m_errorMonitor->VerifyFound();
14857
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014858 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14860 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
14863 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014864
14865 m_errorMonitor->VerifyFound();
14866}
Tobin Ehliscde08892015-09-22 10:11:37 -060014867#endif // IMAGE_TESTS
14868
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060014869
14870// WSI Enabled Tests
14871//
14872TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
14873
14874#if defined(VK_USE_PLATFORM_XCB_KHR)
14875 VkSurfaceKHR surface = VK_NULL_HANDLE;
14876
14877 VkResult err;
14878 bool pass;
14879 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
14880 VkSwapchainCreateInfoKHR swapchain_create_info = {};
14881 // uint32_t swapchain_image_count = 0;
14882 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
14883 // uint32_t image_index = 0;
14884 // VkPresentInfoKHR present_info = {};
14885
14886 ASSERT_NO_FATAL_FAILURE(InitState());
14887
14888 // Use the create function from one of the VK_KHR_*_surface extension in
14889 // order to create a surface, testing all known errors in the process,
14890 // before successfully creating a surface:
14891 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
14892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
14893 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
14894 pass = (err != VK_SUCCESS);
14895 ASSERT_TRUE(pass);
14896 m_errorMonitor->VerifyFound();
14897
14898 // Next, try to create a surface with the wrong
14899 // VkXcbSurfaceCreateInfoKHR::sType:
14900 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
14901 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
14902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
14903 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
14904 pass = (err != VK_SUCCESS);
14905 ASSERT_TRUE(pass);
14906 m_errorMonitor->VerifyFound();
14907
14908 // Create a native window, and then correctly create a surface:
14909 xcb_connection_t *connection;
14910 xcb_screen_t *screen;
14911 xcb_window_t xcb_window;
14912 xcb_intern_atom_reply_t *atom_wm_delete_window;
14913
14914 const xcb_setup_t *setup;
14915 xcb_screen_iterator_t iter;
14916 int scr;
14917 uint32_t value_mask, value_list[32];
14918 int width = 1;
14919 int height = 1;
14920
14921 connection = xcb_connect(NULL, &scr);
14922 ASSERT_TRUE(connection != NULL);
14923 setup = xcb_get_setup(connection);
14924 iter = xcb_setup_roots_iterator(setup);
14925 while (scr-- > 0)
14926 xcb_screen_next(&iter);
14927 screen = iter.data;
14928
14929 xcb_window = xcb_generate_id(connection);
14930
14931 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
14932 value_list[0] = screen->black_pixel;
14933 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
14934
14935 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
14936 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
14937
14938 /* Magic code that will send notification when window is destroyed */
14939 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
14940 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
14941
14942 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
14943 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
14944 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
14945 free(reply);
14946
14947 xcb_map_window(connection, xcb_window);
14948
14949 // Force the x/y coordinates to 100,100 results are identical in consecutive
14950 // runs
14951 const uint32_t coords[] = { 100, 100 };
14952 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
14953
14954 // Finally, try to correctly create a surface:
14955 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
14956 xcb_create_info.pNext = NULL;
14957 xcb_create_info.flags = 0;
14958 xcb_create_info.connection = connection;
14959 xcb_create_info.window = xcb_window;
14960 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
14961 pass = (err == VK_SUCCESS);
14962 ASSERT_TRUE(pass);
14963
14964 // Check if surface supports presentation:
14965
14966 // 1st, do so without having queried the queue families:
14967 VkBool32 supported = false;
14968 // TODO: Get the following error to come out:
14969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14970 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
14971 "function");
14972 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
14973 pass = (err != VK_SUCCESS);
14974 // ASSERT_TRUE(pass);
14975 // m_errorMonitor->VerifyFound();
14976
14977 // Next, query a queue family index that's too large:
14978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
14979 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
14980 pass = (err != VK_SUCCESS);
14981 ASSERT_TRUE(pass);
14982 m_errorMonitor->VerifyFound();
14983
14984 // Finally, do so correctly:
14985 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
14986 // SUPPORTED
14987 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
14988 pass = (err == VK_SUCCESS);
14989 ASSERT_TRUE(pass);
14990
14991 // Before proceeding, try to create a swapchain without having called
14992 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
14993 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
14994 swapchain_create_info.pNext = NULL;
14995 swapchain_create_info.flags = 0;
14996 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14997 swapchain_create_info.surface = surface;
14998 swapchain_create_info.imageArrayLayers = 1;
14999 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15000 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15002 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15003 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15004 pass = (err != VK_SUCCESS);
15005 ASSERT_TRUE(pass);
15006 m_errorMonitor->VerifyFound();
15007
15008 // Get the surface capabilities:
15009 VkSurfaceCapabilitiesKHR surface_capabilities;
15010
15011 // Do so correctly (only error logged by this entrypoint is if the
15012 // extension isn't enabled):
15013 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15014 pass = (err == VK_SUCCESS);
15015 ASSERT_TRUE(pass);
15016
15017 // Get the surface formats:
15018 uint32_t surface_format_count;
15019
15020 // First, try without a pointer to surface_format_count:
15021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15022 "specified as NULL");
15023 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15024 pass = (err == VK_SUCCESS);
15025 ASSERT_TRUE(pass);
15026 m_errorMonitor->VerifyFound();
15027
15028 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15029 // correctly done a 1st try (to get the count):
15030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15031 surface_format_count = 0;
15032 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15033 pass = (err == VK_SUCCESS);
15034 ASSERT_TRUE(pass);
15035 m_errorMonitor->VerifyFound();
15036
15037 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15038 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15039 pass = (err == VK_SUCCESS);
15040 ASSERT_TRUE(pass);
15041
15042 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15043 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15044
15045 // Next, do a 2nd try with surface_format_count being set too high:
15046 surface_format_count += 5;
15047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15048 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15049 pass = (err == VK_SUCCESS);
15050 ASSERT_TRUE(pass);
15051 m_errorMonitor->VerifyFound();
15052
15053 // Finally, do a correct 1st and 2nd try:
15054 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15055 pass = (err == VK_SUCCESS);
15056 ASSERT_TRUE(pass);
15057 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15058 pass = (err == VK_SUCCESS);
15059 ASSERT_TRUE(pass);
15060
15061 // Get the surface present modes:
15062 uint32_t surface_present_mode_count;
15063
15064 // First, try without a pointer to surface_format_count:
15065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15066 "specified as NULL");
15067
15068 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15069 pass = (err == VK_SUCCESS);
15070 ASSERT_TRUE(pass);
15071 m_errorMonitor->VerifyFound();
15072
15073 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15074 // correctly done a 1st try (to get the count):
15075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15076 surface_present_mode_count = 0;
15077 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15078 (VkPresentModeKHR *)&surface_present_mode_count);
15079 pass = (err == VK_SUCCESS);
15080 ASSERT_TRUE(pass);
15081 m_errorMonitor->VerifyFound();
15082
15083 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15084 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15085 pass = (err == VK_SUCCESS);
15086 ASSERT_TRUE(pass);
15087
15088 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15089 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15090
15091 // Next, do a 2nd try with surface_format_count being set too high:
15092 surface_present_mode_count += 5;
15093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15094 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15095 pass = (err == VK_SUCCESS);
15096 ASSERT_TRUE(pass);
15097 m_errorMonitor->VerifyFound();
15098
15099 // Finally, do a correct 1st and 2nd try:
15100 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15101 pass = (err == VK_SUCCESS);
15102 ASSERT_TRUE(pass);
15103 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15104 pass = (err == VK_SUCCESS);
15105 ASSERT_TRUE(pass);
15106
15107 // Create a swapchain:
15108
15109 // First, try without a pointer to swapchain_create_info:
15110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15111 "specified as NULL");
15112
15113 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15114 pass = (err != VK_SUCCESS);
15115 ASSERT_TRUE(pass);
15116 m_errorMonitor->VerifyFound();
15117
15118 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15119 // sType:
15120 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15122
15123 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15124 pass = (err != VK_SUCCESS);
15125 ASSERT_TRUE(pass);
15126 m_errorMonitor->VerifyFound();
15127
15128 // Next, call with a NULL swapchain pointer:
15129 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15130 swapchain_create_info.pNext = NULL;
15131 swapchain_create_info.flags = 0;
15132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15133 "specified as NULL");
15134
15135 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15136 pass = (err != VK_SUCCESS);
15137 ASSERT_TRUE(pass);
15138 m_errorMonitor->VerifyFound();
15139
15140 // TODO: Enhance swapchain layer so that
15141 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15142
15143 // Next, call with a queue family index that's too large:
15144 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15145 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15146 swapchain_create_info.queueFamilyIndexCount = 2;
15147 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15149 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15150 pass = (err != VK_SUCCESS);
15151 ASSERT_TRUE(pass);
15152 m_errorMonitor->VerifyFound();
15153
15154 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15155 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15156 swapchain_create_info.queueFamilyIndexCount = 1;
15157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15158 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15159 "pCreateInfo->pQueueFamilyIndices).");
15160 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15161 pass = (err != VK_SUCCESS);
15162 ASSERT_TRUE(pass);
15163 m_errorMonitor->VerifyFound();
15164
15165 // Next, call with an invalid imageSharingMode:
15166 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15167 swapchain_create_info.queueFamilyIndexCount = 1;
15168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15169 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15170 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15171 pass = (err != VK_SUCCESS);
15172 ASSERT_TRUE(pass);
15173 m_errorMonitor->VerifyFound();
15174 // Fix for the future:
15175 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15176 // SUPPORTED
15177 swapchain_create_info.queueFamilyIndexCount = 0;
15178 queueFamilyIndex[0] = 0;
15179 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15180
15181 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15182 // Get the images from a swapchain:
15183 // Acquire an image from a swapchain:
15184 // Present an image to a swapchain:
15185 // Destroy the swapchain:
15186
15187 // TODOs:
15188 //
15189 // - Try destroying the device without first destroying the swapchain
15190 //
15191 // - Try destroying the device without first destroying the surface
15192 //
15193 // - Try destroying the surface without first destroying the swapchain
15194
15195 // Destroy the surface:
15196 vkDestroySurfaceKHR(instance(), surface, NULL);
15197
15198 // Tear down the window:
15199 xcb_destroy_window(connection, xcb_window);
15200 xcb_disconnect(connection);
15201
15202#else // VK_USE_PLATFORM_XCB_KHR
15203 return;
15204#endif // VK_USE_PLATFORM_XCB_KHR
15205}
15206
15207//
15208// POSITIVE VALIDATION TESTS
15209//
15210// These tests do not expect to encounter ANY validation errors pass only if this is true
15211
15212// This is a positive test. No failures are expected.
15213TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15214 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15215 "is ignoring VkWriteDescriptorSet members that are not "
15216 "related to the descriptor type specified by "
15217 "VkWriteDescriptorSet::descriptorType. Correct "
15218 "validation behavior will result in the test running to "
15219 "completion without validation errors.");
15220
15221 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15222
15223 ASSERT_NO_FATAL_FAILURE(InitState());
15224
15225 // Image Case
15226 {
15227 m_errorMonitor->ExpectSuccess();
15228
15229 VkImage image;
15230 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15231 const int32_t tex_width = 32;
15232 const int32_t tex_height = 32;
15233 VkImageCreateInfo image_create_info = {};
15234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15235 image_create_info.pNext = NULL;
15236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15237 image_create_info.format = tex_format;
15238 image_create_info.extent.width = tex_width;
15239 image_create_info.extent.height = tex_height;
15240 image_create_info.extent.depth = 1;
15241 image_create_info.mipLevels = 1;
15242 image_create_info.arrayLayers = 1;
15243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15244 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15245 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15246 image_create_info.flags = 0;
15247 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15248 ASSERT_VK_SUCCESS(err);
15249
15250 VkMemoryRequirements memory_reqs;
15251 VkDeviceMemory image_memory;
15252 bool pass;
15253 VkMemoryAllocateInfo memory_info = {};
15254 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15255 memory_info.pNext = NULL;
15256 memory_info.allocationSize = 0;
15257 memory_info.memoryTypeIndex = 0;
15258 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15259 memory_info.allocationSize = memory_reqs.size;
15260 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15261 ASSERT_TRUE(pass);
15262 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15263 ASSERT_VK_SUCCESS(err);
15264 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15265 ASSERT_VK_SUCCESS(err);
15266
15267 VkImageViewCreateInfo image_view_create_info = {};
15268 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15269 image_view_create_info.image = image;
15270 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15271 image_view_create_info.format = tex_format;
15272 image_view_create_info.subresourceRange.layerCount = 1;
15273 image_view_create_info.subresourceRange.baseMipLevel = 0;
15274 image_view_create_info.subresourceRange.levelCount = 1;
15275 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15276
15277 VkImageView view;
15278 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15279 ASSERT_VK_SUCCESS(err);
15280
15281 VkDescriptorPoolSize ds_type_count = {};
15282 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15283 ds_type_count.descriptorCount = 1;
15284
15285 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15286 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15287 ds_pool_ci.pNext = NULL;
15288 ds_pool_ci.maxSets = 1;
15289 ds_pool_ci.poolSizeCount = 1;
15290 ds_pool_ci.pPoolSizes = &ds_type_count;
15291
15292 VkDescriptorPool ds_pool;
15293 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15294 ASSERT_VK_SUCCESS(err);
15295
15296 VkDescriptorSetLayoutBinding dsl_binding = {};
15297 dsl_binding.binding = 0;
15298 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15299 dsl_binding.descriptorCount = 1;
15300 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15301 dsl_binding.pImmutableSamplers = NULL;
15302
15303 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15304 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15305 ds_layout_ci.pNext = NULL;
15306 ds_layout_ci.bindingCount = 1;
15307 ds_layout_ci.pBindings = &dsl_binding;
15308 VkDescriptorSetLayout ds_layout;
15309 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15310 ASSERT_VK_SUCCESS(err);
15311
15312 VkDescriptorSet descriptor_set;
15313 VkDescriptorSetAllocateInfo alloc_info = {};
15314 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15315 alloc_info.descriptorSetCount = 1;
15316 alloc_info.descriptorPool = ds_pool;
15317 alloc_info.pSetLayouts = &ds_layout;
15318 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15319 ASSERT_VK_SUCCESS(err);
15320
15321 VkDescriptorImageInfo image_info = {};
15322 image_info.imageView = view;
15323 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15324
15325 VkWriteDescriptorSet descriptor_write;
15326 memset(&descriptor_write, 0, sizeof(descriptor_write));
15327 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15328 descriptor_write.dstSet = descriptor_set;
15329 descriptor_write.dstBinding = 0;
15330 descriptor_write.descriptorCount = 1;
15331 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15332 descriptor_write.pImageInfo = &image_info;
15333
15334 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15335 // be
15336 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15337 // This will most likely produce a crash if the parameter_validation
15338 // layer
15339 // does not correctly ignore pBufferInfo.
15340 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15341 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15342
15343 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15344
15345 m_errorMonitor->VerifyNotFound();
15346
15347 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15348 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15349 vkDestroyImageView(m_device->device(), view, NULL);
15350 vkDestroyImage(m_device->device(), image, NULL);
15351 vkFreeMemory(m_device->device(), image_memory, NULL);
15352 }
15353
15354 // Buffer Case
15355 {
15356 m_errorMonitor->ExpectSuccess();
15357
15358 VkBuffer buffer;
15359 uint32_t queue_family_index = 0;
15360 VkBufferCreateInfo buffer_create_info = {};
15361 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15362 buffer_create_info.size = 1024;
15363 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15364 buffer_create_info.queueFamilyIndexCount = 1;
15365 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15366
15367 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15368 ASSERT_VK_SUCCESS(err);
15369
15370 VkMemoryRequirements memory_reqs;
15371 VkDeviceMemory buffer_memory;
15372 bool pass;
15373 VkMemoryAllocateInfo memory_info = {};
15374 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15375 memory_info.pNext = NULL;
15376 memory_info.allocationSize = 0;
15377 memory_info.memoryTypeIndex = 0;
15378
15379 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15380 memory_info.allocationSize = memory_reqs.size;
15381 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15382 ASSERT_TRUE(pass);
15383
15384 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15385 ASSERT_VK_SUCCESS(err);
15386 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15387 ASSERT_VK_SUCCESS(err);
15388
15389 VkDescriptorPoolSize ds_type_count = {};
15390 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15391 ds_type_count.descriptorCount = 1;
15392
15393 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15394 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15395 ds_pool_ci.pNext = NULL;
15396 ds_pool_ci.maxSets = 1;
15397 ds_pool_ci.poolSizeCount = 1;
15398 ds_pool_ci.pPoolSizes = &ds_type_count;
15399
15400 VkDescriptorPool ds_pool;
15401 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15402 ASSERT_VK_SUCCESS(err);
15403
15404 VkDescriptorSetLayoutBinding dsl_binding = {};
15405 dsl_binding.binding = 0;
15406 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15407 dsl_binding.descriptorCount = 1;
15408 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15409 dsl_binding.pImmutableSamplers = NULL;
15410
15411 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15412 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15413 ds_layout_ci.pNext = NULL;
15414 ds_layout_ci.bindingCount = 1;
15415 ds_layout_ci.pBindings = &dsl_binding;
15416 VkDescriptorSetLayout ds_layout;
15417 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15418 ASSERT_VK_SUCCESS(err);
15419
15420 VkDescriptorSet descriptor_set;
15421 VkDescriptorSetAllocateInfo alloc_info = {};
15422 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15423 alloc_info.descriptorSetCount = 1;
15424 alloc_info.descriptorPool = ds_pool;
15425 alloc_info.pSetLayouts = &ds_layout;
15426 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15427 ASSERT_VK_SUCCESS(err);
15428
15429 VkDescriptorBufferInfo buffer_info = {};
15430 buffer_info.buffer = buffer;
15431 buffer_info.offset = 0;
15432 buffer_info.range = 1024;
15433
15434 VkWriteDescriptorSet descriptor_write;
15435 memset(&descriptor_write, 0, sizeof(descriptor_write));
15436 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15437 descriptor_write.dstSet = descriptor_set;
15438 descriptor_write.dstBinding = 0;
15439 descriptor_write.descriptorCount = 1;
15440 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15441 descriptor_write.pBufferInfo = &buffer_info;
15442
15443 // Set pImageInfo and pTexelBufferView to invalid values, which should
15444 // be
15445 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15446 // This will most likely produce a crash if the parameter_validation
15447 // layer
15448 // does not correctly ignore pImageInfo.
15449 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15450 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15451
15452 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15453
15454 m_errorMonitor->VerifyNotFound();
15455
15456 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15459 vkDestroyBuffer(m_device->device(), buffer, NULL);
15460 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15461 }
15462
15463 // Texel Buffer Case
15464 {
15465 m_errorMonitor->ExpectSuccess();
15466
15467 VkBuffer buffer;
15468 uint32_t queue_family_index = 0;
15469 VkBufferCreateInfo buffer_create_info = {};
15470 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15471 buffer_create_info.size = 1024;
15472 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15473 buffer_create_info.queueFamilyIndexCount = 1;
15474 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15475
15476 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15477 ASSERT_VK_SUCCESS(err);
15478
15479 VkMemoryRequirements memory_reqs;
15480 VkDeviceMemory buffer_memory;
15481 bool pass;
15482 VkMemoryAllocateInfo memory_info = {};
15483 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15484 memory_info.pNext = NULL;
15485 memory_info.allocationSize = 0;
15486 memory_info.memoryTypeIndex = 0;
15487
15488 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15489 memory_info.allocationSize = memory_reqs.size;
15490 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15491 ASSERT_TRUE(pass);
15492
15493 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15494 ASSERT_VK_SUCCESS(err);
15495 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15496 ASSERT_VK_SUCCESS(err);
15497
15498 VkBufferViewCreateInfo buff_view_ci = {};
15499 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15500 buff_view_ci.buffer = buffer;
15501 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15502 buff_view_ci.range = VK_WHOLE_SIZE;
15503 VkBufferView buffer_view;
15504 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15505
15506 VkDescriptorPoolSize ds_type_count = {};
15507 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15508 ds_type_count.descriptorCount = 1;
15509
15510 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15511 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15512 ds_pool_ci.pNext = NULL;
15513 ds_pool_ci.maxSets = 1;
15514 ds_pool_ci.poolSizeCount = 1;
15515 ds_pool_ci.pPoolSizes = &ds_type_count;
15516
15517 VkDescriptorPool ds_pool;
15518 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15519 ASSERT_VK_SUCCESS(err);
15520
15521 VkDescriptorSetLayoutBinding dsl_binding = {};
15522 dsl_binding.binding = 0;
15523 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15524 dsl_binding.descriptorCount = 1;
15525 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15526 dsl_binding.pImmutableSamplers = NULL;
15527
15528 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15529 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15530 ds_layout_ci.pNext = NULL;
15531 ds_layout_ci.bindingCount = 1;
15532 ds_layout_ci.pBindings = &dsl_binding;
15533 VkDescriptorSetLayout ds_layout;
15534 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15535 ASSERT_VK_SUCCESS(err);
15536
15537 VkDescriptorSet descriptor_set;
15538 VkDescriptorSetAllocateInfo alloc_info = {};
15539 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15540 alloc_info.descriptorSetCount = 1;
15541 alloc_info.descriptorPool = ds_pool;
15542 alloc_info.pSetLayouts = &ds_layout;
15543 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15544 ASSERT_VK_SUCCESS(err);
15545
15546 VkWriteDescriptorSet descriptor_write;
15547 memset(&descriptor_write, 0, sizeof(descriptor_write));
15548 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15549 descriptor_write.dstSet = descriptor_set;
15550 descriptor_write.dstBinding = 0;
15551 descriptor_write.descriptorCount = 1;
15552 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15553 descriptor_write.pTexelBufferView = &buffer_view;
15554
15555 // Set pImageInfo and pBufferInfo to invalid values, which should be
15556 // ignored for descriptorType ==
15557 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15558 // This will most likely produce a crash if the parameter_validation
15559 // layer
15560 // does not correctly ignore pImageInfo and pBufferInfo.
15561 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15562 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15563
15564 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15565
15566 m_errorMonitor->VerifyNotFound();
15567
15568 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15569 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15570 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15571 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15572 vkDestroyBuffer(m_device->device(), buffer, NULL);
15573 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15574 }
15575}
15576
15577// This is a positive test. No failures are expected.
15578TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15579 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15580 VkResult err;
15581
15582 ASSERT_NO_FATAL_FAILURE(InitState());
15583 m_errorMonitor->ExpectSuccess();
15584 VkDescriptorPoolSize ds_type_count = {};
15585 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15586 ds_type_count.descriptorCount = 2;
15587
15588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15590 ds_pool_ci.pNext = NULL;
15591 ds_pool_ci.maxSets = 1;
15592 ds_pool_ci.poolSizeCount = 1;
15593 ds_pool_ci.pPoolSizes = &ds_type_count;
15594
15595 VkDescriptorPool ds_pool;
15596 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15597 ASSERT_VK_SUCCESS(err);
15598
15599 // Create layout with two uniform buffer descriptors w/ empty binding between them
15600 static const uint32_t NUM_BINDINGS = 3;
15601 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15602 dsl_binding[0].binding = 0;
15603 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15604 dsl_binding[0].descriptorCount = 1;
15605 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15606 dsl_binding[0].pImmutableSamplers = NULL;
15607 dsl_binding[1].binding = 1;
15608 dsl_binding[1].descriptorCount = 0; // empty binding
15609 dsl_binding[2].binding = 2;
15610 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15611 dsl_binding[2].descriptorCount = 1;
15612 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15613 dsl_binding[2].pImmutableSamplers = NULL;
15614
15615 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15616 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15617 ds_layout_ci.pNext = NULL;
15618 ds_layout_ci.bindingCount = NUM_BINDINGS;
15619 ds_layout_ci.pBindings = dsl_binding;
15620 VkDescriptorSetLayout ds_layout;
15621 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15622 ASSERT_VK_SUCCESS(err);
15623
15624 VkDescriptorSet descriptor_set = {};
15625 VkDescriptorSetAllocateInfo alloc_info = {};
15626 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15627 alloc_info.descriptorSetCount = 1;
15628 alloc_info.descriptorPool = ds_pool;
15629 alloc_info.pSetLayouts = &ds_layout;
15630 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15631 ASSERT_VK_SUCCESS(err);
15632
15633 // Create a buffer to be used for update
15634 VkBufferCreateInfo buff_ci = {};
15635 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15636 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15637 buff_ci.size = 256;
15638 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15639 VkBuffer buffer;
15640 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15641 ASSERT_VK_SUCCESS(err);
15642 // Have to bind memory to buffer before descriptor update
15643 VkMemoryAllocateInfo mem_alloc = {};
15644 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15645 mem_alloc.pNext = NULL;
15646 mem_alloc.allocationSize = 512; // one allocation for both buffers
15647 mem_alloc.memoryTypeIndex = 0;
15648
15649 VkMemoryRequirements mem_reqs;
15650 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15651 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
15652 if (!pass) {
15653 vkDestroyBuffer(m_device->device(), buffer, NULL);
15654 return;
15655 }
15656
15657 VkDeviceMemory mem;
15658 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
15659 ASSERT_VK_SUCCESS(err);
15660 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15661 ASSERT_VK_SUCCESS(err);
15662
15663 // Only update the descriptor at binding 2
15664 VkDescriptorBufferInfo buff_info = {};
15665 buff_info.buffer = buffer;
15666 buff_info.offset = 0;
15667 buff_info.range = VK_WHOLE_SIZE;
15668 VkWriteDescriptorSet descriptor_write = {};
15669 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15670 descriptor_write.dstBinding = 2;
15671 descriptor_write.descriptorCount = 1;
15672 descriptor_write.pTexelBufferView = nullptr;
15673 descriptor_write.pBufferInfo = &buff_info;
15674 descriptor_write.pImageInfo = nullptr;
15675 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15676 descriptor_write.dstSet = descriptor_set;
15677
15678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15679
15680 m_errorMonitor->VerifyNotFound();
15681 // Cleanup
15682 vkFreeMemory(m_device->device(), mem, NULL);
15683 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15684 vkDestroyBuffer(m_device->device(), buffer, NULL);
15685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15686}
15687
15688// This is a positive test. No failures are expected.
15689TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
15690 VkResult err;
15691 bool pass;
15692
15693 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
15694 "the buffer, create an image, and bind the same memory to "
15695 "it");
15696
15697 m_errorMonitor->ExpectSuccess();
15698
15699 ASSERT_NO_FATAL_FAILURE(InitState());
15700
15701 VkBuffer buffer;
15702 VkImage image;
15703 VkDeviceMemory mem;
15704 VkMemoryRequirements mem_reqs;
15705
15706 VkBufferCreateInfo buf_info = {};
15707 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15708 buf_info.pNext = NULL;
15709 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15710 buf_info.size = 256;
15711 buf_info.queueFamilyIndexCount = 0;
15712 buf_info.pQueueFamilyIndices = NULL;
15713 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15714 buf_info.flags = 0;
15715 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
15716 ASSERT_VK_SUCCESS(err);
15717
15718 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15719
15720 VkMemoryAllocateInfo alloc_info = {};
15721 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15722 alloc_info.pNext = NULL;
15723 alloc_info.memoryTypeIndex = 0;
15724
15725 // Ensure memory is big enough for both bindings
15726 alloc_info.allocationSize = 0x10000;
15727
15728 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15729 if (!pass) {
15730 vkDestroyBuffer(m_device->device(), buffer, NULL);
15731 return;
15732 }
15733
15734 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
15735 ASSERT_VK_SUCCESS(err);
15736
15737 uint8_t *pData;
15738 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
15739 ASSERT_VK_SUCCESS(err);
15740
15741 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
15742
15743 vkUnmapMemory(m_device->device(), mem);
15744
15745 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15746 ASSERT_VK_SUCCESS(err);
15747
15748 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
15749 // memory. In fact, it was never used by the GPU.
15750 // Just be be sure, wait for idle.
15751 vkDestroyBuffer(m_device->device(), buffer, NULL);
15752 vkDeviceWaitIdle(m_device->device());
15753
15754 VkImageCreateInfo image_create_info = {};
15755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15756 image_create_info.pNext = NULL;
15757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15758 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
15759 image_create_info.extent.width = 64;
15760 image_create_info.extent.height = 64;
15761 image_create_info.extent.depth = 1;
15762 image_create_info.mipLevels = 1;
15763 image_create_info.arrayLayers = 1;
15764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15765 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15766 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
15767 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15768 image_create_info.queueFamilyIndexCount = 0;
15769 image_create_info.pQueueFamilyIndices = NULL;
15770 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15771 image_create_info.flags = 0;
15772
15773 VkMemoryAllocateInfo mem_alloc = {};
15774 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15775 mem_alloc.pNext = NULL;
15776 mem_alloc.allocationSize = 0;
15777 mem_alloc.memoryTypeIndex = 0;
15778
15779 /* Create a mappable image. It will be the texture if linear images are ok
15780 * to be textures or it will be the staging image if they are not.
15781 */
15782 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15783 ASSERT_VK_SUCCESS(err);
15784
15785 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
15786
15787 mem_alloc.allocationSize = mem_reqs.size;
15788
15789 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15790 if (!pass) {
15791 vkDestroyImage(m_device->device(), image, NULL);
15792 return;
15793 }
15794
15795 // VALIDATION FAILURE:
15796 err = vkBindImageMemory(m_device->device(), image, mem, 0);
15797 ASSERT_VK_SUCCESS(err);
15798
15799 m_errorMonitor->VerifyNotFound();
15800
15801 vkFreeMemory(m_device->device(), mem, NULL);
15802 vkDestroyBuffer(m_device->device(), buffer, NULL);
15803 vkDestroyImage(m_device->device(), image, NULL);
15804}
15805
15806TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
15807
15808 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
15809 "mapping while using VK_WHOLE_SIZE does not cause access "
15810 "violations");
15811 VkResult err;
15812 uint8_t *pData;
15813 ASSERT_NO_FATAL_FAILURE(InitState());
15814
15815 VkDeviceMemory mem;
15816 VkMemoryRequirements mem_reqs;
15817 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
15818 VkMemoryAllocateInfo alloc_info = {};
15819 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15820 alloc_info.pNext = NULL;
15821 alloc_info.memoryTypeIndex = 0;
15822
15823 static const VkDeviceSize allocation_size = 0x1000;
15824 alloc_info.allocationSize = allocation_size;
15825
15826 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
15827 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
15828 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
15829 if (!pass) {
15830 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
15831 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
15832 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
15833 if (!pass) {
15834 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
15835 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
15836 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
15837 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
15838 if (!pass) {
15839 return;
15840 }
15841 }
15842 }
15843
15844 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
15845 ASSERT_VK_SUCCESS(err);
15846
15847 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
15848 // mapped range
15849 m_errorMonitor->ExpectSuccess();
15850 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
15851 ASSERT_VK_SUCCESS(err);
15852 VkMappedMemoryRange mmr = {};
15853 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15854 mmr.memory = mem;
15855 mmr.offset = 0;
15856 mmr.size = VK_WHOLE_SIZE;
15857 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15858 ASSERT_VK_SUCCESS(err);
15859 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
15860 ASSERT_VK_SUCCESS(err);
15861 m_errorMonitor->VerifyNotFound();
15862 vkUnmapMemory(m_device->device(), mem);
15863
15864 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
15865 // mapped range
15866 m_errorMonitor->ExpectSuccess();
15867 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
15868 ASSERT_VK_SUCCESS(err);
15869 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15870 mmr.memory = mem;
15871 mmr.offset = 13;
15872 mmr.size = VK_WHOLE_SIZE;
15873 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15874 ASSERT_VK_SUCCESS(err);
15875 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
15876 ASSERT_VK_SUCCESS(err);
15877 m_errorMonitor->VerifyNotFound();
15878 vkUnmapMemory(m_device->device(), mem);
15879
15880 // Map with prime offset and size
15881 // Flush/Invalidate subrange of mapped area with prime offset and size
15882 m_errorMonitor->ExpectSuccess();
15883 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
15884 ASSERT_VK_SUCCESS(err);
15885 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15886 mmr.memory = mem;
15887 mmr.offset = allocation_size - 107;
15888 mmr.size = 61;
15889 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15890 ASSERT_VK_SUCCESS(err);
15891 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
15892 ASSERT_VK_SUCCESS(err);
15893 m_errorMonitor->VerifyNotFound();
15894 vkUnmapMemory(m_device->device(), mem);
15895
15896 // Map without offset and flush WHOLE_SIZE with two separate offsets
15897 m_errorMonitor->ExpectSuccess();
15898 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
15899 ASSERT_VK_SUCCESS(err);
15900 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
15901 mmr.memory = mem;
15902 mmr.offset = allocation_size - 100;
15903 mmr.size = VK_WHOLE_SIZE;
15904 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15905 ASSERT_VK_SUCCESS(err);
15906 mmr.offset = allocation_size - 200;
15907 mmr.size = VK_WHOLE_SIZE;
15908 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
15909 ASSERT_VK_SUCCESS(err);
15910 m_errorMonitor->VerifyNotFound();
15911 vkUnmapMemory(m_device->device(), mem);
15912
15913 vkFreeMemory(m_device->device(), mem, NULL);
15914}
15915
15916// This is a positive test. We used to expect error in this case but spec now allows it
15917TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
15918 m_errorMonitor->ExpectSuccess();
15919 vk_testing::Fence testFence;
15920 VkFenceCreateInfo fenceInfo = {};
15921 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
15922 fenceInfo.pNext = NULL;
15923
15924 ASSERT_NO_FATAL_FAILURE(InitState());
15925 testFence.init(*m_device, fenceInfo);
15926 VkFence fences[1] = { testFence.handle() };
15927 VkResult result = vkResetFences(m_device->device(), 1, fences);
15928 ASSERT_VK_SUCCESS(result);
15929
15930 m_errorMonitor->VerifyNotFound();
15931}
15932
15933TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
15934 m_errorMonitor->ExpectSuccess();
15935
15936 ASSERT_NO_FATAL_FAILURE(InitState());
15937 VkResult err;
15938
15939 // Record (empty!) command buffer that can be submitted multiple times
15940 // simultaneously.
15941 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
15942 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
15943 m_commandBuffer->BeginCommandBuffer(&cbbi);
15944 m_commandBuffer->EndCommandBuffer();
15945
15946 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
15947 VkFence fence;
15948 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
15949 ASSERT_VK_SUCCESS(err);
15950
15951 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
15952 VkSemaphore s1, s2;
15953 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
15954 ASSERT_VK_SUCCESS(err);
15955 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
15956 ASSERT_VK_SUCCESS(err);
15957
15958 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
15959 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
15960 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
15961 ASSERT_VK_SUCCESS(err);
15962
15963 // Submit CB again, signaling s2.
15964 si.pSignalSemaphores = &s2;
15965 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
15966 ASSERT_VK_SUCCESS(err);
15967
15968 // Wait for fence.
15969 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
15970 ASSERT_VK_SUCCESS(err);
15971
15972 // CB is still in flight from second submission, but semaphore s1 is no
15973 // longer in flight. delete it.
15974 vkDestroySemaphore(m_device->device(), s1, nullptr);
15975
15976 m_errorMonitor->VerifyNotFound();
15977
15978 // Force device idle and clean up remaining objects
15979 vkDeviceWaitIdle(m_device->device());
15980 vkDestroySemaphore(m_device->device(), s2, nullptr);
15981 vkDestroyFence(m_device->device(), fence, nullptr);
15982}
15983
15984TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
15985 m_errorMonitor->ExpectSuccess();
15986
15987 ASSERT_NO_FATAL_FAILURE(InitState());
15988 VkResult err;
15989
15990 // A fence created signaled
15991 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
15992 VkFence f1;
15993 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
15994 ASSERT_VK_SUCCESS(err);
15995
15996 // A fence created not
15997 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
15998 VkFence f2;
15999 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16000 ASSERT_VK_SUCCESS(err);
16001
16002 // Submit the unsignaled fence
16003 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16004 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16005
16006 // Wait on both fences, with signaled first.
16007 VkFence fences[] = { f1, f2 };
16008 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16009
16010 // Should have both retired!
16011 vkDestroyFence(m_device->device(), f1, nullptr);
16012 vkDestroyFence(m_device->device(), f2, nullptr);
16013
16014 m_errorMonitor->VerifyNotFound();
16015}
16016
16017TEST_F(VkPositiveLayerTest, ValidUsage) {
16018 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16019 "doesn't generate validation errors");
16020
16021 ASSERT_NO_FATAL_FAILURE(InitState());
16022
16023 m_errorMonitor->ExpectSuccess();
16024 // Verify that we can create a view with usage INPUT_ATTACHMENT
16025 VkImageObj image(m_device);
16026 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16027 ASSERT_TRUE(image.initialized());
16028 VkImageView imageView;
16029 VkImageViewCreateInfo ivci = {};
16030 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16031 ivci.image = image.handle();
16032 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16033 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16034 ivci.subresourceRange.layerCount = 1;
16035 ivci.subresourceRange.baseMipLevel = 0;
16036 ivci.subresourceRange.levelCount = 1;
16037 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16038
16039 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16040 m_errorMonitor->VerifyNotFound();
16041 vkDestroyImageView(m_device->device(), imageView, NULL);
16042}
16043
16044// This is a positive test. No failures are expected.
16045TEST_F(VkPositiveLayerTest, BindSparse) {
16046 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16047 "and then free the memory");
16048
16049 ASSERT_NO_FATAL_FAILURE(InitState());
16050
16051 auto index = m_device->graphics_queue_node_index_;
16052 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16053 return;
16054
16055 m_errorMonitor->ExpectSuccess();
16056
16057 VkImage image;
16058 VkImageCreateInfo image_create_info = {};
16059 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16060 image_create_info.pNext = NULL;
16061 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16062 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16063 image_create_info.extent.width = 64;
16064 image_create_info.extent.height = 64;
16065 image_create_info.extent.depth = 1;
16066 image_create_info.mipLevels = 1;
16067 image_create_info.arrayLayers = 1;
16068 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16069 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16070 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16071 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16072 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16073 ASSERT_VK_SUCCESS(err);
16074
16075 VkMemoryRequirements memory_reqs;
16076 VkDeviceMemory memory_one, memory_two;
16077 bool pass;
16078 VkMemoryAllocateInfo memory_info = {};
16079 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16080 memory_info.pNext = NULL;
16081 memory_info.allocationSize = 0;
16082 memory_info.memoryTypeIndex = 0;
16083 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16084 // Find an image big enough to allow sparse mapping of 2 memory regions
16085 // Increase the image size until it is at least twice the
16086 // size of the required alignment, to ensure we can bind both
16087 // allocated memory blocks to the image on aligned offsets.
16088 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16089 vkDestroyImage(m_device->device(), image, nullptr);
16090 image_create_info.extent.width *= 2;
16091 image_create_info.extent.height *= 2;
16092 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16093 ASSERT_VK_SUCCESS(err);
16094 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16095 }
16096 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16097 // at the end of the first
16098 memory_info.allocationSize = memory_reqs.alignment;
16099 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16100 ASSERT_TRUE(pass);
16101 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16102 ASSERT_VK_SUCCESS(err);
16103 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16104 ASSERT_VK_SUCCESS(err);
16105 VkSparseMemoryBind binds[2];
16106 binds[0].flags = 0;
16107 binds[0].memory = memory_one;
16108 binds[0].memoryOffset = 0;
16109 binds[0].resourceOffset = 0;
16110 binds[0].size = memory_info.allocationSize;
16111 binds[1].flags = 0;
16112 binds[1].memory = memory_two;
16113 binds[1].memoryOffset = 0;
16114 binds[1].resourceOffset = memory_info.allocationSize;
16115 binds[1].size = memory_info.allocationSize;
16116
16117 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16118 opaqueBindInfo.image = image;
16119 opaqueBindInfo.bindCount = 2;
16120 opaqueBindInfo.pBinds = binds;
16121
16122 VkFence fence = VK_NULL_HANDLE;
16123 VkBindSparseInfo bindSparseInfo = {};
16124 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16125 bindSparseInfo.imageOpaqueBindCount = 1;
16126 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16127
16128 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16129 vkQueueWaitIdle(m_device->m_queue);
16130 vkDestroyImage(m_device->device(), image, NULL);
16131 vkFreeMemory(m_device->device(), memory_one, NULL);
16132 vkFreeMemory(m_device->device(), memory_two, NULL);
16133 m_errorMonitor->VerifyNotFound();
16134}
16135
16136TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16137 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16138 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16139 "the command buffer has prior knowledge of that "
16140 "attachment's layout.");
16141
16142 m_errorMonitor->ExpectSuccess();
16143
16144 ASSERT_NO_FATAL_FAILURE(InitState());
16145
16146 // A renderpass with one color attachment.
16147 VkAttachmentDescription attachment = { 0,
16148 VK_FORMAT_R8G8B8A8_UNORM,
16149 VK_SAMPLE_COUNT_1_BIT,
16150 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16151 VK_ATTACHMENT_STORE_OP_STORE,
16152 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16153 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16154 VK_IMAGE_LAYOUT_UNDEFINED,
16155 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16156
16157 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16158
16159 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16160
16161 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16162
16163 VkRenderPass rp;
16164 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16165 ASSERT_VK_SUCCESS(err);
16166
16167 // A compatible framebuffer.
16168 VkImageObj image(m_device);
16169 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16170 ASSERT_TRUE(image.initialized());
16171
16172 VkImageViewCreateInfo ivci = {
16173 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16174 nullptr,
16175 0,
16176 image.handle(),
16177 VK_IMAGE_VIEW_TYPE_2D,
16178 VK_FORMAT_R8G8B8A8_UNORM,
16179 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16180 VK_COMPONENT_SWIZZLE_IDENTITY },
16181 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16182 };
16183 VkImageView view;
16184 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16185 ASSERT_VK_SUCCESS(err);
16186
16187 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16188 VkFramebuffer fb;
16189 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16190 ASSERT_VK_SUCCESS(err);
16191
16192 // Record a single command buffer which uses this renderpass twice. The
16193 // bug is triggered at the beginning of the second renderpass, when the
16194 // command buffer already has a layout recorded for the attachment.
16195 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16196 BeginCommandBuffer();
16197 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16198 vkCmdEndRenderPass(m_commandBuffer->handle());
16199 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16200
16201 m_errorMonitor->VerifyNotFound();
16202
16203 vkCmdEndRenderPass(m_commandBuffer->handle());
16204 EndCommandBuffer();
16205
16206 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16207 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16208 vkDestroyImageView(m_device->device(), view, nullptr);
16209}
16210
16211TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16212 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16213 "command buffer, bind them together, then destroy "
16214 "command pool and framebuffer and verify there are no "
16215 "errors.");
16216
16217 m_errorMonitor->ExpectSuccess();
16218
16219 ASSERT_NO_FATAL_FAILURE(InitState());
16220
16221 // A renderpass with one color attachment.
16222 VkAttachmentDescription attachment = { 0,
16223 VK_FORMAT_R8G8B8A8_UNORM,
16224 VK_SAMPLE_COUNT_1_BIT,
16225 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16226 VK_ATTACHMENT_STORE_OP_STORE,
16227 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16228 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16229 VK_IMAGE_LAYOUT_UNDEFINED,
16230 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16231
16232 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16233
16234 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16235
16236 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16237
16238 VkRenderPass rp;
16239 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16240 ASSERT_VK_SUCCESS(err);
16241
16242 // A compatible framebuffer.
16243 VkImageObj image(m_device);
16244 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16245 ASSERT_TRUE(image.initialized());
16246
16247 VkImageViewCreateInfo ivci = {
16248 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16249 nullptr,
16250 0,
16251 image.handle(),
16252 VK_IMAGE_VIEW_TYPE_2D,
16253 VK_FORMAT_R8G8B8A8_UNORM,
16254 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16255 VK_COMPONENT_SWIZZLE_IDENTITY },
16256 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16257 };
16258 VkImageView view;
16259 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16260 ASSERT_VK_SUCCESS(err);
16261
16262 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16263 VkFramebuffer fb;
16264 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16265 ASSERT_VK_SUCCESS(err);
16266
16267 // Explicitly create a command buffer to bind the FB to so that we can then
16268 // destroy the command pool in order to implicitly free command buffer
16269 VkCommandPool command_pool;
16270 VkCommandPoolCreateInfo pool_create_info{};
16271 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16272 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16273 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16274 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16275
16276 VkCommandBuffer command_buffer;
16277 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16278 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16279 command_buffer_allocate_info.commandPool = command_pool;
16280 command_buffer_allocate_info.commandBufferCount = 1;
16281 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16282 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16283
16284 // Begin our cmd buffer with renderpass using our framebuffer
16285 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16286 VkCommandBufferBeginInfo begin_info{};
16287 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16288 vkBeginCommandBuffer(command_buffer, &begin_info);
16289
16290 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16291 vkCmdEndRenderPass(command_buffer);
16292 vkEndCommandBuffer(command_buffer);
16293 vkDestroyImageView(m_device->device(), view, nullptr);
16294 // Destroy command pool to implicitly free command buffer
16295 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16296 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16297 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16298 m_errorMonitor->VerifyNotFound();
16299}
16300
16301TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16302 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16303 "transitions for the first subpass");
16304
16305 m_errorMonitor->ExpectSuccess();
16306
16307 ASSERT_NO_FATAL_FAILURE(InitState());
16308
16309 // A renderpass with one color attachment.
16310 VkAttachmentDescription attachment = { 0,
16311 VK_FORMAT_R8G8B8A8_UNORM,
16312 VK_SAMPLE_COUNT_1_BIT,
16313 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16314 VK_ATTACHMENT_STORE_OP_STORE,
16315 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16316 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16317 VK_IMAGE_LAYOUT_UNDEFINED,
16318 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16319
16320 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16321
16322 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16323
16324 VkSubpassDependency dep = { 0,
16325 0,
16326 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16327 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16328 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16329 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16330 VK_DEPENDENCY_BY_REGION_BIT };
16331
16332 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16333
16334 VkResult err;
16335 VkRenderPass rp;
16336 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16337 ASSERT_VK_SUCCESS(err);
16338
16339 // A compatible framebuffer.
16340 VkImageObj image(m_device);
16341 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16342 ASSERT_TRUE(image.initialized());
16343
16344 VkImageViewCreateInfo ivci = {
16345 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16346 nullptr,
16347 0,
16348 image.handle(),
16349 VK_IMAGE_VIEW_TYPE_2D,
16350 VK_FORMAT_R8G8B8A8_UNORM,
16351 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16352 VK_COMPONENT_SWIZZLE_IDENTITY },
16353 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16354 };
16355 VkImageView view;
16356 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16357 ASSERT_VK_SUCCESS(err);
16358
16359 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16360 VkFramebuffer fb;
16361 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16362 ASSERT_VK_SUCCESS(err);
16363
16364 // Record a single command buffer which issues a pipeline barrier w/
16365 // image memory barrier for the attachment. This detects the previously
16366 // missing tracking of the subpass layout by throwing a validation error
16367 // if it doesn't occur.
16368 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16369 BeginCommandBuffer();
16370 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16371
16372 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16373 nullptr,
16374 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16375 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16376 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16377 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16378 VK_QUEUE_FAMILY_IGNORED,
16379 VK_QUEUE_FAMILY_IGNORED,
16380 image.handle(),
16381 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16382 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16383 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16384 &imb);
16385
16386 vkCmdEndRenderPass(m_commandBuffer->handle());
16387 m_errorMonitor->VerifyNotFound();
16388 EndCommandBuffer();
16389
16390 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16391 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16392 vkDestroyImageView(m_device->device(), view, nullptr);
16393}
16394
16395TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16396 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16397 "is used as a depth/stencil framebuffer attachment, the "
16398 "aspectMask is ignored and both depth and stencil image "
16399 "subresources are used.");
16400
16401 VkFormatProperties format_properties;
16402 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16403 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16404 return;
16405 }
16406
16407 m_errorMonitor->ExpectSuccess();
16408
16409 ASSERT_NO_FATAL_FAILURE(InitState());
16410
16411 VkAttachmentDescription attachment = { 0,
16412 VK_FORMAT_D32_SFLOAT_S8_UINT,
16413 VK_SAMPLE_COUNT_1_BIT,
16414 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16415 VK_ATTACHMENT_STORE_OP_STORE,
16416 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16417 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16418 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16419 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16420
16421 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16422
16423 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16424
16425 VkSubpassDependency dep = { 0,
16426 0,
16427 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16428 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16429 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16430 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16431 VK_DEPENDENCY_BY_REGION_BIT};
16432
16433 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16434
16435 VkResult err;
16436 VkRenderPass rp;
16437 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16438 ASSERT_VK_SUCCESS(err);
16439
16440 VkImageObj image(m_device);
16441 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16442 0x26, // usage
16443 VK_IMAGE_TILING_OPTIMAL, 0);
16444 ASSERT_TRUE(image.initialized());
16445 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16446
16447 VkImageViewCreateInfo ivci = {
16448 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16449 nullptr,
16450 0,
16451 image.handle(),
16452 VK_IMAGE_VIEW_TYPE_2D,
16453 VK_FORMAT_D32_SFLOAT_S8_UINT,
16454 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16455 { 0x2, 0, 1, 0, 1 },
16456 };
16457 VkImageView view;
16458 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16459 ASSERT_VK_SUCCESS(err);
16460
16461 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16462 VkFramebuffer fb;
16463 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16464 ASSERT_VK_SUCCESS(err);
16465
16466 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16467 BeginCommandBuffer();
16468 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16469
16470 VkImageMemoryBarrier imb = {};
16471 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16472 imb.pNext = nullptr;
16473 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16474 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16475 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16476 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16477 imb.srcQueueFamilyIndex = 0;
16478 imb.dstQueueFamilyIndex = 0;
16479 imb.image = image.handle();
16480 imb.subresourceRange.aspectMask = 0x6;
16481 imb.subresourceRange.baseMipLevel = 0;
16482 imb.subresourceRange.levelCount = 0x1;
16483 imb.subresourceRange.baseArrayLayer = 0;
16484 imb.subresourceRange.layerCount = 0x1;
16485
16486 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16487 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16488 &imb);
16489
16490 vkCmdEndRenderPass(m_commandBuffer->handle());
16491 EndCommandBuffer();
16492 QueueCommandBuffer(false);
16493 m_errorMonitor->VerifyNotFound();
16494
16495 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16496 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16497 vkDestroyImageView(m_device->device(), view, nullptr);
16498}
16499
16500TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16501 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16502 "errors, when an attachment reference is "
16503 "VK_ATTACHMENT_UNUSED");
16504
16505 m_errorMonitor->ExpectSuccess();
16506
16507 ASSERT_NO_FATAL_FAILURE(InitState());
16508
16509 // A renderpass with no attachments
16510 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16511
16512 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16513
16514 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16515
16516 VkRenderPass rp;
16517 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16518 ASSERT_VK_SUCCESS(err);
16519
16520 // A compatible framebuffer.
16521 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16522 VkFramebuffer fb;
16523 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16524 ASSERT_VK_SUCCESS(err);
16525
16526 // Record a command buffer which just begins and ends the renderpass. The
16527 // bug manifests in BeginRenderPass.
16528 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16529 BeginCommandBuffer();
16530 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16531 vkCmdEndRenderPass(m_commandBuffer->handle());
16532 m_errorMonitor->VerifyNotFound();
16533 EndCommandBuffer();
16534
16535 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16536 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16537}
16538
16539// This is a positive test. No errors are expected.
16540TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16541 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16542 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16543 VkResult result = VK_SUCCESS;
16544 VkImageFormatProperties formatProps;
16545 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16546 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16547 &formatProps);
16548 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16549 return;
16550 }
16551
16552 ASSERT_NO_FATAL_FAILURE(InitState());
16553 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16554 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16555 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16556 VkAttachmentDescription att = {};
16557 VkAttachmentReference ref = {};
16558 att.format = depth_stencil_fmt;
16559 att.samples = VK_SAMPLE_COUNT_1_BIT;
16560 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16561 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16562 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16563 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16564 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16565 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16566
16567 VkClearValue clear;
16568 clear.depthStencil.depth = 1.0;
16569 clear.depthStencil.stencil = 0;
16570 ref.attachment = 0;
16571 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16572
16573 VkSubpassDescription subpass = {};
16574 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16575 subpass.flags = 0;
16576 subpass.inputAttachmentCount = 0;
16577 subpass.pInputAttachments = NULL;
16578 subpass.colorAttachmentCount = 0;
16579 subpass.pColorAttachments = NULL;
16580 subpass.pResolveAttachments = NULL;
16581 subpass.pDepthStencilAttachment = &ref;
16582 subpass.preserveAttachmentCount = 0;
16583 subpass.pPreserveAttachments = NULL;
16584
16585 VkRenderPass rp;
16586 VkRenderPassCreateInfo rp_info = {};
16587 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16588 rp_info.attachmentCount = 1;
16589 rp_info.pAttachments = &att;
16590 rp_info.subpassCount = 1;
16591 rp_info.pSubpasses = &subpass;
16592 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16593 ASSERT_VK_SUCCESS(result);
16594
16595 VkImageView *depthView = m_depthStencil->BindInfo();
16596 VkFramebufferCreateInfo fb_info = {};
16597 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16598 fb_info.pNext = NULL;
16599 fb_info.renderPass = rp;
16600 fb_info.attachmentCount = 1;
16601 fb_info.pAttachments = depthView;
16602 fb_info.width = 100;
16603 fb_info.height = 100;
16604 fb_info.layers = 1;
16605 VkFramebuffer fb;
16606 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16607 ASSERT_VK_SUCCESS(result);
16608
16609 VkRenderPassBeginInfo rpbinfo = {};
16610 rpbinfo.clearValueCount = 1;
16611 rpbinfo.pClearValues = &clear;
16612 rpbinfo.pNext = NULL;
16613 rpbinfo.renderPass = rp;
16614 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16615 rpbinfo.renderArea.extent.width = 100;
16616 rpbinfo.renderArea.extent.height = 100;
16617 rpbinfo.renderArea.offset.x = 0;
16618 rpbinfo.renderArea.offset.y = 0;
16619 rpbinfo.framebuffer = fb;
16620
16621 VkFence fence = {};
16622 VkFenceCreateInfo fence_ci = {};
16623 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16624 fence_ci.pNext = nullptr;
16625 fence_ci.flags = 0;
16626 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16627 ASSERT_VK_SUCCESS(result);
16628
16629 m_commandBuffer->BeginCommandBuffer();
16630 m_commandBuffer->BeginRenderPass(rpbinfo);
16631 m_commandBuffer->EndRenderPass();
16632 m_commandBuffer->EndCommandBuffer();
16633 m_commandBuffer->QueueCommandBuffer(fence);
16634
16635 VkImageObj destImage(m_device);
16636 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16637 VK_IMAGE_TILING_OPTIMAL, 0);
16638 VkImageMemoryBarrier barrier = {};
16639 VkImageSubresourceRange range;
16640 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16641 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16642 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16643 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16644 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16645 barrier.image = m_depthStencil->handle();
16646 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16647 range.baseMipLevel = 0;
16648 range.levelCount = 1;
16649 range.baseArrayLayer = 0;
16650 range.layerCount = 1;
16651 barrier.subresourceRange = range;
16652 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16653 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
16654 cmdbuf.BeginCommandBuffer();
16655 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16656 &barrier);
16657 barrier.srcAccessMask = 0;
16658 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16659 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
16660 barrier.image = destImage.handle();
16661 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16662 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16663 &barrier);
16664 VkImageCopy cregion;
16665 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16666 cregion.srcSubresource.mipLevel = 0;
16667 cregion.srcSubresource.baseArrayLayer = 0;
16668 cregion.srcSubresource.layerCount = 1;
16669 cregion.srcOffset.x = 0;
16670 cregion.srcOffset.y = 0;
16671 cregion.srcOffset.z = 0;
16672 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16673 cregion.dstSubresource.mipLevel = 0;
16674 cregion.dstSubresource.baseArrayLayer = 0;
16675 cregion.dstSubresource.layerCount = 1;
16676 cregion.dstOffset.x = 0;
16677 cregion.dstOffset.y = 0;
16678 cregion.dstOffset.z = 0;
16679 cregion.extent.width = 100;
16680 cregion.extent.height = 100;
16681 cregion.extent.depth = 1;
16682 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
16683 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
16684 cmdbuf.EndCommandBuffer();
16685
16686 VkSubmitInfo submit_info;
16687 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16688 submit_info.pNext = NULL;
16689 submit_info.waitSemaphoreCount = 0;
16690 submit_info.pWaitSemaphores = NULL;
16691 submit_info.pWaitDstStageMask = NULL;
16692 submit_info.commandBufferCount = 1;
16693 submit_info.pCommandBuffers = &cmdbuf.handle();
16694 submit_info.signalSemaphoreCount = 0;
16695 submit_info.pSignalSemaphores = NULL;
16696
16697 m_errorMonitor->ExpectSuccess();
16698 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16699 m_errorMonitor->VerifyNotFound();
16700
16701 vkQueueWaitIdle(m_device->m_queue);
16702 vkDestroyFence(m_device->device(), fence, nullptr);
16703 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16704 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16705}
16706
16707// This is a positive test. No errors should be generated.
16708TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
16709 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
16710
16711 m_errorMonitor->ExpectSuccess();
16712 ASSERT_NO_FATAL_FAILURE(InitState());
16713
16714 VkEvent event;
16715 VkEventCreateInfo event_create_info{};
16716 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
16717 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
16718
16719 VkCommandPool command_pool;
16720 VkCommandPoolCreateInfo pool_create_info{};
16721 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16722 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16723 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16724 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16725
16726 VkCommandBuffer command_buffer;
16727 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16728 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16729 command_buffer_allocate_info.commandPool = command_pool;
16730 command_buffer_allocate_info.commandBufferCount = 1;
16731 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16732 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16733
16734 VkQueue queue = VK_NULL_HANDLE;
16735 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
16736
16737 {
16738 VkCommandBufferBeginInfo begin_info{};
16739 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16740 vkBeginCommandBuffer(command_buffer, &begin_info);
16741
16742 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
16743 nullptr, 0, nullptr);
16744 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
16745 vkEndCommandBuffer(command_buffer);
16746 }
16747 {
16748 VkSubmitInfo submit_info{};
16749 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16750 submit_info.commandBufferCount = 1;
16751 submit_info.pCommandBuffers = &command_buffer;
16752 submit_info.signalSemaphoreCount = 0;
16753 submit_info.pSignalSemaphores = nullptr;
16754 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16755 }
16756 { vkSetEvent(m_device->device(), event); }
16757
16758 vkQueueWaitIdle(queue);
16759
16760 vkDestroyEvent(m_device->device(), event, nullptr);
16761 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
16762 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16763
16764 m_errorMonitor->VerifyNotFound();
16765}
16766// This is a positive test. No errors should be generated.
16767TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
16768 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
16769
16770 ASSERT_NO_FATAL_FAILURE(InitState());
16771 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
16772 return;
16773
16774 m_errorMonitor->ExpectSuccess();
16775
16776 VkQueryPool query_pool;
16777 VkQueryPoolCreateInfo query_pool_create_info{};
16778 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
16779 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
16780 query_pool_create_info.queryCount = 1;
16781 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
16782
16783 VkCommandPool command_pool;
16784 VkCommandPoolCreateInfo pool_create_info{};
16785 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16786 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16787 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16788 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16789
16790 VkCommandBuffer command_buffer;
16791 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16792 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16793 command_buffer_allocate_info.commandPool = command_pool;
16794 command_buffer_allocate_info.commandBufferCount = 1;
16795 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16796 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16797
16798 VkCommandBuffer secondary_command_buffer;
16799 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16800 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
16801
16802 VkQueue queue = VK_NULL_HANDLE;
16803 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
16804
16805 uint32_t qfi = 0;
16806 VkBufferCreateInfo buff_create_info = {};
16807 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16808 buff_create_info.size = 1024;
16809 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
16810 buff_create_info.queueFamilyIndexCount = 1;
16811 buff_create_info.pQueueFamilyIndices = &qfi;
16812
16813 VkResult err;
16814 VkBuffer buffer;
16815 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
16816 ASSERT_VK_SUCCESS(err);
16817 VkMemoryAllocateInfo mem_alloc = {};
16818 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16819 mem_alloc.pNext = NULL;
16820 mem_alloc.allocationSize = 1024;
16821 mem_alloc.memoryTypeIndex = 0;
16822
16823 VkMemoryRequirements memReqs;
16824 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
16825 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
16826 if (!pass) {
16827 vkDestroyBuffer(m_device->device(), buffer, NULL);
16828 return;
16829 }
16830
16831 VkDeviceMemory mem;
16832 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16833 ASSERT_VK_SUCCESS(err);
16834 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16835 ASSERT_VK_SUCCESS(err);
16836
16837 VkCommandBufferInheritanceInfo hinfo = {};
16838 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16839 hinfo.renderPass = VK_NULL_HANDLE;
16840 hinfo.subpass = 0;
16841 hinfo.framebuffer = VK_NULL_HANDLE;
16842 hinfo.occlusionQueryEnable = VK_FALSE;
16843 hinfo.queryFlags = 0;
16844 hinfo.pipelineStatistics = 0;
16845
16846 {
16847 VkCommandBufferBeginInfo begin_info{};
16848 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16849 begin_info.pInheritanceInfo = &hinfo;
16850 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
16851
16852 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
16853 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
16854
16855 vkEndCommandBuffer(secondary_command_buffer);
16856
16857 begin_info.pInheritanceInfo = nullptr;
16858 vkBeginCommandBuffer(command_buffer, &begin_info);
16859
16860 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
16861 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
16862
16863 vkEndCommandBuffer(command_buffer);
16864 }
16865 {
16866 VkSubmitInfo submit_info{};
16867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16868 submit_info.commandBufferCount = 1;
16869 submit_info.pCommandBuffers = &command_buffer;
16870 submit_info.signalSemaphoreCount = 0;
16871 submit_info.pSignalSemaphores = nullptr;
16872 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16873 }
16874
16875 vkQueueWaitIdle(queue);
16876
16877 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
16878 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
16879 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
16880 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16881 vkDestroyBuffer(m_device->device(), buffer, NULL);
16882 vkFreeMemory(m_device->device(), mem, NULL);
16883
16884 m_errorMonitor->VerifyNotFound();
16885}
16886
16887// This is a positive test. No errors should be generated.
16888TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
16889 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
16890
16891 ASSERT_NO_FATAL_FAILURE(InitState());
16892 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
16893 return;
16894
16895 m_errorMonitor->ExpectSuccess();
16896
16897 VkQueryPool query_pool;
16898 VkQueryPoolCreateInfo query_pool_create_info{};
16899 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
16900 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
16901 query_pool_create_info.queryCount = 1;
16902 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
16903
16904 VkCommandPool command_pool;
16905 VkCommandPoolCreateInfo pool_create_info{};
16906 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16907 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16908 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16909 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16910
16911 VkCommandBuffer command_buffer[2];
16912 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16913 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16914 command_buffer_allocate_info.commandPool = command_pool;
16915 command_buffer_allocate_info.commandBufferCount = 2;
16916 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16917 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
16918
16919 VkQueue queue = VK_NULL_HANDLE;
16920 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
16921
16922 uint32_t qfi = 0;
16923 VkBufferCreateInfo buff_create_info = {};
16924 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16925 buff_create_info.size = 1024;
16926 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
16927 buff_create_info.queueFamilyIndexCount = 1;
16928 buff_create_info.pQueueFamilyIndices = &qfi;
16929
16930 VkResult err;
16931 VkBuffer buffer;
16932 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
16933 ASSERT_VK_SUCCESS(err);
16934 VkMemoryAllocateInfo mem_alloc = {};
16935 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16936 mem_alloc.pNext = NULL;
16937 mem_alloc.allocationSize = 1024;
16938 mem_alloc.memoryTypeIndex = 0;
16939
16940 VkMemoryRequirements memReqs;
16941 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
16942 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
16943 if (!pass) {
16944 vkDestroyBuffer(m_device->device(), buffer, NULL);
16945 return;
16946 }
16947
16948 VkDeviceMemory mem;
16949 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16950 ASSERT_VK_SUCCESS(err);
16951 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16952 ASSERT_VK_SUCCESS(err);
16953
16954 {
16955 VkCommandBufferBeginInfo begin_info{};
16956 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16957 vkBeginCommandBuffer(command_buffer[0], &begin_info);
16958
16959 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
16960 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
16961
16962 vkEndCommandBuffer(command_buffer[0]);
16963
16964 vkBeginCommandBuffer(command_buffer[1], &begin_info);
16965
16966 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
16967
16968 vkEndCommandBuffer(command_buffer[1]);
16969 }
16970 {
16971 VkSubmitInfo submit_info{};
16972 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16973 submit_info.commandBufferCount = 2;
16974 submit_info.pCommandBuffers = command_buffer;
16975 submit_info.signalSemaphoreCount = 0;
16976 submit_info.pSignalSemaphores = nullptr;
16977 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16978 }
16979
16980 vkQueueWaitIdle(queue);
16981
16982 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
16983 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
16984 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16985 vkDestroyBuffer(m_device->device(), buffer, NULL);
16986 vkFreeMemory(m_device->device(), mem, NULL);
16987
16988 m_errorMonitor->VerifyNotFound();
16989}
16990
16991TEST_F(VkPositiveLayerTest, ResetEventThenSet) {
16992 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
16993
16994 m_errorMonitor->ExpectSuccess();
16995
16996 ASSERT_NO_FATAL_FAILURE(InitState());
16997 VkEvent event;
16998 VkEventCreateInfo event_create_info{};
16999 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17000 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17001
17002 VkCommandPool command_pool;
17003 VkCommandPoolCreateInfo pool_create_info{};
17004 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17005 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17006 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17007 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17008
17009 VkCommandBuffer command_buffer;
17010 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17011 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17012 command_buffer_allocate_info.commandPool = command_pool;
17013 command_buffer_allocate_info.commandBufferCount = 1;
17014 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17015 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17016
17017 VkQueue queue = VK_NULL_HANDLE;
17018 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17019
17020 {
17021 VkCommandBufferBeginInfo begin_info{};
17022 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17023 vkBeginCommandBuffer(command_buffer, &begin_info);
17024
17025 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17026 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
17027 nullptr, 0, nullptr, 0, nullptr);
17028 vkEndCommandBuffer(command_buffer);
17029 }
17030 {
17031 VkSubmitInfo submit_info{};
17032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17033 submit_info.commandBufferCount = 1;
17034 submit_info.pCommandBuffers = &command_buffer;
17035 submit_info.signalSemaphoreCount = 0;
17036 submit_info.pSignalSemaphores = nullptr;
17037 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17038 }
17039 {
17040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17041 "command buffer.");
17042 vkSetEvent(m_device->device(), event);
17043 m_errorMonitor->VerifyFound();
17044 }
17045
17046 vkQueueWaitIdle(queue);
17047
17048 vkDestroyEvent(m_device->device(), event, nullptr);
17049 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17050 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17051}
17052
17053// This is a positive test. No errors should be generated.
17054TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17055 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17056 "run through a Submit & WaitForFences cycle 3 times. This "
17057 "previously revealed a bug so running this positive test "
17058 "to prevent a regression.");
17059 m_errorMonitor->ExpectSuccess();
17060
17061 ASSERT_NO_FATAL_FAILURE(InitState());
17062 VkQueue queue = VK_NULL_HANDLE;
17063 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17064
17065 static const uint32_t NUM_OBJECTS = 2;
17066 static const uint32_t NUM_FRAMES = 3;
17067 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17068 VkFence fences[NUM_OBJECTS] = {};
17069
17070 VkCommandPool cmd_pool;
17071 VkCommandPoolCreateInfo cmd_pool_ci = {};
17072 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17073 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17074 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17075 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17076 ASSERT_VK_SUCCESS(err);
17077
17078 VkCommandBufferAllocateInfo cmd_buf_info = {};
17079 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17080 cmd_buf_info.commandPool = cmd_pool;
17081 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17082 cmd_buf_info.commandBufferCount = 1;
17083
17084 VkFenceCreateInfo fence_ci = {};
17085 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17086 fence_ci.pNext = nullptr;
17087 fence_ci.flags = 0;
17088
17089 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17090 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17091 ASSERT_VK_SUCCESS(err);
17092 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17093 ASSERT_VK_SUCCESS(err);
17094 }
17095
17096 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17097 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17098 // Create empty cmd buffer
17099 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17100 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17101
17102 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17103 ASSERT_VK_SUCCESS(err);
17104 err = vkEndCommandBuffer(cmd_buffers[obj]);
17105 ASSERT_VK_SUCCESS(err);
17106
17107 VkSubmitInfo submit_info = {};
17108 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17109 submit_info.commandBufferCount = 1;
17110 submit_info.pCommandBuffers = &cmd_buffers[obj];
17111 // Submit cmd buffer and wait for fence
17112 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17113 ASSERT_VK_SUCCESS(err);
17114 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17115 ASSERT_VK_SUCCESS(err);
17116 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17117 ASSERT_VK_SUCCESS(err);
17118 }
17119 }
17120 m_errorMonitor->VerifyNotFound();
17121 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17122 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17123 vkDestroyFence(m_device->device(), fences[i], nullptr);
17124 }
17125}
17126// This is a positive test. No errors should be generated.
17127TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17128
17129 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17130 "submitted on separate queues followed by a QueueWaitIdle.");
17131
17132 ASSERT_NO_FATAL_FAILURE(InitState());
17133 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17134 return;
17135
17136 m_errorMonitor->ExpectSuccess();
17137
17138 VkSemaphore semaphore;
17139 VkSemaphoreCreateInfo semaphore_create_info{};
17140 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17141 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17142
17143 VkCommandPool command_pool;
17144 VkCommandPoolCreateInfo pool_create_info{};
17145 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17146 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17147 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17148 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17149
17150 VkCommandBuffer command_buffer[2];
17151 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17152 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17153 command_buffer_allocate_info.commandPool = command_pool;
17154 command_buffer_allocate_info.commandBufferCount = 2;
17155 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17156 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17157
17158 VkQueue queue = VK_NULL_HANDLE;
17159 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17160
17161 {
17162 VkCommandBufferBeginInfo begin_info{};
17163 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17164 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17165
17166 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17167 nullptr, 0, nullptr, 0, nullptr);
17168
17169 VkViewport viewport{};
17170 viewport.maxDepth = 1.0f;
17171 viewport.minDepth = 0.0f;
17172 viewport.width = 512;
17173 viewport.height = 512;
17174 viewport.x = 0;
17175 viewport.y = 0;
17176 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17177 vkEndCommandBuffer(command_buffer[0]);
17178 }
17179 {
17180 VkCommandBufferBeginInfo begin_info{};
17181 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17182 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17183
17184 VkViewport viewport{};
17185 viewport.maxDepth = 1.0f;
17186 viewport.minDepth = 0.0f;
17187 viewport.width = 512;
17188 viewport.height = 512;
17189 viewport.x = 0;
17190 viewport.y = 0;
17191 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17192 vkEndCommandBuffer(command_buffer[1]);
17193 }
17194 {
17195 VkSubmitInfo submit_info{};
17196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17197 submit_info.commandBufferCount = 1;
17198 submit_info.pCommandBuffers = &command_buffer[0];
17199 submit_info.signalSemaphoreCount = 1;
17200 submit_info.pSignalSemaphores = &semaphore;
17201 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17202 }
17203 {
17204 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17205 VkSubmitInfo submit_info{};
17206 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17207 submit_info.commandBufferCount = 1;
17208 submit_info.pCommandBuffers = &command_buffer[1];
17209 submit_info.waitSemaphoreCount = 1;
17210 submit_info.pWaitSemaphores = &semaphore;
17211 submit_info.pWaitDstStageMask = flags;
17212 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17213 }
17214
17215 vkQueueWaitIdle(m_device->m_queue);
17216
17217 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17218 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17219 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17220
17221 m_errorMonitor->VerifyNotFound();
17222}
17223
17224// This is a positive test. No errors should be generated.
17225TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17226
17227 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17228 "submitted on separate queues, the second having a fence"
17229 "followed by a QueueWaitIdle.");
17230
17231 ASSERT_NO_FATAL_FAILURE(InitState());
17232 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17233 return;
17234
17235 m_errorMonitor->ExpectSuccess();
17236
17237 VkFence fence;
17238 VkFenceCreateInfo fence_create_info{};
17239 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17240 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17241
17242 VkSemaphore semaphore;
17243 VkSemaphoreCreateInfo semaphore_create_info{};
17244 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17245 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17246
17247 VkCommandPool command_pool;
17248 VkCommandPoolCreateInfo pool_create_info{};
17249 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17250 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17251 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17252 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17253
17254 VkCommandBuffer command_buffer[2];
17255 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17256 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17257 command_buffer_allocate_info.commandPool = command_pool;
17258 command_buffer_allocate_info.commandBufferCount = 2;
17259 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17260 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17261
17262 VkQueue queue = VK_NULL_HANDLE;
17263 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17264
17265 {
17266 VkCommandBufferBeginInfo begin_info{};
17267 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17268 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17269
17270 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17271 nullptr, 0, nullptr, 0, nullptr);
17272
17273 VkViewport viewport{};
17274 viewport.maxDepth = 1.0f;
17275 viewport.minDepth = 0.0f;
17276 viewport.width = 512;
17277 viewport.height = 512;
17278 viewport.x = 0;
17279 viewport.y = 0;
17280 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17281 vkEndCommandBuffer(command_buffer[0]);
17282 }
17283 {
17284 VkCommandBufferBeginInfo begin_info{};
17285 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17286 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17287
17288 VkViewport viewport{};
17289 viewport.maxDepth = 1.0f;
17290 viewport.minDepth = 0.0f;
17291 viewport.width = 512;
17292 viewport.height = 512;
17293 viewport.x = 0;
17294 viewport.y = 0;
17295 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17296 vkEndCommandBuffer(command_buffer[1]);
17297 }
17298 {
17299 VkSubmitInfo submit_info{};
17300 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17301 submit_info.commandBufferCount = 1;
17302 submit_info.pCommandBuffers = &command_buffer[0];
17303 submit_info.signalSemaphoreCount = 1;
17304 submit_info.pSignalSemaphores = &semaphore;
17305 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17306 }
17307 {
17308 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17309 VkSubmitInfo submit_info{};
17310 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17311 submit_info.commandBufferCount = 1;
17312 submit_info.pCommandBuffers = &command_buffer[1];
17313 submit_info.waitSemaphoreCount = 1;
17314 submit_info.pWaitSemaphores = &semaphore;
17315 submit_info.pWaitDstStageMask = flags;
17316 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17317 }
17318
17319 vkQueueWaitIdle(m_device->m_queue);
17320
17321 vkDestroyFence(m_device->device(), fence, nullptr);
17322 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17323 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17324 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17325
17326 m_errorMonitor->VerifyNotFound();
17327}
17328
17329// This is a positive test. No errors should be generated.
17330TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17331
17332 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17333 "submitted on separate queues, the second having a fence"
17334 "followed by two consecutive WaitForFences calls on the same fence.");
17335
17336 ASSERT_NO_FATAL_FAILURE(InitState());
17337 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17338 return;
17339
17340 m_errorMonitor->ExpectSuccess();
17341
17342 VkFence fence;
17343 VkFenceCreateInfo fence_create_info{};
17344 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17345 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17346
17347 VkSemaphore semaphore;
17348 VkSemaphoreCreateInfo semaphore_create_info{};
17349 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17350 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17351
17352 VkCommandPool command_pool;
17353 VkCommandPoolCreateInfo pool_create_info{};
17354 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17355 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17356 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17357 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17358
17359 VkCommandBuffer command_buffer[2];
17360 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17361 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17362 command_buffer_allocate_info.commandPool = command_pool;
17363 command_buffer_allocate_info.commandBufferCount = 2;
17364 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17365 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17366
17367 VkQueue queue = VK_NULL_HANDLE;
17368 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17369
17370 {
17371 VkCommandBufferBeginInfo begin_info{};
17372 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17373 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17374
17375 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17376 nullptr, 0, nullptr, 0, nullptr);
17377
17378 VkViewport viewport{};
17379 viewport.maxDepth = 1.0f;
17380 viewport.minDepth = 0.0f;
17381 viewport.width = 512;
17382 viewport.height = 512;
17383 viewport.x = 0;
17384 viewport.y = 0;
17385 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17386 vkEndCommandBuffer(command_buffer[0]);
17387 }
17388 {
17389 VkCommandBufferBeginInfo begin_info{};
17390 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17391 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17392
17393 VkViewport viewport{};
17394 viewport.maxDepth = 1.0f;
17395 viewport.minDepth = 0.0f;
17396 viewport.width = 512;
17397 viewport.height = 512;
17398 viewport.x = 0;
17399 viewport.y = 0;
17400 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17401 vkEndCommandBuffer(command_buffer[1]);
17402 }
17403 {
17404 VkSubmitInfo submit_info{};
17405 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17406 submit_info.commandBufferCount = 1;
17407 submit_info.pCommandBuffers = &command_buffer[0];
17408 submit_info.signalSemaphoreCount = 1;
17409 submit_info.pSignalSemaphores = &semaphore;
17410 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17411 }
17412 {
17413 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17414 VkSubmitInfo submit_info{};
17415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17416 submit_info.commandBufferCount = 1;
17417 submit_info.pCommandBuffers = &command_buffer[1];
17418 submit_info.waitSemaphoreCount = 1;
17419 submit_info.pWaitSemaphores = &semaphore;
17420 submit_info.pWaitDstStageMask = flags;
17421 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17422 }
17423
17424 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17425 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17426
17427 vkDestroyFence(m_device->device(), fence, nullptr);
17428 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17429 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17430 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17431
17432 m_errorMonitor->VerifyNotFound();
17433}
17434
17435TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17436
17437 ASSERT_NO_FATAL_FAILURE(InitState());
17438 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17439 printf("Test requires two queues, skipping\n");
17440 return;
17441 }
17442
17443 VkResult err;
17444
17445 m_errorMonitor->ExpectSuccess();
17446
17447 VkQueue q0 = m_device->m_queue;
17448 VkQueue q1 = nullptr;
17449 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17450 ASSERT_NE(q1, nullptr);
17451
17452 // An (empty) command buffer. We must have work in the first submission --
17453 // the layer treats unfenced work differently from fenced work.
17454 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17455 VkCommandPool pool;
17456 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17457 ASSERT_VK_SUCCESS(err);
17458 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17459 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17460 VkCommandBuffer cb;
17461 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17462 ASSERT_VK_SUCCESS(err);
17463 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17464 err = vkBeginCommandBuffer(cb, &cbbi);
17465 ASSERT_VK_SUCCESS(err);
17466 err = vkEndCommandBuffer(cb);
17467 ASSERT_VK_SUCCESS(err);
17468
17469 // A semaphore
17470 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17471 VkSemaphore s;
17472 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17473 ASSERT_VK_SUCCESS(err);
17474
17475 // First submission, to q0
17476 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17477
17478 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17479 ASSERT_VK_SUCCESS(err);
17480
17481 // Second submission, to q1, waiting on s
17482 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17483 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17484
17485 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17486 ASSERT_VK_SUCCESS(err);
17487
17488 // Wait for q0 idle
17489 err = vkQueueWaitIdle(q0);
17490 ASSERT_VK_SUCCESS(err);
17491
17492 // Command buffer should have been completed (it was on q0); reset the pool.
17493 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17494
17495 m_errorMonitor->VerifyNotFound();
17496
17497 // Force device completely idle and clean up resources
17498 vkDeviceWaitIdle(m_device->device());
17499 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17500 vkDestroySemaphore(m_device->device(), s, nullptr);
17501}
17502
17503// This is a positive test. No errors should be generated.
17504TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17505
17506 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17507 "submitted on separate queues, the second having a fence, "
17508 "followed by a WaitForFences call.");
17509
17510 ASSERT_NO_FATAL_FAILURE(InitState());
17511 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17512 return;
17513
17514 m_errorMonitor->ExpectSuccess();
17515
17516 ASSERT_NO_FATAL_FAILURE(InitState());
17517 VkFence fence;
17518 VkFenceCreateInfo fence_create_info{};
17519 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17520 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17521
17522 VkSemaphore semaphore;
17523 VkSemaphoreCreateInfo semaphore_create_info{};
17524 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17525 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17526
17527 VkCommandPool command_pool;
17528 VkCommandPoolCreateInfo pool_create_info{};
17529 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17530 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17531 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17532 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17533
17534 VkCommandBuffer command_buffer[2];
17535 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17536 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17537 command_buffer_allocate_info.commandPool = command_pool;
17538 command_buffer_allocate_info.commandBufferCount = 2;
17539 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17540 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17541
17542 VkQueue queue = VK_NULL_HANDLE;
17543 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17544
17545 {
17546 VkCommandBufferBeginInfo begin_info{};
17547 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17548 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17549
17550 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17551 nullptr, 0, nullptr, 0, nullptr);
17552
17553 VkViewport viewport{};
17554 viewport.maxDepth = 1.0f;
17555 viewport.minDepth = 0.0f;
17556 viewport.width = 512;
17557 viewport.height = 512;
17558 viewport.x = 0;
17559 viewport.y = 0;
17560 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17561 vkEndCommandBuffer(command_buffer[0]);
17562 }
17563 {
17564 VkCommandBufferBeginInfo begin_info{};
17565 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17566 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17567
17568 VkViewport viewport{};
17569 viewport.maxDepth = 1.0f;
17570 viewport.minDepth = 0.0f;
17571 viewport.width = 512;
17572 viewport.height = 512;
17573 viewport.x = 0;
17574 viewport.y = 0;
17575 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17576 vkEndCommandBuffer(command_buffer[1]);
17577 }
17578 {
17579 VkSubmitInfo submit_info{};
17580 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17581 submit_info.commandBufferCount = 1;
17582 submit_info.pCommandBuffers = &command_buffer[0];
17583 submit_info.signalSemaphoreCount = 1;
17584 submit_info.pSignalSemaphores = &semaphore;
17585 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17586 }
17587 {
17588 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17589 VkSubmitInfo submit_info{};
17590 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17591 submit_info.commandBufferCount = 1;
17592 submit_info.pCommandBuffers = &command_buffer[1];
17593 submit_info.waitSemaphoreCount = 1;
17594 submit_info.pWaitSemaphores = &semaphore;
17595 submit_info.pWaitDstStageMask = flags;
17596 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17597 }
17598
17599 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17600
17601 vkDestroyFence(m_device->device(), fence, nullptr);
17602 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17603 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17604 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17605
17606 m_errorMonitor->VerifyNotFound();
17607}
17608
17609// This is a positive test. No errors should be generated.
17610TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17611
17612 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17613 "on the same queue, sharing a signal/wait semaphore, the "
17614 "second having a fence, "
17615 "followed by a WaitForFences call.");
17616
17617 m_errorMonitor->ExpectSuccess();
17618
17619 ASSERT_NO_FATAL_FAILURE(InitState());
17620 VkFence fence;
17621 VkFenceCreateInfo fence_create_info{};
17622 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17623 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17624
17625 VkSemaphore semaphore;
17626 VkSemaphoreCreateInfo semaphore_create_info{};
17627 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17628 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17629
17630 VkCommandPool command_pool;
17631 VkCommandPoolCreateInfo pool_create_info{};
17632 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17633 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17634 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17635 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17636
17637 VkCommandBuffer command_buffer[2];
17638 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17639 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17640 command_buffer_allocate_info.commandPool = command_pool;
17641 command_buffer_allocate_info.commandBufferCount = 2;
17642 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17643 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17644
17645 {
17646 VkCommandBufferBeginInfo begin_info{};
17647 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17648 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17649
17650 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17651 nullptr, 0, nullptr, 0, nullptr);
17652
17653 VkViewport viewport{};
17654 viewport.maxDepth = 1.0f;
17655 viewport.minDepth = 0.0f;
17656 viewport.width = 512;
17657 viewport.height = 512;
17658 viewport.x = 0;
17659 viewport.y = 0;
17660 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17661 vkEndCommandBuffer(command_buffer[0]);
17662 }
17663 {
17664 VkCommandBufferBeginInfo begin_info{};
17665 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17666 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17667
17668 VkViewport viewport{};
17669 viewport.maxDepth = 1.0f;
17670 viewport.minDepth = 0.0f;
17671 viewport.width = 512;
17672 viewport.height = 512;
17673 viewport.x = 0;
17674 viewport.y = 0;
17675 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17676 vkEndCommandBuffer(command_buffer[1]);
17677 }
17678 {
17679 VkSubmitInfo submit_info{};
17680 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17681 submit_info.commandBufferCount = 1;
17682 submit_info.pCommandBuffers = &command_buffer[0];
17683 submit_info.signalSemaphoreCount = 1;
17684 submit_info.pSignalSemaphores = &semaphore;
17685 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17686 }
17687 {
17688 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17689 VkSubmitInfo submit_info{};
17690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17691 submit_info.commandBufferCount = 1;
17692 submit_info.pCommandBuffers = &command_buffer[1];
17693 submit_info.waitSemaphoreCount = 1;
17694 submit_info.pWaitSemaphores = &semaphore;
17695 submit_info.pWaitDstStageMask = flags;
17696 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17697 }
17698
17699 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17700
17701 vkDestroyFence(m_device->device(), fence, nullptr);
17702 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17703 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17704 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17705
17706 m_errorMonitor->VerifyNotFound();
17707}
17708
17709// This is a positive test. No errors should be generated.
17710TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
17711
17712 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17713 "on the same queue, no fences, followed by a third QueueSubmit with NO "
17714 "SubmitInfos but with a fence, followed by a WaitForFences call.");
17715
17716 m_errorMonitor->ExpectSuccess();
17717
17718 ASSERT_NO_FATAL_FAILURE(InitState());
17719 VkFence fence;
17720 VkFenceCreateInfo fence_create_info{};
17721 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17722 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17723
17724 VkCommandPool command_pool;
17725 VkCommandPoolCreateInfo pool_create_info{};
17726 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17727 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17728 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17729 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17730
17731 VkCommandBuffer command_buffer[2];
17732 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17733 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17734 command_buffer_allocate_info.commandPool = command_pool;
17735 command_buffer_allocate_info.commandBufferCount = 2;
17736 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17737 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17738
17739 {
17740 VkCommandBufferBeginInfo begin_info{};
17741 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17742 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17743
17744 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17745 nullptr, 0, nullptr, 0, nullptr);
17746
17747 VkViewport viewport{};
17748 viewport.maxDepth = 1.0f;
17749 viewport.minDepth = 0.0f;
17750 viewport.width = 512;
17751 viewport.height = 512;
17752 viewport.x = 0;
17753 viewport.y = 0;
17754 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17755 vkEndCommandBuffer(command_buffer[0]);
17756 }
17757 {
17758 VkCommandBufferBeginInfo begin_info{};
17759 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17760 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17761
17762 VkViewport viewport{};
17763 viewport.maxDepth = 1.0f;
17764 viewport.minDepth = 0.0f;
17765 viewport.width = 512;
17766 viewport.height = 512;
17767 viewport.x = 0;
17768 viewport.y = 0;
17769 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17770 vkEndCommandBuffer(command_buffer[1]);
17771 }
17772 {
17773 VkSubmitInfo submit_info{};
17774 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17775 submit_info.commandBufferCount = 1;
17776 submit_info.pCommandBuffers = &command_buffer[0];
17777 submit_info.signalSemaphoreCount = 0;
17778 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
17779 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17780 }
17781 {
17782 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17783 VkSubmitInfo submit_info{};
17784 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17785 submit_info.commandBufferCount = 1;
17786 submit_info.pCommandBuffers = &command_buffer[1];
17787 submit_info.waitSemaphoreCount = 0;
17788 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
17789 submit_info.pWaitDstStageMask = flags;
17790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17791 }
17792
17793 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
17794
17795 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17796 ASSERT_VK_SUCCESS(err);
17797
17798 vkDestroyFence(m_device->device(), fence, nullptr);
17799 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17800 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17801
17802 m_errorMonitor->VerifyNotFound();
17803}
17804
17805// This is a positive test. No errors should be generated.
17806TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
17807
17808 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17809 "on the same queue, the second having a fence, followed "
17810 "by a WaitForFences call.");
17811
17812 m_errorMonitor->ExpectSuccess();
17813
17814 ASSERT_NO_FATAL_FAILURE(InitState());
17815 VkFence fence;
17816 VkFenceCreateInfo fence_create_info{};
17817 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17818 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17819
17820 VkCommandPool command_pool;
17821 VkCommandPoolCreateInfo pool_create_info{};
17822 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17823 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17824 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17825 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17826
17827 VkCommandBuffer command_buffer[2];
17828 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17829 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17830 command_buffer_allocate_info.commandPool = command_pool;
17831 command_buffer_allocate_info.commandBufferCount = 2;
17832 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17833 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17834
17835 {
17836 VkCommandBufferBeginInfo begin_info{};
17837 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17838 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17839
17840 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17841 nullptr, 0, nullptr, 0, nullptr);
17842
17843 VkViewport viewport{};
17844 viewport.maxDepth = 1.0f;
17845 viewport.minDepth = 0.0f;
17846 viewport.width = 512;
17847 viewport.height = 512;
17848 viewport.x = 0;
17849 viewport.y = 0;
17850 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17851 vkEndCommandBuffer(command_buffer[0]);
17852 }
17853 {
17854 VkCommandBufferBeginInfo begin_info{};
17855 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17856 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17857
17858 VkViewport viewport{};
17859 viewport.maxDepth = 1.0f;
17860 viewport.minDepth = 0.0f;
17861 viewport.width = 512;
17862 viewport.height = 512;
17863 viewport.x = 0;
17864 viewport.y = 0;
17865 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17866 vkEndCommandBuffer(command_buffer[1]);
17867 }
17868 {
17869 VkSubmitInfo submit_info{};
17870 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17871 submit_info.commandBufferCount = 1;
17872 submit_info.pCommandBuffers = &command_buffer[0];
17873 submit_info.signalSemaphoreCount = 0;
17874 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
17875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17876 }
17877 {
17878 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17879 VkSubmitInfo submit_info{};
17880 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17881 submit_info.commandBufferCount = 1;
17882 submit_info.pCommandBuffers = &command_buffer[1];
17883 submit_info.waitSemaphoreCount = 0;
17884 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
17885 submit_info.pWaitDstStageMask = flags;
17886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17887 }
17888
17889 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17890
17891 vkDestroyFence(m_device->device(), fence, nullptr);
17892 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17894
17895 m_errorMonitor->VerifyNotFound();
17896}
17897
17898// This is a positive test. No errors should be generated.
17899TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
17900
17901 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
17902 "QueueSubmit call followed by a WaitForFences call.");
17903 ASSERT_NO_FATAL_FAILURE(InitState());
17904
17905 m_errorMonitor->ExpectSuccess();
17906
17907 VkFence fence;
17908 VkFenceCreateInfo fence_create_info{};
17909 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17910 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17911
17912 VkSemaphore semaphore;
17913 VkSemaphoreCreateInfo semaphore_create_info{};
17914 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17915 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17916
17917 VkCommandPool command_pool;
17918 VkCommandPoolCreateInfo pool_create_info{};
17919 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17920 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17921 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17922 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17923
17924 VkCommandBuffer command_buffer[2];
17925 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17926 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17927 command_buffer_allocate_info.commandPool = command_pool;
17928 command_buffer_allocate_info.commandBufferCount = 2;
17929 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17930 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17931
17932 {
17933 VkCommandBufferBeginInfo begin_info{};
17934 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17935 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17936
17937 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17938 nullptr, 0, nullptr, 0, nullptr);
17939
17940 VkViewport viewport{};
17941 viewport.maxDepth = 1.0f;
17942 viewport.minDepth = 0.0f;
17943 viewport.width = 512;
17944 viewport.height = 512;
17945 viewport.x = 0;
17946 viewport.y = 0;
17947 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17948 vkEndCommandBuffer(command_buffer[0]);
17949 }
17950 {
17951 VkCommandBufferBeginInfo begin_info{};
17952 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17953 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17954
17955 VkViewport viewport{};
17956 viewport.maxDepth = 1.0f;
17957 viewport.minDepth = 0.0f;
17958 viewport.width = 512;
17959 viewport.height = 512;
17960 viewport.x = 0;
17961 viewport.y = 0;
17962 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17963 vkEndCommandBuffer(command_buffer[1]);
17964 }
17965 {
17966 VkSubmitInfo submit_info[2];
17967 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17968
17969 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17970 submit_info[0].pNext = NULL;
17971 submit_info[0].commandBufferCount = 1;
17972 submit_info[0].pCommandBuffers = &command_buffer[0];
17973 submit_info[0].signalSemaphoreCount = 1;
17974 submit_info[0].pSignalSemaphores = &semaphore;
17975 submit_info[0].waitSemaphoreCount = 0;
17976 submit_info[0].pWaitSemaphores = NULL;
17977 submit_info[0].pWaitDstStageMask = 0;
17978
17979 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17980 submit_info[1].pNext = NULL;
17981 submit_info[1].commandBufferCount = 1;
17982 submit_info[1].pCommandBuffers = &command_buffer[1];
17983 submit_info[1].waitSemaphoreCount = 1;
17984 submit_info[1].pWaitSemaphores = &semaphore;
17985 submit_info[1].pWaitDstStageMask = flags;
17986 submit_info[1].signalSemaphoreCount = 0;
17987 submit_info[1].pSignalSemaphores = NULL;
17988 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
17989 }
17990
17991 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17992
17993 vkDestroyFence(m_device->device(), fence, nullptr);
17994 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17995 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17996 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17997
17998 m_errorMonitor->VerifyNotFound();
17999}
18000
18001TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18002 m_errorMonitor->ExpectSuccess();
18003
18004 ASSERT_NO_FATAL_FAILURE(InitState());
18005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18006
18007 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18008 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18009
18010 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18011 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18012 m_errorMonitor->VerifyNotFound();
18013 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18014 m_errorMonitor->VerifyNotFound();
18015 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18016 m_errorMonitor->VerifyNotFound();
18017
18018 m_commandBuffer->EndCommandBuffer();
18019 m_errorMonitor->VerifyNotFound();
18020}
18021
18022TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18023 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18024 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18025 "has a valid layout, and a second subpass then uses a "
18026 "valid *READ_ONLY* layout.");
18027 m_errorMonitor->ExpectSuccess();
18028 ASSERT_NO_FATAL_FAILURE(InitState());
18029
18030 VkAttachmentReference attach[2] = {};
18031 attach[0].attachment = 0;
18032 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18033 attach[1].attachment = 0;
18034 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18035 VkSubpassDescription subpasses[2] = {};
18036 // First subpass clears DS attach on load
18037 subpasses[0].pDepthStencilAttachment = &attach[0];
18038 // 2nd subpass reads in DS as input attachment
18039 subpasses[1].inputAttachmentCount = 1;
18040 subpasses[1].pInputAttachments = &attach[1];
18041 VkAttachmentDescription attach_desc = {};
18042 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18043 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18044 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18045 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18046 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18047 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18048 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18049 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18050 VkRenderPassCreateInfo rpci = {};
18051 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18052 rpci.attachmentCount = 1;
18053 rpci.pAttachments = &attach_desc;
18054 rpci.subpassCount = 2;
18055 rpci.pSubpasses = subpasses;
18056
18057 // Now create RenderPass and verify no errors
18058 VkRenderPass rp;
18059 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18060 m_errorMonitor->VerifyNotFound();
18061
18062 vkDestroyRenderPass(m_device->device(), rp, NULL);
18063}
18064
18065TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18066 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18067 "as vertex attributes");
18068 m_errorMonitor->ExpectSuccess();
18069
18070 ASSERT_NO_FATAL_FAILURE(InitState());
18071 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18072
18073 VkVertexInputBindingDescription input_binding;
18074 memset(&input_binding, 0, sizeof(input_binding));
18075
18076 VkVertexInputAttributeDescription input_attribs[2];
18077 memset(input_attribs, 0, sizeof(input_attribs));
18078
18079 for (int i = 0; i < 2; i++) {
18080 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18081 input_attribs[i].location = i;
18082 }
18083
18084 char const *vsSource = "#version 450\n"
18085 "\n"
18086 "layout(location=0) in mat2x4 x;\n"
18087 "out gl_PerVertex {\n"
18088 " vec4 gl_Position;\n"
18089 "};\n"
18090 "void main(){\n"
18091 " gl_Position = x[0] + x[1];\n"
18092 "}\n";
18093 char const *fsSource = "#version 450\n"
18094 "\n"
18095 "layout(location=0) out vec4 color;\n"
18096 "void main(){\n"
18097 " color = vec4(1);\n"
18098 "}\n";
18099
18100 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18101 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18102
18103 VkPipelineObj pipe(m_device);
18104 pipe.AddColorAttachment();
18105 pipe.AddShader(&vs);
18106 pipe.AddShader(&fs);
18107
18108 pipe.AddVertexInputBindings(&input_binding, 1);
18109 pipe.AddVertexInputAttribs(input_attribs, 2);
18110
18111 VkDescriptorSetObj descriptorSet(m_device);
18112 descriptorSet.AppendDummy();
18113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18114
18115 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18116
18117 /* expect success */
18118 m_errorMonitor->VerifyNotFound();
18119}
18120
18121TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18122 m_errorMonitor->ExpectSuccess();
18123
18124 ASSERT_NO_FATAL_FAILURE(InitState());
18125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18126
18127 VkVertexInputBindingDescription input_binding;
18128 memset(&input_binding, 0, sizeof(input_binding));
18129
18130 VkVertexInputAttributeDescription input_attribs[2];
18131 memset(input_attribs, 0, sizeof(input_attribs));
18132
18133 for (int i = 0; i < 2; i++) {
18134 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18135 input_attribs[i].location = i;
18136 }
18137
18138 char const *vsSource = "#version 450\n"
18139 "\n"
18140 "layout(location=0) in vec4 x[2];\n"
18141 "out gl_PerVertex {\n"
18142 " vec4 gl_Position;\n"
18143 "};\n"
18144 "void main(){\n"
18145 " gl_Position = x[0] + x[1];\n"
18146 "}\n";
18147 char const *fsSource = "#version 450\n"
18148 "\n"
18149 "layout(location=0) out vec4 color;\n"
18150 "void main(){\n"
18151 " color = vec4(1);\n"
18152 "}\n";
18153
18154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18156
18157 VkPipelineObj pipe(m_device);
18158 pipe.AddColorAttachment();
18159 pipe.AddShader(&vs);
18160 pipe.AddShader(&fs);
18161
18162 pipe.AddVertexInputBindings(&input_binding, 1);
18163 pipe.AddVertexInputAttribs(input_attribs, 2);
18164
18165 VkDescriptorSetObj descriptorSet(m_device);
18166 descriptorSet.AppendDummy();
18167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18168
18169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18170
18171 m_errorMonitor->VerifyNotFound();
18172}
18173
18174TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18175 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18176 "through multiple vertex shader inputs, each consuming a different "
18177 "subset of the components.");
18178 m_errorMonitor->ExpectSuccess();
18179
18180 ASSERT_NO_FATAL_FAILURE(InitState());
18181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18182
18183 VkVertexInputBindingDescription input_binding;
18184 memset(&input_binding, 0, sizeof(input_binding));
18185
18186 VkVertexInputAttributeDescription input_attribs[3];
18187 memset(input_attribs, 0, sizeof(input_attribs));
18188
18189 for (int i = 0; i < 3; i++) {
18190 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18191 input_attribs[i].location = i;
18192 }
18193
18194 char const *vsSource = "#version 450\n"
18195 "\n"
18196 "layout(location=0) in vec4 x;\n"
18197 "layout(location=1) in vec3 y1;\n"
18198 "layout(location=1, component=3) in float y2;\n"
18199 "layout(location=2) in vec4 z;\n"
18200 "out gl_PerVertex {\n"
18201 " vec4 gl_Position;\n"
18202 "};\n"
18203 "void main(){\n"
18204 " gl_Position = x + vec4(y1, y2) + z;\n"
18205 "}\n";
18206 char const *fsSource = "#version 450\n"
18207 "\n"
18208 "layout(location=0) out vec4 color;\n"
18209 "void main(){\n"
18210 " color = vec4(1);\n"
18211 "}\n";
18212
18213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18215
18216 VkPipelineObj pipe(m_device);
18217 pipe.AddColorAttachment();
18218 pipe.AddShader(&vs);
18219 pipe.AddShader(&fs);
18220
18221 pipe.AddVertexInputBindings(&input_binding, 1);
18222 pipe.AddVertexInputAttribs(input_attribs, 3);
18223
18224 VkDescriptorSetObj descriptorSet(m_device);
18225 descriptorSet.AppendDummy();
18226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18227
18228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18229
18230 m_errorMonitor->VerifyNotFound();
18231}
18232
18233TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18234 m_errorMonitor->ExpectSuccess();
18235
18236 ASSERT_NO_FATAL_FAILURE(InitState());
18237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18238
18239 char const *vsSource = "#version 450\n"
18240 "out gl_PerVertex {\n"
18241 " vec4 gl_Position;\n"
18242 "};\n"
18243 "void main(){\n"
18244 " gl_Position = vec4(0);\n"
18245 "}\n";
18246 char const *fsSource = "#version 450\n"
18247 "\n"
18248 "layout(location=0) out vec4 color;\n"
18249 "void main(){\n"
18250 " color = vec4(1);\n"
18251 "}\n";
18252
18253 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18254 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18255
18256 VkPipelineObj pipe(m_device);
18257 pipe.AddColorAttachment();
18258 pipe.AddShader(&vs);
18259 pipe.AddShader(&fs);
18260
18261 VkDescriptorSetObj descriptorSet(m_device);
18262 descriptorSet.AppendDummy();
18263 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18264
18265 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18266
18267 m_errorMonitor->VerifyNotFound();
18268}
18269
18270TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18271 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18272 "set out in 14.1.3: fundamental type must match, and producer side must "
18273 "have at least as many components");
18274 m_errorMonitor->ExpectSuccess();
18275
18276 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18277
18278 ASSERT_NO_FATAL_FAILURE(InitState());
18279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18280
18281 char const *vsSource = "#version 450\n"
18282 "out gl_PerVertex {\n"
18283 " vec4 gl_Position;\n"
18284 "};\n"
18285 "layout(location=0) out vec3 x;\n"
18286 "layout(location=1) out ivec3 y;\n"
18287 "layout(location=2) out vec3 z;\n"
18288 "void main(){\n"
18289 " gl_Position = vec4(0);\n"
18290 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18291 "}\n";
18292 char const *fsSource = "#version 450\n"
18293 "\n"
18294 "layout(location=0) out vec4 color;\n"
18295 "layout(location=0) in float x;\n"
18296 "layout(location=1) flat in int y;\n"
18297 "layout(location=2) in vec2 z;\n"
18298 "void main(){\n"
18299 " color = vec4(1 + x + y + z.x);\n"
18300 "}\n";
18301
18302 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18303 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18304
18305 VkPipelineObj pipe(m_device);
18306 pipe.AddColorAttachment();
18307 pipe.AddShader(&vs);
18308 pipe.AddShader(&fs);
18309
18310 VkDescriptorSetObj descriptorSet(m_device);
18311 descriptorSet.AppendDummy();
18312 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18313
18314 VkResult err = VK_SUCCESS;
18315 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18316 ASSERT_VK_SUCCESS(err);
18317
18318 m_errorMonitor->VerifyNotFound();
18319}
18320
18321TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18322 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18323 "passed between the TCS and TES stages");
18324 m_errorMonitor->ExpectSuccess();
18325
18326 ASSERT_NO_FATAL_FAILURE(InitState());
18327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18328
18329 if (!m_device->phy().features().tessellationShader) {
18330 printf("Device does not support tessellation shaders; skipped.\n");
18331 return;
18332 }
18333
18334 char const *vsSource = "#version 450\n"
18335 "void main(){}\n";
18336 char const *tcsSource = "#version 450\n"
18337 "layout(location=0) out int x[];\n"
18338 "layout(vertices=3) out;\n"
18339 "void main(){\n"
18340 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18341 " gl_TessLevelInner[0] = 1;\n"
18342 " x[gl_InvocationID] = gl_InvocationID;\n"
18343 "}\n";
18344 char const *tesSource = "#version 450\n"
18345 "layout(triangles, equal_spacing, cw) in;\n"
18346 "layout(location=0) in int x[];\n"
18347 "out gl_PerVertex { vec4 gl_Position; };\n"
18348 "void main(){\n"
18349 " gl_Position.xyz = gl_TessCoord;\n"
18350 " gl_Position.w = x[0] + x[1] + x[2];\n"
18351 "}\n";
18352 char const *fsSource = "#version 450\n"
18353 "layout(location=0) out vec4 color;\n"
18354 "void main(){\n"
18355 " color = vec4(1);\n"
18356 "}\n";
18357
18358 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18359 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18360 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18361 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18362
18363 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18364 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18365
18366 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18367
18368 VkPipelineObj pipe(m_device);
18369 pipe.SetInputAssembly(&iasci);
18370 pipe.SetTessellation(&tsci);
18371 pipe.AddColorAttachment();
18372 pipe.AddShader(&vs);
18373 pipe.AddShader(&tcs);
18374 pipe.AddShader(&tes);
18375 pipe.AddShader(&fs);
18376
18377 VkDescriptorSetObj descriptorSet(m_device);
18378 descriptorSet.AppendDummy();
18379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18380
18381 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18382
18383 m_errorMonitor->VerifyNotFound();
18384}
18385
18386TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18387 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18388 "interface block passed into the geometry shader. This "
18389 "is interesting because the 'extra' array level is not "
18390 "present on the member type, but on the block instance.");
18391 m_errorMonitor->ExpectSuccess();
18392
18393 ASSERT_NO_FATAL_FAILURE(InitState());
18394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18395
18396 if (!m_device->phy().features().geometryShader) {
18397 printf("Device does not support geometry shaders; skipped.\n");
18398 return;
18399 }
18400
18401 char const *vsSource = "#version 450\n"
18402 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18403 "void main(){\n"
18404 " vs_out.x = vec4(1);\n"
18405 "}\n";
18406 char const *gsSource = "#version 450\n"
18407 "layout(triangles) in;\n"
18408 "layout(triangle_strip, max_vertices=3) out;\n"
18409 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18410 "out gl_PerVertex { vec4 gl_Position; };\n"
18411 "void main() {\n"
18412 " gl_Position = gs_in[0].x;\n"
18413 " EmitVertex();\n"
18414 "}\n";
18415 char const *fsSource = "#version 450\n"
18416 "layout(location=0) out vec4 color;\n"
18417 "void main(){\n"
18418 " color = vec4(1);\n"
18419 "}\n";
18420
18421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18422 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18424
18425 VkPipelineObj pipe(m_device);
18426 pipe.AddColorAttachment();
18427 pipe.AddShader(&vs);
18428 pipe.AddShader(&gs);
18429 pipe.AddShader(&fs);
18430
18431 VkDescriptorSetObj descriptorSet(m_device);
18432 descriptorSet.AppendDummy();
18433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18434
18435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18436
18437 m_errorMonitor->VerifyNotFound();
18438}
18439
18440TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18441 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18442 "attributes. This is interesting because they consume multiple "
18443 "locations.");
18444 m_errorMonitor->ExpectSuccess();
18445
18446 ASSERT_NO_FATAL_FAILURE(InitState());
18447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18448
18449 if (!m_device->phy().features().shaderFloat64) {
18450 printf("Device does not support 64bit vertex attributes; skipped.\n");
18451 return;
18452 }
18453
18454 VkVertexInputBindingDescription input_bindings[1];
18455 memset(input_bindings, 0, sizeof(input_bindings));
18456
18457 VkVertexInputAttributeDescription input_attribs[4];
18458 memset(input_attribs, 0, sizeof(input_attribs));
18459 input_attribs[0].location = 0;
18460 input_attribs[0].offset = 0;
18461 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18462 input_attribs[1].location = 2;
18463 input_attribs[1].offset = 32;
18464 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18465 input_attribs[2].location = 4;
18466 input_attribs[2].offset = 64;
18467 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18468 input_attribs[3].location = 6;
18469 input_attribs[3].offset = 96;
18470 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18471
18472 char const *vsSource = "#version 450\n"
18473 "\n"
18474 "layout(location=0) in dmat4 x;\n"
18475 "out gl_PerVertex {\n"
18476 " vec4 gl_Position;\n"
18477 "};\n"
18478 "void main(){\n"
18479 " gl_Position = vec4(x[0][0]);\n"
18480 "}\n";
18481 char const *fsSource = "#version 450\n"
18482 "\n"
18483 "layout(location=0) out vec4 color;\n"
18484 "void main(){\n"
18485 " color = vec4(1);\n"
18486 "}\n";
18487
18488 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18489 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18490
18491 VkPipelineObj pipe(m_device);
18492 pipe.AddColorAttachment();
18493 pipe.AddShader(&vs);
18494 pipe.AddShader(&fs);
18495
18496 pipe.AddVertexInputBindings(input_bindings, 1);
18497 pipe.AddVertexInputAttribs(input_attribs, 4);
18498
18499 VkDescriptorSetObj descriptorSet(m_device);
18500 descriptorSet.AppendDummy();
18501 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18502
18503 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18504
18505 m_errorMonitor->VerifyNotFound();
18506}
18507
18508TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18509 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18510 m_errorMonitor->ExpectSuccess();
18511
18512 ASSERT_NO_FATAL_FAILURE(InitState());
18513
18514 char const *vsSource = "#version 450\n"
18515 "\n"
18516 "out gl_PerVertex {\n"
18517 " vec4 gl_Position;\n"
18518 "};\n"
18519 "void main(){\n"
18520 " gl_Position = vec4(1);\n"
18521 "}\n";
18522 char const *fsSource = "#version 450\n"
18523 "\n"
18524 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18525 "layout(location=0) out vec4 color;\n"
18526 "void main() {\n"
18527 " color = subpassLoad(x);\n"
18528 "}\n";
18529
18530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18531 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18532
18533 VkPipelineObj pipe(m_device);
18534 pipe.AddShader(&vs);
18535 pipe.AddShader(&fs);
18536 pipe.AddColorAttachment();
18537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18538
18539 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18540 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18541 VkDescriptorSetLayout dsl;
18542 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18543 ASSERT_VK_SUCCESS(err);
18544
18545 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18546 VkPipelineLayout pl;
18547 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18548 ASSERT_VK_SUCCESS(err);
18549
18550 VkAttachmentDescription descs[2] = {
18551 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18552 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18553 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18554 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18555 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18556 };
18557 VkAttachmentReference color = {
18558 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18559 };
18560 VkAttachmentReference input = {
18561 1, VK_IMAGE_LAYOUT_GENERAL,
18562 };
18563
18564 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18565
18566 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18567 VkRenderPass rp;
18568 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18569 ASSERT_VK_SUCCESS(err);
18570
18571 // should be OK. would go wrong here if it's going to...
18572 pipe.CreateVKPipeline(pl, rp);
18573
18574 m_errorMonitor->VerifyNotFound();
18575
18576 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18577 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18578 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18579}
18580
18581TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18582 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18583 "descriptor-backed resource which is not provided, but the shader does not "
18584 "statically use it. This is interesting because it requires compute pipelines "
18585 "to have a proper descriptor use walk, which they didn't for some time.");
18586 m_errorMonitor->ExpectSuccess();
18587
18588 ASSERT_NO_FATAL_FAILURE(InitState());
18589
18590 char const *csSource = "#version 450\n"
18591 "\n"
18592 "layout(local_size_x=1) in;\n"
18593 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18594 "void main(){\n"
18595 " // x is not used.\n"
18596 "}\n";
18597
18598 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18599
18600 VkDescriptorSetObj descriptorSet(m_device);
18601 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18602
18603 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18604 nullptr,
18605 0,
18606 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18607 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18608 descriptorSet.GetPipelineLayout(),
18609 VK_NULL_HANDLE,
18610 -1 };
18611
18612 VkPipeline pipe;
18613 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18614
18615 m_errorMonitor->VerifyNotFound();
18616
18617 if (err == VK_SUCCESS) {
18618 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18619 }
18620}
18621
18622TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18623 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18624 "sampler portion of a combined image + sampler");
18625 m_errorMonitor->ExpectSuccess();
18626
18627 ASSERT_NO_FATAL_FAILURE(InitState());
18628
18629 VkDescriptorSetLayoutBinding bindings[] = {
18630 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18631 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18632 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18633 };
18634 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18635 VkDescriptorSetLayout dsl;
18636 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18637 ASSERT_VK_SUCCESS(err);
18638
18639 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18640 VkPipelineLayout pl;
18641 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18642 ASSERT_VK_SUCCESS(err);
18643
18644 char const *csSource = "#version 450\n"
18645 "\n"
18646 "layout(local_size_x=1) in;\n"
18647 "layout(set=0, binding=0) uniform sampler s;\n"
18648 "layout(set=0, binding=1) uniform texture2D t;\n"
18649 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18650 "void main() {\n"
18651 " x = texture(sampler2D(t, s), vec2(0));\n"
18652 "}\n";
18653 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18654
18655 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18656 nullptr,
18657 0,
18658 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18659 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18660 pl,
18661 VK_NULL_HANDLE,
18662 -1 };
18663
18664 VkPipeline pipe;
18665 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18666
18667 m_errorMonitor->VerifyNotFound();
18668
18669 if (err == VK_SUCCESS) {
18670 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18671 }
18672
18673 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18674 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18675}
18676
18677TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
18678 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18679 "image portion of a combined image + sampler");
18680 m_errorMonitor->ExpectSuccess();
18681
18682 ASSERT_NO_FATAL_FAILURE(InitState());
18683
18684 VkDescriptorSetLayoutBinding bindings[] = {
18685 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18686 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18687 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18688 };
18689 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18690 VkDescriptorSetLayout dsl;
18691 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18692 ASSERT_VK_SUCCESS(err);
18693
18694 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18695 VkPipelineLayout pl;
18696 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18697 ASSERT_VK_SUCCESS(err);
18698
18699 char const *csSource = "#version 450\n"
18700 "\n"
18701 "layout(local_size_x=1) in;\n"
18702 "layout(set=0, binding=0) uniform texture2D t;\n"
18703 "layout(set=0, binding=1) uniform sampler s;\n"
18704 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18705 "void main() {\n"
18706 " x = texture(sampler2D(t, s), vec2(0));\n"
18707 "}\n";
18708 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18709
18710 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18711 nullptr,
18712 0,
18713 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18714 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18715 pl,
18716 VK_NULL_HANDLE,
18717 -1 };
18718
18719 VkPipeline pipe;
18720 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18721
18722 m_errorMonitor->VerifyNotFound();
18723
18724 if (err == VK_SUCCESS) {
18725 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18726 }
18727
18728 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18729 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18730}
18731
18732TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
18733 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
18734 "both the sampler and the image of a combined image+sampler "
18735 "but via separate variables");
18736 m_errorMonitor->ExpectSuccess();
18737
18738 ASSERT_NO_FATAL_FAILURE(InitState());
18739
18740 VkDescriptorSetLayoutBinding bindings[] = {
18741 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18742 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18743 };
18744 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
18745 VkDescriptorSetLayout dsl;
18746 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18747 ASSERT_VK_SUCCESS(err);
18748
18749 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18750 VkPipelineLayout pl;
18751 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18752 ASSERT_VK_SUCCESS(err);
18753
18754 char const *csSource = "#version 450\n"
18755 "\n"
18756 "layout(local_size_x=1) in;\n"
18757 "layout(set=0, binding=0) uniform texture2D t;\n"
18758 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
18759 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
18760 "void main() {\n"
18761 " x = texture(sampler2D(t, s), vec2(0));\n"
18762 "}\n";
18763 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18764
18765 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18766 nullptr,
18767 0,
18768 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18769 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18770 pl,
18771 VK_NULL_HANDLE,
18772 -1 };
18773
18774 VkPipeline pipe;
18775 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18776
18777 m_errorMonitor->VerifyNotFound();
18778
18779 if (err == VK_SUCCESS) {
18780 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18781 }
18782
18783 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18784 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18785}
18786
18787TEST_F(VkPositiveLayerTest, ValidStructPNext) {
18788 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
18789
18790 ASSERT_NO_FATAL_FAILURE(InitState());
18791
18792 // Positive test to check parameter_validation and unique_objects support
18793 // for NV_dedicated_allocation
18794 uint32_t extension_count = 0;
18795 bool supports_nv_dedicated_allocation = false;
18796 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
18797 ASSERT_VK_SUCCESS(err);
18798
18799 if (extension_count > 0) {
18800 std::vector<VkExtensionProperties> available_extensions(extension_count);
18801
18802 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
18803 ASSERT_VK_SUCCESS(err);
18804
18805 for (const auto &extension_props : available_extensions) {
18806 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
18807 supports_nv_dedicated_allocation = true;
18808 }
18809 }
18810 }
18811
18812 if (supports_nv_dedicated_allocation) {
18813 m_errorMonitor->ExpectSuccess();
18814
18815 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
18816 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
18817 dedicated_buffer_create_info.pNext = nullptr;
18818 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
18819
18820 uint32_t queue_family_index = 0;
18821 VkBufferCreateInfo buffer_create_info = {};
18822 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18823 buffer_create_info.pNext = &dedicated_buffer_create_info;
18824 buffer_create_info.size = 1024;
18825 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18826 buffer_create_info.queueFamilyIndexCount = 1;
18827 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18828
18829 VkBuffer buffer;
18830 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18831 ASSERT_VK_SUCCESS(err);
18832
18833 VkMemoryRequirements memory_reqs;
18834 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18835
18836 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
18837 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
18838 dedicated_memory_info.pNext = nullptr;
18839 dedicated_memory_info.buffer = buffer;
18840 dedicated_memory_info.image = VK_NULL_HANDLE;
18841
18842 VkMemoryAllocateInfo memory_info = {};
18843 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18844 memory_info.pNext = &dedicated_memory_info;
18845 memory_info.allocationSize = memory_reqs.size;
18846
18847 bool pass;
18848 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18849 ASSERT_TRUE(pass);
18850
18851 VkDeviceMemory buffer_memory;
18852 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18853 ASSERT_VK_SUCCESS(err);
18854
18855 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18856 ASSERT_VK_SUCCESS(err);
18857
18858 vkDestroyBuffer(m_device->device(), buffer, NULL);
18859 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18860
18861 m_errorMonitor->VerifyNotFound();
18862 }
18863}
18864
18865TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
18866 VkResult err;
18867
18868 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
18869
18870 ASSERT_NO_FATAL_FAILURE(InitState());
18871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18872
18873 std::vector<const char *> device_extension_names;
18874 auto features = m_device->phy().features();
18875 // Artificially disable support for non-solid fill modes
18876 features.fillModeNonSolid = false;
18877 // The sacrificial device object
18878 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
18879
18880 VkRenderpassObj render_pass(&test_device);
18881
18882 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18883 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18884 pipeline_layout_ci.setLayoutCount = 0;
18885 pipeline_layout_ci.pSetLayouts = NULL;
18886
18887 VkPipelineLayout pipeline_layout;
18888 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18889 ASSERT_VK_SUCCESS(err);
18890
18891 VkPipelineRasterizationStateCreateInfo rs_ci = {};
18892 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
18893 rs_ci.pNext = nullptr;
18894 rs_ci.lineWidth = 1.0f;
18895 rs_ci.rasterizerDiscardEnable = true;
18896
18897 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
18898 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18899
18900 // Set polygonMode=FILL. No error is expected
18901 m_errorMonitor->ExpectSuccess();
18902 {
18903 VkPipelineObj pipe(&test_device);
18904 pipe.AddShader(&vs);
18905 pipe.AddShader(&fs);
18906 pipe.AddColorAttachment();
18907 // Set polygonMode to a good value
18908 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
18909 pipe.SetRasterization(&rs_ci);
18910 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
18911 }
18912 m_errorMonitor->VerifyNotFound();
18913
18914 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
18915}
18916
18917TEST_F(VkPositiveLayerTest, ValidPushConstants) {
18918 VkResult err;
18919 ASSERT_NO_FATAL_FAILURE(InitState());
18920 ASSERT_NO_FATAL_FAILURE(InitViewport());
18921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18922
18923 VkPipelineLayout pipeline_layout;
18924 VkPushConstantRange pc_range = {};
18925 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18926 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18927 pipeline_layout_ci.pushConstantRangeCount = 1;
18928 pipeline_layout_ci.pPushConstantRanges = &pc_range;
18929
18930 //
18931 // Check for invalid push constant ranges in pipeline layouts.
18932 //
18933 struct PipelineLayoutTestCase {
18934 VkPushConstantRange const range;
18935 char const *msg;
18936 };
18937
18938 // Check for overlapping ranges
18939 const uint32_t ranges_per_test = 5;
18940 struct OverlappingRangeTestCase {
18941 VkPushConstantRange const ranges[ranges_per_test];
18942 char const *msg;
18943 };
18944
18945 // Run some positive tests to make sure overlap checking in the layer is OK
18946 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
18947 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
18948 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
18949 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
18950 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
18951 "" },
18952 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
18953 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
18954 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
18955 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
18956 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
18957 "" } } };
18958 for (const auto &iter : overlapping_range_tests_pos) {
18959 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
18960 m_errorMonitor->ExpectSuccess();
18961 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18962 m_errorMonitor->VerifyNotFound();
18963 if (VK_SUCCESS == err) {
18964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18965 }
18966 }
18967
18968 //
18969 // CmdPushConstants tests
18970 //
18971 const uint8_t dummy_values[100] = {};
18972
18973 BeginCommandBuffer();
18974
18975 // positive overlapping range tests with cmd
18976 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
18977 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
18978 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
18979 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
18980 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
18981 } };
18982
18983 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
18984 const VkPushConstantRange pc_range4[] = {
18985 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
18986 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
18987 };
18988
18989 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
18990 pipeline_layout_ci.pPushConstantRanges = pc_range4;
18991 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18992 ASSERT_VK_SUCCESS(err);
18993 for (const auto &iter : cmd_overlap_tests_pos) {
18994 m_errorMonitor->ExpectSuccess();
18995 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
18996 iter.range.size, dummy_values);
18997 m_errorMonitor->VerifyNotFound();
18998 }
18999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19000
19001 EndCommandBuffer();
19002}
19003
19004
19005
19006
19007
19008
19009
19010#if 0 // A few devices have issues with this test so disabling for now
19011TEST_F(VkPositiveLayerTest, LongFenceChain)
19012{
19013 m_errorMonitor->ExpectSuccess();
19014
19015 ASSERT_NO_FATAL_FAILURE(InitState());
19016 VkResult err;
19017
19018 std::vector<VkFence> fences;
19019
19020 const int chainLength = 32768;
19021
19022 for (int i = 0; i < chainLength; i++) {
19023 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19024 VkFence fence;
19025 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19026 ASSERT_VK_SUCCESS(err);
19027
19028 fences.push_back(fence);
19029
19030 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19031 0, nullptr, 0, nullptr };
19032 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19033 ASSERT_VK_SUCCESS(err);
19034
19035 }
19036
19037 // BOOM, stack overflow.
19038 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19039
19040 for (auto fence : fences)
19041 vkDestroyFence(m_device->device(), fence, nullptr);
19042
19043 m_errorMonitor->VerifyNotFound();
19044}
19045#endif
19046
19047
Cody Northrop1242dfd2016-07-13 17:24:59 -060019048#if defined(ANDROID) && defined(VALIDATION_APK)
19049static bool initialized = false;
19050static bool active = false;
19051
19052// Convert Intents to argv
19053// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019054std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019055 std::vector<std::string> args;
19056 JavaVM &vm = *app.activity->vm;
19057 JNIEnv *p_env;
19058 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19059 return args;
19060
19061 JNIEnv &env = *p_env;
19062 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019063 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019064 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019065 jmethodID get_string_extra_method =
19066 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019067 jvalue get_string_extra_args;
19068 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019069 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019070
19071 std::string args_str;
19072 if (extra_str) {
19073 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19074 args_str = extra_utf;
19075 env.ReleaseStringUTFChars(extra_str, extra_utf);
19076 env.DeleteLocalRef(extra_str);
19077 }
19078
19079 env.DeleteLocalRef(get_string_extra_args.l);
19080 env.DeleteLocalRef(intent);
19081 vm.DetachCurrentThread();
19082
19083 // split args_str
19084 std::stringstream ss(args_str);
19085 std::string arg;
19086 while (std::getline(ss, arg, ' ')) {
19087 if (!arg.empty())
19088 args.push_back(arg);
19089 }
19090
19091 return args;
19092}
19093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019094static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019096static void processCommand(struct android_app *app, int32_t cmd) {
19097 switch (cmd) {
19098 case APP_CMD_INIT_WINDOW: {
19099 if (app->window) {
19100 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019101 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019102 break;
19103 }
19104 case APP_CMD_GAINED_FOCUS: {
19105 active = true;
19106 break;
19107 }
19108 case APP_CMD_LOST_FOCUS: {
19109 active = false;
19110 break;
19111 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019112 }
19113}
19114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019115void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019116 app_dummy();
19117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019118 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019119
19120 int vulkanSupport = InitVulkan();
19121 if (vulkanSupport == 0) {
19122 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19123 return;
19124 }
19125
19126 app->onAppCmd = processCommand;
19127 app->onInputEvent = processInput;
19128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019129 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019130 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019131 struct android_poll_source *source;
19132 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019133 if (source) {
19134 source->process(app, source);
19135 }
19136
19137 if (app->destroyRequested != 0) {
19138 VkTestFramework::Finish();
19139 return;
19140 }
19141 }
19142
19143 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019144 // Use the following key to send arguments to gtest, i.e.
19145 // --es args "--gtest_filter=-VkLayerTest.foo"
19146 const char key[] = "args";
19147 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019149 std::string filter = "";
19150 if (args.size() > 0) {
19151 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19152 filter += args[0];
19153 } else {
19154 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19155 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019157 int argc = 2;
19158 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19159 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019161 // Route output to files until we can override the gtest output
19162 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19163 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019165 ::testing::InitGoogleTest(&argc, argv);
19166 VkTestFramework::InitArgs(&argc, argv);
19167 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019169 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019171 if (result != 0) {
19172 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19173 } else {
19174 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19175 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019177 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019179 fclose(stdout);
19180 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019182 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019184 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019185 }
19186 }
19187}
19188#endif
19189
Tony Barbour300a6082015-04-07 13:44:53 -060019190int main(int argc, char **argv) {
19191 int result;
19192
Cody Northrop8e54a402016-03-08 22:25:52 -070019193#ifdef ANDROID
19194 int vulkanSupport = InitVulkan();
19195 if (vulkanSupport == 0)
19196 return 1;
19197#endif
19198
Tony Barbour300a6082015-04-07 13:44:53 -060019199 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019200 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019201
19202 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19203
19204 result = RUN_ALL_TESTS();
19205
Tony Barbour6918cd52015-04-09 12:58:51 -060019206 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019207 return result;
19208}