blob: 915b625fb8f7de24c4c673040b9f6a5df67c1ce7 [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>
Tony Barbour300a6082015-04-07 13:44:53 -060039
Mark Lobodzinski3780e142015-05-14 15:08:13 -050040#define GLM_FORCE_RADIANS
41#include "glm/glm.hpp"
42#include <glm/gtc/matrix_transform.hpp>
43
Dustin Gravesffa90fa2016-05-06 11:20:38 -060044#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060045#define MEM_TRACKER_TESTS 1
46#define OBJ_TRACKER_TESTS 1
47#define DRAW_STATE_TESTS 1
48#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120049#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060050#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060051#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060052
Mark Lobodzinski3780e142015-05-14 15:08:13 -050053//--------------------------------------------------------------------------------------
54// Mesh and VertexFormat Data
55//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070056struct Vertex {
57 float posX, posY, posZ, posW; // Position data
58 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059};
60
Karl Schultz6addd812016-02-02 17:17:23 -070061#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050062
63typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070064 BsoFailNone = 0x00000000,
65 BsoFailLineWidth = 0x00000001,
66 BsoFailDepthBias = 0x00000002,
67 BsoFailViewport = 0x00000004,
68 BsoFailScissor = 0x00000008,
69 BsoFailBlend = 0x00000010,
70 BsoFailDepthBounds = 0x00000020,
71 BsoFailStencilReadMask = 0x00000040,
72 BsoFailStencilWriteMask = 0x00000080,
73 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060074 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060075 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050076} BsoFailSelect;
77
78struct vktriangle_vs_uniform {
79 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070080 float mvp[4][4];
81 float position[3][4];
82 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050083};
84
Mark Lobodzinskice751c62016-09-08 10:45:35 -060085static const char bindStateVertShaderText[] = "#version 450\n"
86 "vec2 vertices[3];\n"
87 "out gl_PerVertex {\n"
88 " vec4 gl_Position;\n"
89 "};\n"
90 "void main() {\n"
91 " vertices[0] = vec2(-1.0, -1.0);\n"
92 " vertices[1] = vec2( 1.0, -1.0);\n"
93 " vertices[2] = vec2( 0.0, 1.0);\n"
94 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060097static const char bindStateFragShaderText[] = "#version 450\n"
98 "\n"
99 "layout(location = 0) out vec4 uFragColor;\n"
100 "void main(){\n"
101 " uFragColor = vec4(0,1,0,1);\n"
102 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500103
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600104static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
105 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
106 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600107
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600108// ********************************************************
109// ErrorMonitor Usage:
110//
111// Call SetDesiredFailureMsg with a string to be compared against all
112// encountered log messages. Passing NULL will match all log messages.
113// logMsg will return true for skipCall only if msg is matched or NULL.
114//
115// Call DesiredMsgFound to determine if the desired failure message
116// was encountered.
117
Tony Barbour300a6082015-04-07 13:44:53 -0600118class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700119 public:
120 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600121 test_platform_thread_create_mutex(&m_mutex);
122 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200123 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700124 m_bailout = NULL;
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_desiredMsgSet = false;
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
Karl Schultz6addd812016-02-02 17:17:23 -0700131 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200132 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600133 test_platform_thread_lock_mutex(&m_mutex);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600134 m_failureMsgs.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 m_otherMsgs.clear();
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600136 m_desiredMsgs.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700137 m_msgFound = VK_FALSE;
138 m_msgFlags = msgFlags;
Chris Forbes17756132016-09-16 14:36:39 +1200139 m_desiredMsgSet = true;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600140 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600141 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600142
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600143 VkBool32 CheckForDesiredMsg(const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600144 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600145 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600146 if (m_bailout != NULL) {
147 *m_bailout = true;
148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600150 bool found_expected = false;
151 for (auto desired_msg : m_desiredMsgs) {
152 if (errorString.find(desired_msg) != string::npos) {
153 found_expected = true;
154 m_failureMsgs.insert(errorString);
155 m_msgFound = VK_TRUE;
156 result = VK_TRUE;
157 // We only want one match for each expected error so remove from set here
158 // Since we're about the break the loop it's ok to remove from set we're iterating over
159 m_desiredMsgs.erase(desired_msg);
160 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600162 }
163 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200164 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600165 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600167 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600168 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600169 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600170
Karl Schultz6addd812016-02-02 17:17:23 -0700171 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600172
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600173 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
174
Karl Schultz6addd812016-02-02 17:17:23 -0700175 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600176
Karl Schultz6addd812016-02-02 17:17:23 -0700177 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600178
Karl Schultz6addd812016-02-02 17:17:23 -0700179 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600180 vector<string> otherMsgs = GetOtherFailureMsgs();
181 cout << "Other error messages logged for this test were:" << endl;
182 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
183 cout << " " << *iter << endl;
184 }
185 }
186
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600187 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200188
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600189 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
190 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
191 m_msgFlags = message_flag_mask;
192 // Match ANY message matching specified type
193 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200194 }
195
196 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600197 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200198 if (!DesiredMsgFound()) {
199 DumpFailureMsgs();
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600200 for (auto desired_msg : m_desiredMsgs) {
201 FAIL() << "Did not receive expected error '" << desired_msg << "'";
202 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200203 }
204 }
205
206 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200208 if (DesiredMsgFound()) {
209 DumpFailureMsgs();
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 for (auto msg : m_failureMsgs) {
211 FAIL() << "Expected to succeed but got error: " << msg;
212 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200213 }
214 }
215
Karl Schultz6addd812016-02-02 17:17:23 -0700216 private:
217 VkFlags m_msgFlags;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600218 std::unordered_set<string> m_desiredMsgs;
219 std::unordered_set<string> m_failureMsgs;
Karl Schultz6addd812016-02-02 17:17:23 -0700220 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600221 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700222 bool *m_bailout;
223 VkBool32 m_msgFound;
Chris Forbes17756132016-09-16 14:36:39 +1200224 bool m_desiredMsgSet;
Tony Barbour300a6082015-04-07 13:44:53 -0600225};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500226
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600227static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
228 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
229 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600230 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
231 if (msgFlags & errMonitor->GetMessageFlags()) {
232 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600233 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600234 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600235}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500236
Karl Schultz6addd812016-02-02 17:17:23 -0700237class VkLayerTest : public VkRenderFramework {
238 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800239 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
240 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600241 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
242 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700243 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600244 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
245 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700246 }
Tony Barbour300a6082015-04-07 13:44:53 -0600247
Tony Barbourfe3351b2015-07-28 10:17:20 -0600248 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600249 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800250 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600251 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
252 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700253 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600254 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700255 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600256 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700257 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600258 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
259 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
260 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600273 std::vector<const char *> instance_extension_names;
274 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700276 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600277 /*
278 * Since CreateDbgMsgCallback is an instance level extension call
279 * any extension / layer that utilizes that feature also needs
280 * to be enabled at create instance time.
281 */
Karl Schultz6addd812016-02-02 17:17:23 -0700282 // Use Threading layer first to protect others from
283 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700284 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600285 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800286 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700287 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800288 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600289 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700290 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600291
Ian Elliott2c1daf52016-05-12 09:41:46 -0600292 if (m_enableWSI) {
293 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
294 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
295#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
296#if defined(VK_USE_PLATFORM_ANDROID_KHR)
297 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
298#endif // VK_USE_PLATFORM_ANDROID_KHR
299#if defined(VK_USE_PLATFORM_MIR_KHR)
300 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
301#endif // VK_USE_PLATFORM_MIR_KHR
302#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
303 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
304#endif // VK_USE_PLATFORM_WAYLAND_KHR
305#if defined(VK_USE_PLATFORM_WIN32_KHR)
306 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
307#endif // VK_USE_PLATFORM_WIN32_KHR
308#endif // NEED_TO_TEST_THIS_ON_PLATFORM
309#if defined(VK_USE_PLATFORM_XCB_KHR)
310 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
311#elif defined(VK_USE_PLATFORM_XLIB_KHR)
312 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
313#endif // VK_USE_PLATFORM_XLIB_KHR
314 }
315
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600316 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600317 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800318 this->app_info.pApplicationName = "layer_tests";
319 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600320 this->app_info.pEngineName = "unittest";
321 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600322 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600323
Tony Barbour15524c32015-04-29 17:34:29 -0600324 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600325 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600326 }
327
328 virtual void TearDown() {
329 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600330 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600331 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600332 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600333
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600334 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600335};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500336
Karl Schultz6addd812016-02-02 17:17:23 -0700337VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600338 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600339
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800340 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600341
342 /*
343 * For render test all drawing happens in a single render pass
344 * on a single command buffer.
345 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200346 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800347 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600348 }
349
350 return result;
351}
352
Karl Schultz6addd812016-02-02 17:17:23 -0700353VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600354 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600355
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200356 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800357 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200358 }
Tony Barbour300a6082015-04-07 13:44:53 -0600359
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800360 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600361
362 return result;
363}
364
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600365void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500366 // Create identity matrix
367 int i;
368 struct vktriangle_vs_uniform data;
369
370 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700371 glm::mat4 View = glm::mat4(1.0f);
372 glm::mat4 Model = glm::mat4(1.0f);
373 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500374 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700375 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500376
377 memcpy(&data.mvp, &MVP[0][0], matrixSize);
378
Karl Schultz6addd812016-02-02 17:17:23 -0700379 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600380 {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 -0500381 };
382
Karl Schultz6addd812016-02-02 17:17:23 -0700383 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500384 data.position[i][0] = tri_data[i].posX;
385 data.position[i][1] = tri_data[i].posY;
386 data.position[i][2] = tri_data[i].posZ;
387 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700388 data.color[i][0] = tri_data[i].r;
389 data.color[i][1] = tri_data[i].g;
390 data.color[i][2] = tri_data[i].b;
391 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392 }
393
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394 ASSERT_NO_FATAL_FAILURE(InitViewport());
395
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200396 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
397 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500398
Karl Schultz6addd812016-02-02 17:17:23 -0700399 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600400 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500401
402 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800403 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500404 pipelineobj.AddShader(&vs);
405 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600406 if (failMask & BsoFailLineWidth) {
407 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600408 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600410 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
411 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600412 }
413 if (failMask & BsoFailDepthBias) {
414 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600415 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600417 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600418 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600419 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600420 }
Karl Schultz6addd812016-02-02 17:17:23 -0700421 // Viewport and scissors must stay in synch or other errors will occur than
422 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600423 if (failMask & BsoFailViewport) {
424 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
425 }
426 if (failMask & BsoFailScissor) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
428 }
429 if (failMask & BsoFailBlend) {
430 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600431 VkPipelineColorBlendAttachmentState att_state = {};
432 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
433 att_state.blendEnable = VK_TRUE;
434 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600435 }
436 if (failMask & BsoFailDepthBounds) {
437 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
438 }
439 if (failMask & BsoFailStencilReadMask) {
440 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
441 }
442 if (failMask & BsoFailStencilWriteMask) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
444 }
445 if (failMask & BsoFailStencilReference) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
447 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500448
449 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600450 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451
452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600453 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500454
Tony Barbourfe3351b2015-07-28 10:17:20 -0600455 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456
457 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600458 if (failMask & BsoFailIndexBuffer) {
459 // Use DrawIndexed w/o an index buffer bound
460 DrawIndexed(3, 1, 0, 0, 0);
461 } else {
462 Draw(3, 1, 0, 0);
463 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464
Mark Muellerd4914412016-06-13 17:52:06 -0600465 if (failMask & BsoFailCmdClearAttachments) {
466 VkClearAttachment color_attachment = {};
467 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
468 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
469 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
470
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600471 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600472 }
473
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600475 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476
Tony Barbourfe3351b2015-07-28 10:17:20 -0600477 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478}
479
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600480void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
481 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600485 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486 }
487
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800488 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700489 // Make sure depthWriteEnable is set so that Depth fail test will work
490 // correctly
491 // Make sure stencilTestEnable is set so that Stencil fail test will work
492 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600493 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800494 stencil.failOp = VK_STENCIL_OP_KEEP;
495 stencil.passOp = VK_STENCIL_OP_KEEP;
496 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
497 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600498
499 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
500 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600501 ds_ci.pNext = NULL;
502 ds_ci.depthTestEnable = VK_FALSE;
503 ds_ci.depthWriteEnable = VK_TRUE;
504 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
505 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600506 if (failMask & BsoFailDepthBounds) {
507 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600508 ds_ci.maxDepthBounds = 0.0f;
509 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600510 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600511 ds_ci.stencilTestEnable = VK_TRUE;
512 ds_ci.front = stencil;
513 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600514
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600515 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600516 pipelineobj.SetViewport(m_viewports);
517 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800518 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600519 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600520 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800521 commandBuffer->BindPipeline(pipelineobj);
522 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523}
524
Ian Elliott2c1daf52016-05-12 09:41:46 -0600525class VkWsiEnabledLayerTest : public VkLayerTest {
526 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600527 protected:
528 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600529};
530
Mark Muellerdfe37552016-07-07 14:47:42 -0600531class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600533 enum eTestEnFlags {
534 eDoubleDelete,
535 eInvalidDeviceOffset,
536 eInvalidMemoryOffset,
537 eBindNullBuffer,
538 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600539 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600540 };
541
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600542 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600543
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
545 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600546 return true;
547 }
548 VkDeviceSize offset_limit = 0;
549 if (eInvalidMemoryOffset == aTestFlag) {
550 VkBuffer vulkanBuffer;
551 VkBufferCreateInfo buffer_create_info = {};
552 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
553 buffer_create_info.size = 32;
554 buffer_create_info.usage = aBufferUsage;
555
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600556 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600557 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600558
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600559 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600560 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
561 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600562 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
563 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600564 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600565 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600566 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600568 }
569 if (eOffsetAlignment < offset_limit) {
570 return true;
571 }
572 return false;
573 }
574
575 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600576 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
577 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600578
579 if (eBindNullBuffer == aTestFlag) {
580 VulkanMemory = 0;
581 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
582 } else {
583 VkBufferCreateInfo buffer_create_info = {};
584 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
585 buffer_create_info.size = 32;
586 buffer_create_info.usage = aBufferUsage;
587
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600588 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600589
590 CreateCurrent = true;
591
592 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600594
595 VkMemoryAllocateInfo memory_allocate_info = {};
596 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
597 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
599 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 if (!pass) {
601 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
602 return;
603 }
604
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600605 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600606 AllocateCurrent = true;
607 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600608 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
609 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600610 BoundCurrent = true;
611
612 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
613 }
614 }
615
616 ~VkBufferTest() {
617 if (CreateCurrent) {
618 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
619 }
620 if (AllocateCurrent) {
621 if (InvalidDeleteEn) {
622 union {
623 VkDeviceMemory device_memory;
624 unsigned long long index_access;
625 } bad_index;
626
627 bad_index.device_memory = VulkanMemory;
628 bad_index.index_access++;
629
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 }
632 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
633 }
634 }
635
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600636 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600637
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600638 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600639
640 void TestDoubleDestroy() {
641 // Destroy the buffer but leave the flag set, which will cause
642 // the buffer to be destroyed again in the destructor.
643 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
644 }
645
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600646 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600647 bool AllocateCurrent;
648 bool BoundCurrent;
649 bool CreateCurrent;
650 bool InvalidDeleteEn;
651
652 VkBuffer VulkanBuffer;
653 VkDevice VulkanDevice;
654 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655};
656
657class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600658 public:
659 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600661 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600662 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
664 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600665 BindIdGenerator++; // NB: This can wrap w/misuse
666
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
668 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600669
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600670 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
671 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
672 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
673 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
674 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600675
676 unsigned i = 0;
677 do {
678 VertexInputAttributeDescription[i].binding = BindId;
679 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600680 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
681 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600682 i++;
683 } while (AttributeCount < i);
684
685 i = 0;
686 do {
687 VertexInputBindingDescription[i].binding = BindId;
688 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600689 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600690 i++;
691 } while (BindingCount < i);
692 }
693
694 ~VkVerticesObj() {
695 if (VertexInputAttributeDescription) {
696 delete[] VertexInputAttributeDescription;
697 }
698 if (VertexInputBindingDescription) {
699 delete[] VertexInputBindingDescription;
700 }
701 }
702
703 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
705 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600706 return true;
707 }
708
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600709 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600710 VkDeviceSize *offsetList;
711 unsigned offsetCount;
712
713 if (aOffsetCount) {
714 offsetList = aOffsetList;
715 offsetCount = aOffsetCount;
716 } else {
717 offsetList = new VkDeviceSize[1]();
718 offsetCount = 1;
719 }
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BoundCurrent = true;
723
724 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600725 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600726 }
727 }
728
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600729 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600730 static uint32_t BindIdGenerator;
731
732 bool BoundCurrent;
733 unsigned AttributeCount;
734 unsigned BindingCount;
735 uint32_t BindId;
736
737 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
738 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
739 VkVertexInputBindingDescription *VertexInputBindingDescription;
740 VkConstantBufferObj VulkanMemoryBuffer;
741};
742
743uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500744// ********************************************************************************************************************
745// ********************************************************************************************************************
746// ********************************************************************************************************************
747// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600748#if PARAMETER_VALIDATION_TESTS
749TEST_F(VkLayerTest, RequiredParameter) {
750 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
751 "pointer, array, and array count parameters");
752
753 ASSERT_NO_FATAL_FAILURE(InitState());
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600756 // Specify NULL for a pointer to a handle
757 // Expected to trigger an error with
758 // parameter_validation::validate_required_pointer
759 vkGetPhysicalDeviceFeatures(gpu(), NULL);
760 m_errorMonitor->VerifyFound();
761
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
763 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600764 // Specify NULL for pointer to array count
765 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600766 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600767 m_errorMonitor->VerifyFound();
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600770 // Specify 0 for a required array count
771 // Expected to trigger an error with parameter_validation::validate_array
772 VkViewport view_port = {};
773 m_commandBuffer->SetViewport(0, 0, &view_port);
774 m_errorMonitor->VerifyFound();
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600777 // Specify NULL for a required array
778 // Expected to trigger an error with parameter_validation::validate_array
779 m_commandBuffer->SetViewport(0, 1, NULL);
780 m_errorMonitor->VerifyFound();
781
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600783 // Specify VK_NULL_HANDLE for a required handle
784 // Expected to trigger an error with
785 // parameter_validation::validate_required_handle
786 vkUnmapMemory(device(), VK_NULL_HANDLE);
787 m_errorMonitor->VerifyFound();
788
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
790 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600791 // Specify VK_NULL_HANDLE for a required handle array entry
792 // Expected to trigger an error with
793 // parameter_validation::validate_required_handle_array
794 VkFence fence = VK_NULL_HANDLE;
795 vkResetFences(device(), 1, &fence);
796 m_errorMonitor->VerifyFound();
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600799 // Specify NULL for a required struct pointer
800 // Expected to trigger an error with
801 // parameter_validation::validate_struct_type
802 VkDeviceMemory memory = VK_NULL_HANDLE;
803 vkAllocateMemory(device(), NULL, NULL, &memory);
804 m_errorMonitor->VerifyFound();
805
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600807 // Specify 0 for a required VkFlags parameter
808 // Expected to trigger an error with parameter_validation::validate_flags
809 m_commandBuffer->SetStencilReference(0, 0);
810 m_errorMonitor->VerifyFound();
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 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 -0600813 // Specify 0 for a required VkFlags array entry
814 // Expected to trigger an error with
815 // parameter_validation::validate_flags_array
816 VkSemaphore semaphore = VK_NULL_HANDLE;
817 VkPipelineStageFlags stageFlags = 0;
818 VkSubmitInfo submitInfo = {};
819 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
820 submitInfo.waitSemaphoreCount = 1;
821 submitInfo.pWaitSemaphores = &semaphore;
822 submitInfo.pWaitDstStageMask = &stageFlags;
823 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
824 m_errorMonitor->VerifyFound();
825}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600826
Dustin Gravesfce74c02016-05-10 11:42:58 -0600827TEST_F(VkLayerTest, ReservedParameter) {
828 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600833 // Specify 0 for a reserved VkFlags parameter
834 // Expected to trigger an error with
835 // parameter_validation::validate_reserved_flags
836 VkEvent event_handle = VK_NULL_HANDLE;
837 VkEventCreateInfo event_info = {};
838 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
839 event_info.flags = 1;
840 vkCreateEvent(device(), &event_info, NULL, &event_handle);
841 m_errorMonitor->VerifyFound();
842}
843
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600844TEST_F(VkLayerTest, InvalidStructSType) {
845 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
846 "structure's sType field");
847
848 ASSERT_NO_FATAL_FAILURE(InitState());
849
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600851 // Zero struct memory, effectively setting sType to
852 // VK_STRUCTURE_TYPE_APPLICATION_INFO
853 // Expected to trigger an error with
854 // parameter_validation::validate_struct_type
855 VkMemoryAllocateInfo alloc_info = {};
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600861 // Zero struct memory, effectively setting sType to
862 // VK_STRUCTURE_TYPE_APPLICATION_INFO
863 // Expected to trigger an error with
864 // parameter_validation::validate_struct_type_array
865 VkSubmitInfo submit_info = {};
866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
867 m_errorMonitor->VerifyFound();
868}
869
870TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600871 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600872
873 ASSERT_NO_FATAL_FAILURE(InitState());
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600876 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600877 // NULL.
878 // Need to pick a function that has no allowed pNext structure types.
879 // Expected to trigger an error with
880 // parameter_validation::validate_struct_pnext
881 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600882 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600883 // Zero-initialization will provide the correct sType
884 VkApplicationInfo app_info = {};
885 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
886 event_alloc_info.pNext = &app_info;
887 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
888 m_errorMonitor->VerifyFound();
889
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
891 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600892 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
893 // a function that has allowed pNext structure types and specify
894 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 // Expected to trigger an error with
896 // parameter_validation::validate_struct_pnext
897 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600898 VkMemoryAllocateInfo memory_alloc_info = {};
899 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
900 memory_alloc_info.pNext = &app_info;
901 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600902 m_errorMonitor->VerifyFound();
903
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600904 // Positive test to check parameter_validation and unique_objects support
905 // for NV_dedicated_allocation
906 uint32_t extension_count = 0;
907 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600908 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600909 ASSERT_VK_SUCCESS(err);
910
911 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600912 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600915 ASSERT_VK_SUCCESS(err);
916
917 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600919 supports_nv_dedicated_allocation = true;
920 }
921 }
922 }
923
924 if (supports_nv_dedicated_allocation) {
925 m_errorMonitor->ExpectSuccess();
926
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600927 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
928 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600929 dedicated_buffer_create_info.pNext = nullptr;
930 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
931
932 uint32_t queue_family_index = 0;
933 VkBufferCreateInfo buffer_create_info = {};
934 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
935 buffer_create_info.pNext = &dedicated_buffer_create_info;
936 buffer_create_info.size = 1024;
937 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
938 buffer_create_info.queueFamilyIndexCount = 1;
939 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
940
941 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600943 ASSERT_VK_SUCCESS(err);
944
945 VkMemoryRequirements memory_reqs;
946 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
947
948 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600949 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600950 dedicated_memory_info.pNext = nullptr;
951 dedicated_memory_info.buffer = buffer;
952 dedicated_memory_info.image = VK_NULL_HANDLE;
953
954 VkMemoryAllocateInfo memory_info = {};
955 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
956 memory_info.pNext = &dedicated_memory_info;
957 memory_info.allocationSize = memory_reqs.size;
958
959 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600961 ASSERT_TRUE(pass);
962
963 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600965 ASSERT_VK_SUCCESS(err);
966
967 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
968 ASSERT_VK_SUCCESS(err);
969
970 vkDestroyBuffer(m_device->device(), buffer, NULL);
971 vkFreeMemory(m_device->device(), buffer_memory, NULL);
972
973 m_errorMonitor->VerifyNotFound();
974 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600975}
Dustin Graves5d33d532016-05-09 16:21:12 -0600976
977TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979
980 ASSERT_NO_FATAL_FAILURE(InitState());
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
983 "range of the core VkFormat "
984 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 // Specify an invalid VkFormat value
986 // Expected to trigger an error with
987 // parameter_validation::validate_ranged_enum
988 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600990 m_errorMonitor->VerifyFound();
991
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600992 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 -0600993 // Specify an invalid VkFlags bitmask value
994 // Expected to trigger an error with parameter_validation::validate_flags
995 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
997 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600998 m_errorMonitor->VerifyFound();
999
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 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 -06001001 // Specify an invalid VkFlags array entry
1002 // Expected to trigger an error with
1003 // parameter_validation::validate_flags_array
1004 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001005 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001006 VkSubmitInfo submit_info = {};
1007 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1008 submit_info.waitSemaphoreCount = 1;
1009 submit_info.pWaitSemaphores = &semaphore;
1010 submit_info.pWaitDstStageMask = &stage_flags;
1011 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1012 m_errorMonitor->VerifyFound();
1013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001015 // Specify an invalid VkBool32 value
1016 // Expected to trigger a warning with
1017 // parameter_validation::validate_bool32
1018 VkSampler sampler = VK_NULL_HANDLE;
1019 VkSamplerCreateInfo sampler_info = {};
1020 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1021 sampler_info.pNext = NULL;
1022 sampler_info.magFilter = VK_FILTER_NEAREST;
1023 sampler_info.minFilter = VK_FILTER_NEAREST;
1024 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1025 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1026 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1027 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1028 sampler_info.mipLodBias = 1.0;
1029 sampler_info.maxAnisotropy = 1;
1030 sampler_info.compareEnable = VK_FALSE;
1031 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1032 sampler_info.minLod = 1.0;
1033 sampler_info.maxLod = 1.0;
1034 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1035 sampler_info.unnormalizedCoordinates = VK_FALSE;
1036 // Not VK_TRUE or VK_FALSE
1037 sampler_info.anisotropyEnable = 3;
1038 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1039 m_errorMonitor->VerifyFound();
1040}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001041
1042TEST_F(VkLayerTest, FailedReturnValue) {
1043 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1044
1045 ASSERT_NO_FATAL_FAILURE(InitState());
1046
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 // Find an unsupported image format
1048 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1049 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1050 VkFormat format = static_cast<VkFormat>(f);
1051 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001053 unsupported = format;
1054 break;
1055 }
1056 }
1057
1058 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1060 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001061 // Specify an unsupported VkFormat value to generate a
1062 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1063 // Expected to trigger a warning from
1064 // parameter_validation::validate_result
1065 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001066 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1067 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001068 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1069 m_errorMonitor->VerifyFound();
1070 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001071}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001072
1073TEST_F(VkLayerTest, UpdateBufferAlignment) {
1074 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076
1077 ASSERT_NO_FATAL_FAILURE(InitState());
1078
1079 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1080 vk_testing::Buffer buffer;
1081 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1082
1083 BeginCommandBuffer();
1084 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001086 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1087 m_errorMonitor->VerifyFound();
1088
1089 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is < 0
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1098 m_errorMonitor->VerifyFound();
1099
1100 // Introduce failure by using dataSize that is > 65536
1101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001102 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001103 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1104 m_errorMonitor->VerifyFound();
1105
1106 EndCommandBuffer();
1107}
1108
1109TEST_F(VkLayerTest, FillBufferAlignment) {
1110 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1111
1112 ASSERT_NO_FATAL_FAILURE(InitState());
1113
1114 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1115 vk_testing::Buffer buffer;
1116 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1117
1118 BeginCommandBuffer();
1119
1120 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001122 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1123 m_errorMonitor->VerifyFound();
1124
1125 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001127 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1128 m_errorMonitor->VerifyFound();
1129
1130 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001132 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1133 m_errorMonitor->VerifyFound();
1134
1135 EndCommandBuffer();
1136}
Dustin Graves40f35822016-06-23 11:12:53 -06001137
1138// This is a positive test. No failures are expected.
1139TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1140 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1141 "is ignoring VkWriteDescriptorSet members that are not "
1142 "related to the descriptor type specified by "
1143 "VkWriteDescriptorSet::descriptorType. Correct "
1144 "validation behavior will result in the test running to "
1145 "completion without validation errors.");
1146
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001147 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1148
Dustin Graves40f35822016-06-23 11:12:53 -06001149 ASSERT_NO_FATAL_FAILURE(InitState());
1150
1151 // Image Case
1152 {
1153 m_errorMonitor->ExpectSuccess();
1154
1155 VkImage image;
1156 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1157 const int32_t tex_width = 32;
1158 const int32_t tex_height = 32;
1159 VkImageCreateInfo image_create_info = {};
1160 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1161 image_create_info.pNext = NULL;
1162 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1163 image_create_info.format = tex_format;
1164 image_create_info.extent.width = tex_width;
1165 image_create_info.extent.height = tex_height;
1166 image_create_info.extent.depth = 1;
1167 image_create_info.mipLevels = 1;
1168 image_create_info.arrayLayers = 1;
1169 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001170 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001171 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1172 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001173 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001174 ASSERT_VK_SUCCESS(err);
1175
1176 VkMemoryRequirements memory_reqs;
1177 VkDeviceMemory image_memory;
1178 bool pass;
1179 VkMemoryAllocateInfo memory_info = {};
1180 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1181 memory_info.pNext = NULL;
1182 memory_info.allocationSize = 0;
1183 memory_info.memoryTypeIndex = 0;
1184 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1185 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001186 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001187 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001188 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001189 ASSERT_VK_SUCCESS(err);
1190 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1191 ASSERT_VK_SUCCESS(err);
1192
1193 VkImageViewCreateInfo image_view_create_info = {};
1194 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1195 image_view_create_info.image = image;
1196 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1197 image_view_create_info.format = tex_format;
1198 image_view_create_info.subresourceRange.layerCount = 1;
1199 image_view_create_info.subresourceRange.baseMipLevel = 0;
1200 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001201 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001202
1203 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001204 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001205 ASSERT_VK_SUCCESS(err);
1206
1207 VkDescriptorPoolSize ds_type_count = {};
1208 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1209 ds_type_count.descriptorCount = 1;
1210
1211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1213 ds_pool_ci.pNext = NULL;
1214 ds_pool_ci.maxSets = 1;
1215 ds_pool_ci.poolSizeCount = 1;
1216 ds_pool_ci.pPoolSizes = &ds_type_count;
1217
1218 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001219 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001220 ASSERT_VK_SUCCESS(err);
1221
1222 VkDescriptorSetLayoutBinding dsl_binding = {};
1223 dsl_binding.binding = 0;
1224 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1225 dsl_binding.descriptorCount = 1;
1226 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1227 dsl_binding.pImmutableSamplers = NULL;
1228
1229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001231 ds_layout_ci.pNext = NULL;
1232 ds_layout_ci.bindingCount = 1;
1233 ds_layout_ci.pBindings = &dsl_binding;
1234 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001235 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001236 ASSERT_VK_SUCCESS(err);
1237
1238 VkDescriptorSet descriptor_set;
1239 VkDescriptorSetAllocateInfo alloc_info = {};
1240 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1241 alloc_info.descriptorSetCount = 1;
1242 alloc_info.descriptorPool = ds_pool;
1243 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001244 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001245 ASSERT_VK_SUCCESS(err);
1246
1247 VkDescriptorImageInfo image_info = {};
1248 image_info.imageView = view;
1249 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1250
1251 VkWriteDescriptorSet descriptor_write;
1252 memset(&descriptor_write, 0, sizeof(descriptor_write));
1253 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1254 descriptor_write.dstSet = descriptor_set;
1255 descriptor_write.dstBinding = 0;
1256 descriptor_write.descriptorCount = 1;
1257 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1258 descriptor_write.pImageInfo = &image_info;
1259
1260 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1261 // be
1262 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1263 // This will most likely produce a crash if the parameter_validation
1264 // layer
1265 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001266 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1267 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001269 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001270
1271 m_errorMonitor->VerifyNotFound();
1272
Dustin Graves40f35822016-06-23 11:12:53 -06001273 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1274 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1275 vkDestroyImageView(m_device->device(), view, NULL);
1276 vkDestroyImage(m_device->device(), image, NULL);
1277 vkFreeMemory(m_device->device(), image_memory, NULL);
1278 }
1279
1280 // Buffer Case
1281 {
1282 m_errorMonitor->ExpectSuccess();
1283
1284 VkBuffer buffer;
1285 uint32_t queue_family_index = 0;
1286 VkBufferCreateInfo buffer_create_info = {};
1287 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1288 buffer_create_info.size = 1024;
1289 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1290 buffer_create_info.queueFamilyIndexCount = 1;
1291 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1292
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001293 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001294 ASSERT_VK_SUCCESS(err);
1295
1296 VkMemoryRequirements memory_reqs;
1297 VkDeviceMemory buffer_memory;
1298 bool pass;
1299 VkMemoryAllocateInfo memory_info = {};
1300 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1301 memory_info.pNext = NULL;
1302 memory_info.allocationSize = 0;
1303 memory_info.memoryTypeIndex = 0;
1304
1305 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1306 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001307 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001308 ASSERT_TRUE(pass);
1309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001310 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001311 ASSERT_VK_SUCCESS(err);
1312 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1313 ASSERT_VK_SUCCESS(err);
1314
1315 VkDescriptorPoolSize ds_type_count = {};
1316 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1317 ds_type_count.descriptorCount = 1;
1318
1319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1321 ds_pool_ci.pNext = NULL;
1322 ds_pool_ci.maxSets = 1;
1323 ds_pool_ci.poolSizeCount = 1;
1324 ds_pool_ci.pPoolSizes = &ds_type_count;
1325
1326 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001327 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001328 ASSERT_VK_SUCCESS(err);
1329
1330 VkDescriptorSetLayoutBinding dsl_binding = {};
1331 dsl_binding.binding = 0;
1332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1333 dsl_binding.descriptorCount = 1;
1334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1335 dsl_binding.pImmutableSamplers = NULL;
1336
1337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001339 ds_layout_ci.pNext = NULL;
1340 ds_layout_ci.bindingCount = 1;
1341 ds_layout_ci.pBindings = &dsl_binding;
1342 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001344 ASSERT_VK_SUCCESS(err);
1345
1346 VkDescriptorSet descriptor_set;
1347 VkDescriptorSetAllocateInfo alloc_info = {};
1348 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1349 alloc_info.descriptorSetCount = 1;
1350 alloc_info.descriptorPool = ds_pool;
1351 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001353 ASSERT_VK_SUCCESS(err);
1354
1355 VkDescriptorBufferInfo buffer_info = {};
1356 buffer_info.buffer = buffer;
1357 buffer_info.offset = 0;
1358 buffer_info.range = 1024;
1359
1360 VkWriteDescriptorSet descriptor_write;
1361 memset(&descriptor_write, 0, sizeof(descriptor_write));
1362 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1363 descriptor_write.dstSet = descriptor_set;
1364 descriptor_write.dstBinding = 0;
1365 descriptor_write.descriptorCount = 1;
1366 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1367 descriptor_write.pBufferInfo = &buffer_info;
1368
1369 // Set pImageInfo and pTexelBufferView to invalid values, which should
1370 // be
1371 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1372 // This will most likely produce a crash if the parameter_validation
1373 // layer
1374 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001375 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1376 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001378 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001379
1380 m_errorMonitor->VerifyNotFound();
1381
1382 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1385 vkDestroyBuffer(m_device->device(), buffer, NULL);
1386 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1387 }
1388
1389 // Texel Buffer Case
1390 {
1391 m_errorMonitor->ExpectSuccess();
1392
1393 VkBuffer buffer;
1394 uint32_t queue_family_index = 0;
1395 VkBufferCreateInfo buffer_create_info = {};
1396 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1397 buffer_create_info.size = 1024;
1398 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1399 buffer_create_info.queueFamilyIndexCount = 1;
1400 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1401
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001402 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001403 ASSERT_VK_SUCCESS(err);
1404
1405 VkMemoryRequirements memory_reqs;
1406 VkDeviceMemory buffer_memory;
1407 bool pass;
1408 VkMemoryAllocateInfo memory_info = {};
1409 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1410 memory_info.pNext = NULL;
1411 memory_info.allocationSize = 0;
1412 memory_info.memoryTypeIndex = 0;
1413
1414 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1415 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001416 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001417 ASSERT_TRUE(pass);
1418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001420 ASSERT_VK_SUCCESS(err);
1421 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1422 ASSERT_VK_SUCCESS(err);
1423
1424 VkBufferViewCreateInfo buff_view_ci = {};
1425 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1426 buff_view_ci.buffer = buffer;
1427 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1428 buff_view_ci.range = VK_WHOLE_SIZE;
1429 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001430 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001431
1432 VkDescriptorPoolSize ds_type_count = {};
1433 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1434 ds_type_count.descriptorCount = 1;
1435
1436 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1437 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1438 ds_pool_ci.pNext = NULL;
1439 ds_pool_ci.maxSets = 1;
1440 ds_pool_ci.poolSizeCount = 1;
1441 ds_pool_ci.pPoolSizes = &ds_type_count;
1442
1443 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001444 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001445 ASSERT_VK_SUCCESS(err);
1446
1447 VkDescriptorSetLayoutBinding dsl_binding = {};
1448 dsl_binding.binding = 0;
1449 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1450 dsl_binding.descriptorCount = 1;
1451 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1452 dsl_binding.pImmutableSamplers = NULL;
1453
1454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001456 ds_layout_ci.pNext = NULL;
1457 ds_layout_ci.bindingCount = 1;
1458 ds_layout_ci.pBindings = &dsl_binding;
1459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001461 ASSERT_VK_SUCCESS(err);
1462
1463 VkDescriptorSet descriptor_set;
1464 VkDescriptorSetAllocateInfo alloc_info = {};
1465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1466 alloc_info.descriptorSetCount = 1;
1467 alloc_info.descriptorPool = ds_pool;
1468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001470 ASSERT_VK_SUCCESS(err);
1471
1472 VkWriteDescriptorSet descriptor_write;
1473 memset(&descriptor_write, 0, sizeof(descriptor_write));
1474 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1475 descriptor_write.dstSet = descriptor_set;
1476 descriptor_write.dstBinding = 0;
1477 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001479 descriptor_write.pTexelBufferView = &buffer_view;
1480
1481 // Set pImageInfo and pBufferInfo to invalid values, which should be
1482 // ignored for descriptorType ==
1483 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1484 // This will most likely produce a crash if the parameter_validation
1485 // layer
1486 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001487 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1488 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001489
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001490 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001491
1492 m_errorMonitor->VerifyNotFound();
1493
1494 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1495 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1496 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1497 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1498 vkDestroyBuffer(m_device->device(), buffer, NULL);
1499 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1500 }
1501}
Cortd889ff92016-07-27 09:51:27 -07001502
1503TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1504 VkResult err;
1505
1506 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001507 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001508
1509 ASSERT_NO_FATAL_FAILURE(InitState());
1510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1511
1512 std::vector<const char *> device_extension_names;
1513 auto features = m_device->phy().features();
1514 // Artificially disable support for non-solid fill modes
1515 features.fillModeNonSolid = false;
1516 // The sacrificial device object
1517 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1518
1519 VkRenderpassObj render_pass(&test_device);
1520
1521 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1522 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1523 pipeline_layout_ci.setLayoutCount = 0;
1524 pipeline_layout_ci.pSetLayouts = NULL;
1525
1526 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001527 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001528 ASSERT_VK_SUCCESS(err);
1529
1530 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1531 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1532 rs_ci.pNext = nullptr;
1533 rs_ci.lineWidth = 1.0f;
1534 rs_ci.rasterizerDiscardEnable = true;
1535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1537 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001538
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001539 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1541 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001542 {
1543 VkPipelineObj pipe(&test_device);
1544 pipe.AddShader(&vs);
1545 pipe.AddShader(&fs);
1546 pipe.AddColorAttachment();
1547 // Introduce failure by setting unsupported polygon mode
1548 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1549 pipe.SetRasterization(&rs_ci);
1550 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1551 }
1552 m_errorMonitor->VerifyFound();
1553
1554 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001557 {
1558 VkPipelineObj pipe(&test_device);
1559 pipe.AddShader(&vs);
1560 pipe.AddShader(&fs);
1561 pipe.AddColorAttachment();
1562 // Introduce failure by setting unsupported polygon mode
1563 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1564 pipe.SetRasterization(&rs_ci);
1565 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1566 }
1567 m_errorMonitor->VerifyFound();
1568
1569 // Try again with polygonMode=FILL. No error is expected
1570 m_errorMonitor->ExpectSuccess();
1571 {
1572 VkPipelineObj pipe(&test_device);
1573 pipe.AddShader(&vs);
1574 pipe.AddShader(&fs);
1575 pipe.AddColorAttachment();
1576 // Set polygonMode to a good value
1577 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1578 pipe.SetRasterization(&rs_ci);
1579 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1580 }
1581 m_errorMonitor->VerifyNotFound();
1582
1583 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1584}
1585
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001586#endif // PARAMETER_VALIDATION_TESTS
1587
Tobin Ehlis0788f522015-05-26 16:11:58 -06001588#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001589#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001590TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001591{
1592 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001593 VkFenceCreateInfo fenceInfo = {};
1594 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1595 fenceInfo.pNext = NULL;
1596 fenceInfo.flags = 0;
1597
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001599
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001600 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001601
1602 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1603 vk_testing::Buffer buffer;
1604 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001605
Tony Barbourfe3351b2015-07-28 10:17:20 -06001606 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001607 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001608 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001609
1610 testFence.init(*m_device, fenceInfo);
1611
1612 // Bypass framework since it does the waits automatically
1613 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001614 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001615 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1616 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001617 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001618 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001619 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001620 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001621 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001622 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001623 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001624
1625 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001626 ASSERT_VK_SUCCESS( err );
1627
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001628 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001629 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001630
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001631 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001632}
1633
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001634TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001635{
1636 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001637 VkFenceCreateInfo fenceInfo = {};
1638 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1639 fenceInfo.pNext = NULL;
1640 fenceInfo.flags = 0;
1641
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001643
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001644 ASSERT_NO_FATAL_FAILURE(InitState());
1645 ASSERT_NO_FATAL_FAILURE(InitViewport());
1646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1647
Tony Barbourfe3351b2015-07-28 10:17:20 -06001648 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001649 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001650 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001651
1652 testFence.init(*m_device, fenceInfo);
1653
1654 // Bypass framework since it does the waits automatically
1655 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001656 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001657 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1658 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001659 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001660 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001661 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001662 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001663 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001664 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001665 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001666
1667 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001668 ASSERT_VK_SUCCESS( err );
1669
Jon Ashburnf19916e2016-01-11 13:12:43 -07001670 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001671 VkCommandBufferBeginInfo info = {};
1672 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1673 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001674 info.renderPass = VK_NULL_HANDLE;
1675 info.subpass = 0;
1676 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001677 info.occlusionQueryEnable = VK_FALSE;
1678 info.queryFlags = 0;
1679 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001680
1681 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001682 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001683
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001684 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001685}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001686#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001687
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001688// This is a positive test. No failures are expected.
1689TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1690 VkResult err;
1691 bool pass;
1692
1693 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1694 "the buffer, create an image, and bind the same memory to "
1695 "it");
1696
1697 m_errorMonitor->ExpectSuccess();
1698
1699 ASSERT_NO_FATAL_FAILURE(InitState());
1700
1701 VkBuffer buffer;
1702 VkImage image;
1703 VkDeviceMemory mem;
1704 VkMemoryRequirements mem_reqs;
1705
1706 VkBufferCreateInfo buf_info = {};
1707 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1708 buf_info.pNext = NULL;
1709 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1710 buf_info.size = 256;
1711 buf_info.queueFamilyIndexCount = 0;
1712 buf_info.pQueueFamilyIndices = NULL;
1713 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1714 buf_info.flags = 0;
1715 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1716 ASSERT_VK_SUCCESS(err);
1717
1718 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1719
1720 VkMemoryAllocateInfo alloc_info = {};
1721 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1722 alloc_info.pNext = NULL;
1723 alloc_info.memoryTypeIndex = 0;
1724
1725 // Ensure memory is big enough for both bindings
1726 alloc_info.allocationSize = 0x10000;
1727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001728 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001729 if (!pass) {
1730 vkDestroyBuffer(m_device->device(), buffer, NULL);
1731 return;
1732 }
1733
1734 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1735 ASSERT_VK_SUCCESS(err);
1736
1737 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001738 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001739 ASSERT_VK_SUCCESS(err);
1740
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001741 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001742
1743 vkUnmapMemory(m_device->device(), mem);
1744
1745 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1746 ASSERT_VK_SUCCESS(err);
1747
1748 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1749 // memory. In fact, it was never used by the GPU.
1750 // Just be be sure, wait for idle.
1751 vkDestroyBuffer(m_device->device(), buffer, NULL);
1752 vkDeviceWaitIdle(m_device->device());
1753
1754 VkImageCreateInfo image_create_info = {};
1755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1756 image_create_info.pNext = NULL;
1757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1758 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1759 image_create_info.extent.width = 64;
1760 image_create_info.extent.height = 64;
1761 image_create_info.extent.depth = 1;
1762 image_create_info.mipLevels = 1;
1763 image_create_info.arrayLayers = 1;
1764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1765 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1766 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1767 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1768 image_create_info.queueFamilyIndexCount = 0;
1769 image_create_info.pQueueFamilyIndices = NULL;
1770 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1771 image_create_info.flags = 0;
1772
1773 VkMemoryAllocateInfo mem_alloc = {};
1774 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1775 mem_alloc.pNext = NULL;
1776 mem_alloc.allocationSize = 0;
1777 mem_alloc.memoryTypeIndex = 0;
1778
1779 /* Create a mappable image. It will be the texture if linear images are ok
1780 * to be textures or it will be the staging image if they are not.
1781 */
1782 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1783 ASSERT_VK_SUCCESS(err);
1784
1785 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1786
1787 mem_alloc.allocationSize = mem_reqs.size;
1788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001790 if (!pass) {
1791 vkDestroyImage(m_device->device(), image, NULL);
1792 return;
1793 }
1794
Tobin Ehlis077ded32016-05-12 17:39:13 -06001795 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001796 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1797 ASSERT_VK_SUCCESS(err);
1798
1799 m_errorMonitor->VerifyNotFound();
1800
Tony Barbourdf4c0042016-06-01 15:55:43 -06001801 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001802 vkDestroyBuffer(m_device->device(), buffer, NULL);
1803 vkDestroyImage(m_device->device(), image, NULL);
1804}
1805
Tobin Ehlisf11be982016-05-11 13:52:53 -06001806TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1807 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1808 "buffer and image to memory such that they will alias.");
1809 VkResult err;
1810 bool pass;
1811 ASSERT_NO_FATAL_FAILURE(InitState());
1812
Tobin Ehlis077ded32016-05-12 17:39:13 -06001813 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001814 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001815 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001816 VkDeviceMemory mem; // buffer will be bound first
1817 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001818 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001819
1820 VkBufferCreateInfo buf_info = {};
1821 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1822 buf_info.pNext = NULL;
1823 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1824 buf_info.size = 256;
1825 buf_info.queueFamilyIndexCount = 0;
1826 buf_info.pQueueFamilyIndices = NULL;
1827 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1828 buf_info.flags = 0;
1829 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1830 ASSERT_VK_SUCCESS(err);
1831
Tobin Ehlis077ded32016-05-12 17:39:13 -06001832 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001833
1834 VkImageCreateInfo image_create_info = {};
1835 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1836 image_create_info.pNext = NULL;
1837 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1838 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1839 image_create_info.extent.width = 64;
1840 image_create_info.extent.height = 64;
1841 image_create_info.extent.depth = 1;
1842 image_create_info.mipLevels = 1;
1843 image_create_info.arrayLayers = 1;
1844 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001845 // Image tiling must be optimal to trigger error when aliasing linear buffer
1846 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001847 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1849 image_create_info.queueFamilyIndexCount = 0;
1850 image_create_info.pQueueFamilyIndices = NULL;
1851 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1852 image_create_info.flags = 0;
1853
Tobin Ehlisf11be982016-05-11 13:52:53 -06001854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1855 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001856 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1857 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001858
Tobin Ehlis077ded32016-05-12 17:39:13 -06001859 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1860
1861 VkMemoryAllocateInfo alloc_info = {};
1862 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1863 alloc_info.pNext = NULL;
1864 alloc_info.memoryTypeIndex = 0;
1865 // Ensure memory is big enough for both bindings
1866 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001867 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1868 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001869 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001870 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001871 vkDestroyImage(m_device->device(), image, NULL);
1872 return;
1873 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001874 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1875 ASSERT_VK_SUCCESS(err);
1876 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1877 ASSERT_VK_SUCCESS(err);
1878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001880 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001881 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1882 m_errorMonitor->VerifyFound();
1883
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001884 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001885 // aliasing buffer2
1886 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1887 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1889 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001890 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001891 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001893 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001894 m_errorMonitor->VerifyFound();
1895
1896 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001897 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001898 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001899 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001900 vkFreeMemory(m_device->device(), mem, NULL);
1901 vkFreeMemory(m_device->device(), mem_img, NULL);
1902}
1903
Tobin Ehlis35372522016-05-12 08:32:31 -06001904TEST_F(VkLayerTest, InvalidMemoryMapping) {
1905 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1906 VkResult err;
1907 bool pass;
1908 ASSERT_NO_FATAL_FAILURE(InitState());
1909
1910 VkBuffer buffer;
1911 VkDeviceMemory mem;
1912 VkMemoryRequirements mem_reqs;
1913
1914 VkBufferCreateInfo buf_info = {};
1915 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1916 buf_info.pNext = NULL;
1917 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1918 buf_info.size = 256;
1919 buf_info.queueFamilyIndexCount = 0;
1920 buf_info.pQueueFamilyIndices = NULL;
1921 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1922 buf_info.flags = 0;
1923 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1924 ASSERT_VK_SUCCESS(err);
1925
1926 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1927 VkMemoryAllocateInfo alloc_info = {};
1928 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1929 alloc_info.pNext = NULL;
1930 alloc_info.memoryTypeIndex = 0;
1931
1932 // Ensure memory is big enough for both bindings
1933 static const VkDeviceSize allocation_size = 0x10000;
1934 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001935 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 -06001936 if (!pass) {
1937 vkDestroyBuffer(m_device->device(), buffer, NULL);
1938 return;
1939 }
1940 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1941 ASSERT_VK_SUCCESS(err);
1942
1943 uint8_t *pData;
1944 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 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 -06001946 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1947 m_errorMonitor->VerifyFound();
1948 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001950 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1952 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1953 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001954 m_errorMonitor->VerifyFound();
1955
1956 // Unmap the memory to avoid re-map error
1957 vkUnmapMemory(m_device->device(), mem);
1958 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1960 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1961 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 m_errorMonitor->VerifyFound();
1963 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1965 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001966 m_errorMonitor->VerifyFound();
1967 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001969 vkUnmapMemory(m_device->device(), mem);
1970 m_errorMonitor->VerifyFound();
1971 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001972 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001973 ASSERT_VK_SUCCESS(err);
1974 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001975 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001976 mmr.memory = mem;
1977 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001979 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1980 m_errorMonitor->VerifyFound();
1981 // Now flush range that oversteps mapped range
1982 vkUnmapMemory(m_device->device(), mem);
1983 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1984 ASSERT_VK_SUCCESS(err);
1985 mmr.offset = 16;
1986 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001988 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1989 m_errorMonitor->VerifyFound();
1990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001991 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1992 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001993 if (!pass) {
1994 vkFreeMemory(m_device->device(), mem, NULL);
1995 vkDestroyBuffer(m_device->device(), buffer, NULL);
1996 return;
1997 }
1998 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1999 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
2000
2001 vkDestroyBuffer(m_device->device(), buffer, NULL);
2002 vkFreeMemory(m_device->device(), mem, NULL);
2003}
2004
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002005TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
2006
2007 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
2008 "mapping while using VK_WHOLE_SIZE does not cause access "
2009 "violations");
2010 VkResult err;
2011 uint8_t *pData;
2012 ASSERT_NO_FATAL_FAILURE(InitState());
2013
2014 VkDeviceMemory mem;
2015 VkMemoryRequirements mem_reqs;
2016 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2017 VkMemoryAllocateInfo alloc_info = {};
2018 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2019 alloc_info.pNext = NULL;
2020 alloc_info.memoryTypeIndex = 0;
2021
2022 static const VkDeviceSize allocation_size = 0x1000;
2023 alloc_info.allocationSize = allocation_size;
2024
2025 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002026 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2027 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002028 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002029 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2030 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2031 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002032 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002033 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2034 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2035 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2036 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002037 if (!pass) {
2038 return;
2039 }
2040 }
2041 }
2042
2043 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2044 ASSERT_VK_SUCCESS(err);
2045
2046 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2047 // mapped range
2048 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002049 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002050 ASSERT_VK_SUCCESS(err);
2051 VkMappedMemoryRange mmr = {};
2052 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2053 mmr.memory = mem;
2054 mmr.offset = 0;
2055 mmr.size = VK_WHOLE_SIZE;
2056 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2057 ASSERT_VK_SUCCESS(err);
2058 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2059 ASSERT_VK_SUCCESS(err);
2060 m_errorMonitor->VerifyNotFound();
2061 vkUnmapMemory(m_device->device(), mem);
2062
2063 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2064 // mapped range
2065 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002067 ASSERT_VK_SUCCESS(err);
2068 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2069 mmr.memory = mem;
2070 mmr.offset = 13;
2071 mmr.size = VK_WHOLE_SIZE;
2072 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2073 ASSERT_VK_SUCCESS(err);
2074 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2075 ASSERT_VK_SUCCESS(err);
2076 m_errorMonitor->VerifyNotFound();
2077 vkUnmapMemory(m_device->device(), mem);
2078
2079 // Map with prime offset and size
2080 // Flush/Invalidate subrange of mapped area with prime offset and size
2081 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002082 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002083 ASSERT_VK_SUCCESS(err);
2084 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2085 mmr.memory = mem;
2086 mmr.offset = allocation_size - 107;
2087 mmr.size = 61;
2088 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2089 ASSERT_VK_SUCCESS(err);
2090 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2091 ASSERT_VK_SUCCESS(err);
2092 m_errorMonitor->VerifyNotFound();
2093 vkUnmapMemory(m_device->device(), mem);
2094
2095 vkFreeMemory(m_device->device(), mem, NULL);
2096}
2097
Ian Elliott1c32c772016-04-28 14:47:13 -06002098TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2099 VkResult err;
2100 bool pass;
2101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002102 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2103 // following declaration (which is temporarily being moved below):
2104 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002105 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2106 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2107 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002108 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002109 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002111
2112 ASSERT_NO_FATAL_FAILURE(InitState());
2113
Ian Elliott3f06ce52016-04-29 14:46:21 -06002114#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2115#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2116 // Use the functions from the VK_KHR_android_surface extension without
2117 // enabling that extension:
2118
2119 // Create a surface:
2120 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2122 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002123 pass = (err != VK_SUCCESS);
2124 ASSERT_TRUE(pass);
2125 m_errorMonitor->VerifyFound();
2126#endif // VK_USE_PLATFORM_ANDROID_KHR
2127
Ian Elliott3f06ce52016-04-29 14:46:21 -06002128#if defined(VK_USE_PLATFORM_MIR_KHR)
2129 // Use the functions from the VK_KHR_mir_surface extension without enabling
2130 // that extension:
2131
2132 // Create a surface:
2133 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002135 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2136 pass = (err != VK_SUCCESS);
2137 ASSERT_TRUE(pass);
2138 m_errorMonitor->VerifyFound();
2139
2140 // Tell whether an mir_connection supports presentation:
2141 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2143 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002144 m_errorMonitor->VerifyFound();
2145#endif // VK_USE_PLATFORM_MIR_KHR
2146
Ian Elliott3f06ce52016-04-29 14:46:21 -06002147#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2148 // Use the functions from the VK_KHR_wayland_surface extension without
2149 // enabling that extension:
2150
2151 // Create a surface:
2152 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2154 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155 pass = (err != VK_SUCCESS);
2156 ASSERT_TRUE(pass);
2157 m_errorMonitor->VerifyFound();
2158
2159 // Tell whether an wayland_display supports presentation:
2160 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2162 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002163 m_errorMonitor->VerifyFound();
2164#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002165#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002166
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002168 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2169 // TO NON-LINUX PLATFORMS:
2170 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002171 // Use the functions from the VK_KHR_win32_surface extension without
2172 // enabling that extension:
2173
2174 // Create a surface:
2175 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2177 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178 pass = (err != VK_SUCCESS);
2179 ASSERT_TRUE(pass);
2180 m_errorMonitor->VerifyFound();
2181
2182 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002184 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002185 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002186// Set this (for now, until all platforms are supported and tested):
2187#define NEED_TO_TEST_THIS_ON_PLATFORM
2188#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002189
Ian Elliott1c32c772016-04-28 14:47:13 -06002190#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002191 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2192 // TO NON-LINUX PLATFORMS:
2193 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002194 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2195 // that extension:
2196
2197 // Create a surface:
2198 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002200 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2201 pass = (err != VK_SUCCESS);
2202 ASSERT_TRUE(pass);
2203 m_errorMonitor->VerifyFound();
2204
2205 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002206 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002207 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2209 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002210 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002211// Set this (for now, until all platforms are supported and tested):
2212#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002213#endif // VK_USE_PLATFORM_XCB_KHR
2214
Ian Elliott12630812016-04-29 14:35:43 -06002215#if defined(VK_USE_PLATFORM_XLIB_KHR)
2216 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2217 // that extension:
2218
2219 // Create a surface:
2220 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002222 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2223 pass = (err != VK_SUCCESS);
2224 ASSERT_TRUE(pass);
2225 m_errorMonitor->VerifyFound();
2226
2227 // Tell whether an Xlib VisualID supports presentation:
2228 Display *dpy = NULL;
2229 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002231 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2232 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002233// Set this (for now, until all platforms are supported and tested):
2234#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002235#endif // VK_USE_PLATFORM_XLIB_KHR
2236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237// Use the functions from the VK_KHR_surface extension without enabling
2238// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002239
Ian Elliott489eec02016-05-05 14:12:44 -06002240#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002241 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002243 vkDestroySurfaceKHR(instance(), surface, NULL);
2244 m_errorMonitor->VerifyFound();
2245
2246 // Check if surface supports presentation:
2247 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002249 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2250 pass = (err != VK_SUCCESS);
2251 ASSERT_TRUE(pass);
2252 m_errorMonitor->VerifyFound();
2253
2254 // Check surface capabilities:
2255 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2257 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002258 pass = (err != VK_SUCCESS);
2259 ASSERT_TRUE(pass);
2260 m_errorMonitor->VerifyFound();
2261
2262 // Check surface formats:
2263 uint32_t format_count = 0;
2264 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2266 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002267 pass = (err != VK_SUCCESS);
2268 ASSERT_TRUE(pass);
2269 m_errorMonitor->VerifyFound();
2270
2271 // Check surface present modes:
2272 uint32_t present_mode_count = 0;
2273 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2275 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002276 pass = (err != VK_SUCCESS);
2277 ASSERT_TRUE(pass);
2278 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002279#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002280
Ian Elliott1c32c772016-04-28 14:47:13 -06002281 // Use the functions from the VK_KHR_swapchain extension without enabling
2282 // that extension:
2283
2284 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002286 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2287 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002288 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002289 pass = (err != VK_SUCCESS);
2290 ASSERT_TRUE(pass);
2291 m_errorMonitor->VerifyFound();
2292
2293 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2295 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002296 pass = (err != VK_SUCCESS);
2297 ASSERT_TRUE(pass);
2298 m_errorMonitor->VerifyFound();
2299
Chris Forbeseb7d5502016-09-13 18:19:21 +12002300 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2301 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2302 VkFence fence;
2303 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2304
Ian Elliott1c32c772016-04-28 14:47:13 -06002305 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002307 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002308 pass = (err != VK_SUCCESS);
2309 ASSERT_TRUE(pass);
2310 m_errorMonitor->VerifyFound();
2311
Chris Forbeseb7d5502016-09-13 18:19:21 +12002312 vkDestroyFence(m_device->device(), fence, nullptr);
2313
Ian Elliott1c32c772016-04-28 14:47:13 -06002314 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315 //
2316 // NOTE: Currently can't test this because a real swapchain is needed (as
2317 // opposed to the fake one we created) in order for the layer to lookup the
2318 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002319
2320 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002322 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2323 m_errorMonitor->VerifyFound();
2324}
2325
Ian Elliott2c1daf52016-05-12 09:41:46 -06002326TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002327
Dustin Graves6c6d8982016-05-17 10:09:21 -06002328#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002329 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002330
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002331 VkResult err;
2332 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002333 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2334 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002335 // uint32_t swapchain_image_count = 0;
2336 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2337 // uint32_t image_index = 0;
2338 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002339
2340 ASSERT_NO_FATAL_FAILURE(InitState());
2341
2342 // Use the create function from one of the VK_KHR_*_surface extension in
2343 // order to create a surface, testing all known errors in the process,
2344 // before successfully creating a surface:
2345 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002347 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2348 pass = (err != VK_SUCCESS);
2349 ASSERT_TRUE(pass);
2350 m_errorMonitor->VerifyFound();
2351
2352 // Next, try to create a surface with the wrong
2353 // VkXcbSurfaceCreateInfoKHR::sType:
2354 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2355 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002357 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2358 pass = (err != VK_SUCCESS);
2359 ASSERT_TRUE(pass);
2360 m_errorMonitor->VerifyFound();
2361
Ian Elliott2c1daf52016-05-12 09:41:46 -06002362 // Create a native window, and then correctly create a surface:
2363 xcb_connection_t *connection;
2364 xcb_screen_t *screen;
2365 xcb_window_t xcb_window;
2366 xcb_intern_atom_reply_t *atom_wm_delete_window;
2367
2368 const xcb_setup_t *setup;
2369 xcb_screen_iterator_t iter;
2370 int scr;
2371 uint32_t value_mask, value_list[32];
2372 int width = 1;
2373 int height = 1;
2374
2375 connection = xcb_connect(NULL, &scr);
2376 ASSERT_TRUE(connection != NULL);
2377 setup = xcb_get_setup(connection);
2378 iter = xcb_setup_roots_iterator(setup);
2379 while (scr-- > 0)
2380 xcb_screen_next(&iter);
2381 screen = iter.data;
2382
2383 xcb_window = xcb_generate_id(connection);
2384
2385 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2386 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2390 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002391
2392 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2394 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002396 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002397 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002398 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002399 free(reply);
2400
2401 xcb_map_window(connection, xcb_window);
2402
2403 // Force the x/y coordinates to 100,100 results are identical in consecutive
2404 // runs
2405 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002406 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407
Ian Elliott2c1daf52016-05-12 09:41:46 -06002408 // Finally, try to correctly create a surface:
2409 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2410 xcb_create_info.pNext = NULL;
2411 xcb_create_info.flags = 0;
2412 xcb_create_info.connection = connection;
2413 xcb_create_info.window = xcb_window;
2414 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2415 pass = (err == VK_SUCCESS);
2416 ASSERT_TRUE(pass);
2417
Ian Elliott2c1daf52016-05-12 09:41:46 -06002418 // Check if surface supports presentation:
2419
2420 // 1st, do so without having queried the queue families:
2421 VkBool32 supported = false;
2422 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2424 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2425 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002426 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2427 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002428 // ASSERT_TRUE(pass);
2429 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430
2431 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2433 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 pass = (err != VK_SUCCESS);
2435 ASSERT_TRUE(pass);
2436 m_errorMonitor->VerifyFound();
2437
2438 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002439 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2440 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002441 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2442 pass = (err == VK_SUCCESS);
2443 ASSERT_TRUE(pass);
2444
Ian Elliott2c1daf52016-05-12 09:41:46 -06002445 // Before proceeding, try to create a swapchain without having called
2446 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2447 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2448 swapchain_create_info.pNext = NULL;
2449 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2451 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2452 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002453 pass = (err != VK_SUCCESS);
2454 ASSERT_TRUE(pass);
2455 m_errorMonitor->VerifyFound();
2456
Ian Elliott2c1daf52016-05-12 09:41:46 -06002457 // Get the surface capabilities:
2458 VkSurfaceCapabilitiesKHR surface_capabilities;
2459
2460 // Do so correctly (only error logged by this entrypoint is if the
2461 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002462 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002463 pass = (err == VK_SUCCESS);
2464 ASSERT_TRUE(pass);
2465
Ian Elliott2c1daf52016-05-12 09:41:46 -06002466 // Get the surface formats:
2467 uint32_t surface_format_count;
2468
2469 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2471 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002472 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2473 pass = (err == VK_SUCCESS);
2474 ASSERT_TRUE(pass);
2475 m_errorMonitor->VerifyFound();
2476
2477 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2478 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002480 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002481 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002482 pass = (err == VK_SUCCESS);
2483 ASSERT_TRUE(pass);
2484 m_errorMonitor->VerifyFound();
2485
2486 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002487 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002488 pass = (err == VK_SUCCESS);
2489 ASSERT_TRUE(pass);
2490
2491 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002493
2494 // Next, do a 2nd try with surface_format_count being set too high:
2495 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2497 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002498 pass = (err == VK_SUCCESS);
2499 ASSERT_TRUE(pass);
2500 m_errorMonitor->VerifyFound();
2501
2502 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002504 pass = (err == VK_SUCCESS);
2505 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002506 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002507 pass = (err == VK_SUCCESS);
2508 ASSERT_TRUE(pass);
2509
Ian Elliott2c1daf52016-05-12 09:41:46 -06002510 // Get the surface present modes:
2511 uint32_t surface_present_mode_count;
2512
2513 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2515 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002516
Ian Elliott2c1daf52016-05-12 09:41:46 -06002517 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2518 pass = (err == VK_SUCCESS);
2519 ASSERT_TRUE(pass);
2520 m_errorMonitor->VerifyFound();
2521
2522 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2523 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002525 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2527 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002528 pass = (err == VK_SUCCESS);
2529 ASSERT_TRUE(pass);
2530 m_errorMonitor->VerifyFound();
2531
2532 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002533 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002534 pass = (err == VK_SUCCESS);
2535 ASSERT_TRUE(pass);
2536
2537 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002539
2540 // Next, do a 2nd try with surface_format_count being set too high:
2541 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2543 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002544 pass = (err == VK_SUCCESS);
2545 ASSERT_TRUE(pass);
2546 m_errorMonitor->VerifyFound();
2547
2548 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002549 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002550 pass = (err == VK_SUCCESS);
2551 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002553 pass = (err == VK_SUCCESS);
2554 ASSERT_TRUE(pass);
2555
Ian Elliott2c1daf52016-05-12 09:41:46 -06002556 // Create a swapchain:
2557
2558 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2560 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002561
Ian Elliott2c1daf52016-05-12 09:41:46 -06002562 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2563 pass = (err != VK_SUCCESS);
2564 ASSERT_TRUE(pass);
2565 m_errorMonitor->VerifyFound();
2566
2567 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2568 // sType:
2569 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002572 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002573 pass = (err != VK_SUCCESS);
2574 ASSERT_TRUE(pass);
2575 m_errorMonitor->VerifyFound();
2576
2577 // Next, call with a NULL swapchain pointer:
2578 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2579 swapchain_create_info.pNext = NULL;
2580 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2582 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002584 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002585 pass = (err != VK_SUCCESS);
2586 ASSERT_TRUE(pass);
2587 m_errorMonitor->VerifyFound();
2588
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002589 // TODO: Enhance swapchain layer so that
2590 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002591
2592 // Next, call with a queue family index that's too large:
2593 uint32_t queueFamilyIndex[2] = {100000, 0};
2594 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2595 swapchain_create_info.queueFamilyIndexCount = 2;
2596 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002599 pass = (err != VK_SUCCESS);
2600 ASSERT_TRUE(pass);
2601 m_errorMonitor->VerifyFound();
2602
2603 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2604 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2605 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2607 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2608 "pCreateInfo->pQueueFamilyIndices).");
2609 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002610 pass = (err != VK_SUCCESS);
2611 ASSERT_TRUE(pass);
2612 m_errorMonitor->VerifyFound();
2613
2614 // Next, call with an invalid imageSharingMode:
2615 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2616 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2618 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2619 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002620 pass = (err != VK_SUCCESS);
2621 ASSERT_TRUE(pass);
2622 m_errorMonitor->VerifyFound();
2623 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002624 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2625 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002626 swapchain_create_info.queueFamilyIndexCount = 0;
2627 queueFamilyIndex[0] = 0;
2628 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2629
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002630 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002631 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002632 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002633 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002634 // Destroy the swapchain:
2635
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002636 // TODOs:
2637 //
2638 // - Try destroying the device without first destroying the swapchain
2639 //
2640 // - Try destroying the device without first destroying the surface
2641 //
2642 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002643
2644 // Destroy the surface:
2645 vkDestroySurfaceKHR(instance(), surface, NULL);
2646
Ian Elliott2c1daf52016-05-12 09:41:46 -06002647 // Tear down the window:
2648 xcb_destroy_window(connection, xcb_window);
2649 xcb_disconnect(connection);
2650
2651#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002652 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002653#endif // VK_USE_PLATFORM_XCB_KHR
2654}
2655
Karl Schultz6addd812016-02-02 17:17:23 -07002656TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2657 VkResult err;
2658 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002659
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2661 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002662
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002663 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002664
2665 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002666 VkImage image;
2667 VkDeviceMemory mem;
2668 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002669
Karl Schultz6addd812016-02-02 17:17:23 -07002670 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2671 const int32_t tex_width = 32;
2672 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002673
Tony Barboureb254902015-07-15 12:50:33 -06002674 VkImageCreateInfo image_create_info = {};
2675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002676 image_create_info.pNext = NULL;
2677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2678 image_create_info.format = tex_format;
2679 image_create_info.extent.width = tex_width;
2680 image_create_info.extent.height = tex_height;
2681 image_create_info.extent.depth = 1;
2682 image_create_info.mipLevels = 1;
2683 image_create_info.arrayLayers = 1;
2684 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2685 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2686 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2687 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002688 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002689
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002690 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002691 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002692 mem_alloc.pNext = NULL;
2693 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002694
Chia-I Wuf7458c52015-10-26 21:10:41 +08002695 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002696 ASSERT_VK_SUCCESS(err);
2697
Karl Schultz6addd812016-02-02 17:17:23 -07002698 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002699
Mark Lobodzinski23065352015-05-29 09:32:35 -05002700 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002702 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 -07002703 if (!pass) { // If we can't find any unmappable memory this test doesn't
2704 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002705 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002706 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002707 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002708
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002710 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002711 ASSERT_VK_SUCCESS(err);
2712
2713 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002714 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002715 ASSERT_VK_SUCCESS(err);
2716
2717 // Map memory as if to initialize the image
2718 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002719 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002720
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002721 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002722
Chia-I Wuf7458c52015-10-26 21:10:41 +08002723 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002724 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002725}
2726
Karl Schultz6addd812016-02-02 17:17:23 -07002727TEST_F(VkLayerTest, RebindMemory) {
2728 VkResult err;
2729 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002732
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002734
2735 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002736 VkImage image;
2737 VkDeviceMemory mem1;
2738 VkDeviceMemory mem2;
2739 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002740
Karl Schultz6addd812016-02-02 17:17:23 -07002741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2742 const int32_t tex_width = 32;
2743 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002744
Tony Barboureb254902015-07-15 12:50:33 -06002745 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2747 image_create_info.pNext = NULL;
2748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2749 image_create_info.format = tex_format;
2750 image_create_info.extent.width = tex_width;
2751 image_create_info.extent.height = tex_height;
2752 image_create_info.extent.depth = 1;
2753 image_create_info.mipLevels = 1;
2754 image_create_info.arrayLayers = 1;
2755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2756 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2758 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002759
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002760 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 mem_alloc.pNext = NULL;
2763 mem_alloc.allocationSize = 0;
2764 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002765
Karl Schultz6addd812016-02-02 17:17:23 -07002766 // Introduce failure, do NOT set memProps to
2767 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002768 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002769 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002770 ASSERT_VK_SUCCESS(err);
2771
Karl Schultz6addd812016-02-02 17:17:23 -07002772 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002773
2774 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002776 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002777
2778 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002779 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002781 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002782 ASSERT_VK_SUCCESS(err);
2783
2784 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002785 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002786 ASSERT_VK_SUCCESS(err);
2787
Karl Schultz6addd812016-02-02 17:17:23 -07002788 // Introduce validation failure, try to bind a different memory object to
2789 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002790 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002791
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002792 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002793
Chia-I Wuf7458c52015-10-26 21:10:41 +08002794 vkDestroyImage(m_device->device(), image, NULL);
2795 vkFreeMemory(m_device->device(), mem1, NULL);
2796 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002797}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002798
Karl Schultz6addd812016-02-02 17:17:23 -07002799TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002800 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2803 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002804
2805 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002806 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2807 fenceInfo.pNext = NULL;
2808 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002809
Tony Barbour300a6082015-04-07 13:44:53 -06002810 ASSERT_NO_FATAL_FAILURE(InitState());
2811 ASSERT_NO_FATAL_FAILURE(InitViewport());
2812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2813
Tony Barbourfe3351b2015-07-28 10:17:20 -06002814 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002815 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002816 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002817
2818 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002819
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002820 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002821 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2822 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002823 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002824 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002825 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002826 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002828 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002829 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002830
2831 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002832 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002833
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002834 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002835}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002836// This is a positive test. We used to expect error in this case but spec now
2837// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002838TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002839 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002840 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002841 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002842 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2843 fenceInfo.pNext = NULL;
2844
Tony Barbour0b4d9562015-04-09 10:48:04 -06002845 ASSERT_NO_FATAL_FAILURE(InitState());
2846 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002847 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002848 VkResult result = vkResetFences(m_device->device(), 1, fences);
2849 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002850
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002851 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002852}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002853#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002854TEST_F(VkLayerTest, LongFenceChain)
2855{
2856 m_errorMonitor->ExpectSuccess();
2857
2858 ASSERT_NO_FATAL_FAILURE(InitState());
2859 VkResult err;
2860
2861 std::vector<VkFence> fences;
2862
2863 const int chainLength = 32768;
2864
2865 for (int i = 0; i < chainLength; i++) {
2866 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2867 VkFence fence;
2868 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2869 ASSERT_VK_SUCCESS(err);
2870
2871 fences.push_back(fence);
2872
2873 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2874 0, nullptr, 0, nullptr };
2875 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2876 ASSERT_VK_SUCCESS(err);
2877
2878 }
2879
2880 // BOOM, stack overflow.
2881 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2882
2883 for (auto fence : fences)
2884 vkDestroyFence(m_device->device(), fence, nullptr);
2885
2886 m_errorMonitor->VerifyNotFound();
2887}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002888#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002889TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002890 m_errorMonitor->ExpectSuccess();
2891
2892 ASSERT_NO_FATAL_FAILURE(InitState());
2893 VkResult err;
2894
2895 // Record (empty!) command buffer that can be submitted multiple times
2896 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002897 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2898 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002899 m_commandBuffer->BeginCommandBuffer(&cbbi);
2900 m_commandBuffer->EndCommandBuffer();
2901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002902 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002903 VkFence fence;
2904 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2905 ASSERT_VK_SUCCESS(err);
2906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002907 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002908 VkSemaphore s1, s2;
2909 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2910 ASSERT_VK_SUCCESS(err);
2911 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2912 ASSERT_VK_SUCCESS(err);
2913
2914 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002915 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002916 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2917 ASSERT_VK_SUCCESS(err);
2918
2919 // Submit CB again, signaling s2.
2920 si.pSignalSemaphores = &s2;
2921 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2922 ASSERT_VK_SUCCESS(err);
2923
2924 // Wait for fence.
2925 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2926 ASSERT_VK_SUCCESS(err);
2927
2928 // CB is still in flight from second submission, but semaphore s1 is no
2929 // longer in flight. delete it.
2930 vkDestroySemaphore(m_device->device(), s1, nullptr);
2931
2932 m_errorMonitor->VerifyNotFound();
2933
2934 // Force device idle and clean up remaining objects
2935 vkDeviceWaitIdle(m_device->device());
2936 vkDestroySemaphore(m_device->device(), s2, nullptr);
2937 vkDestroyFence(m_device->device(), fence, nullptr);
2938}
2939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002940TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002941 m_errorMonitor->ExpectSuccess();
2942
2943 ASSERT_NO_FATAL_FAILURE(InitState());
2944 VkResult err;
2945
2946 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002947 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002948 VkFence f1;
2949 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2950 ASSERT_VK_SUCCESS(err);
2951
2952 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002953 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002954 VkFence f2;
2955 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2956 ASSERT_VK_SUCCESS(err);
2957
2958 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002959 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002960 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2961
2962 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002963 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002964 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2965
2966 // Should have both retired!
2967 vkDestroyFence(m_device->device(), f1, nullptr);
2968 vkDestroyFence(m_device->device(), f2, nullptr);
2969
2970 m_errorMonitor->VerifyNotFound();
2971}
2972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002973TEST_F(VkLayerTest, InvalidUsageBits) {
2974 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2975 "Initialize buffer with wrong usage then perform copy expecting errors "
2976 "from both the image and the buffer (2 calls)");
2977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002978
2979 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002980 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002981 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002982 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 -06002983 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002984
Tony Barbourf92621a2016-05-02 14:28:12 -06002985 VkImageView dsv;
2986 VkImageViewCreateInfo dsvci = {};
2987 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2988 dsvci.image = image.handle();
2989 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2990 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2991 dsvci.subresourceRange.layerCount = 1;
2992 dsvci.subresourceRange.baseMipLevel = 0;
2993 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002994 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002995
Tony Barbourf92621a2016-05-02 14:28:12 -06002996 // Create a view with depth / stencil aspect for image with different usage
2997 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002998
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002999 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06003000
3001 // Initialize buffer with TRANSFER_DST usage
3002 vk_testing::Buffer buffer;
3003 VkMemoryPropertyFlags reqs = 0;
3004 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3005 VkBufferImageCopy region = {};
3006 region.bufferRowLength = 128;
3007 region.bufferImageHeight = 128;
3008 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3009 region.imageSubresource.layerCount = 1;
3010 region.imageExtent.height = 16;
3011 region.imageExtent.width = 16;
3012 region.imageExtent.depth = 1;
3013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003015 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3016 // TRANSFER_DST
3017 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3019 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003020 m_errorMonitor->VerifyFound();
3021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3023 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3024 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003025 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003026}
Tony Barbour75d79f02016-08-30 09:39:07 -06003027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003028TEST_F(VkLayerTest, ValidUsage) {
3029 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3030 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003031
3032 ASSERT_NO_FATAL_FAILURE(InitState());
3033
3034 m_errorMonitor->ExpectSuccess();
3035 // Verify that we can create a view with usage INPUT_ATTACHMENT
3036 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003037 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour75d79f02016-08-30 09:39:07 -06003038 ASSERT_TRUE(image.initialized());
3039 VkImageView imageView;
3040 VkImageViewCreateInfo ivci = {};
3041 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3042 ivci.image = image.handle();
3043 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3044 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3045 ivci.subresourceRange.layerCount = 1;
3046 ivci.subresourceRange.baseMipLevel = 0;
3047 ivci.subresourceRange.levelCount = 1;
3048 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3049
3050 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3051 m_errorMonitor->VerifyNotFound();
3052 vkDestroyImageView(m_device->device(), imageView, NULL);
3053}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003054#endif // MEM_TRACKER_TESTS
3055
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003056#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003057
3058TEST_F(VkLayerTest, LeakAnObject) {
3059 VkResult err;
3060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003061 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003062
3063 // Note that we have to create a new device since destroying the
3064 // framework's device causes Teardown() to fail and just calling Teardown
3065 // will destroy the errorMonitor.
3066
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003068
3069 ASSERT_NO_FATAL_FAILURE(InitState());
3070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003071 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003072 std::vector<VkDeviceQueueCreateInfo> queue_info;
3073 queue_info.reserve(queue_props.size());
3074 std::vector<std::vector<float>> queue_priorities;
3075 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3076 VkDeviceQueueCreateInfo qi = {};
3077 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3078 qi.pNext = NULL;
3079 qi.queueFamilyIndex = i;
3080 qi.queueCount = queue_props[i].queueCount;
3081 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3082 qi.pQueuePriorities = queue_priorities[i].data();
3083 queue_info.push_back(qi);
3084 }
3085
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003086 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003087
3088 // The sacrificial device object
3089 VkDevice testDevice;
3090 VkDeviceCreateInfo device_create_info = {};
3091 auto features = m_device->phy().features();
3092 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3093 device_create_info.pNext = NULL;
3094 device_create_info.queueCreateInfoCount = queue_info.size();
3095 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003096 device_create_info.enabledLayerCount = 0;
3097 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003098 device_create_info.pEnabledFeatures = &features;
3099 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3100 ASSERT_VK_SUCCESS(err);
3101
3102 VkFence fence;
3103 VkFenceCreateInfo fence_create_info = {};
3104 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3105 fence_create_info.pNext = NULL;
3106 fence_create_info.flags = 0;
3107 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3108 ASSERT_VK_SUCCESS(err);
3109
3110 // Induce failure by not calling vkDestroyFence
3111 vkDestroyDevice(testDevice, NULL);
3112 m_errorMonitor->VerifyFound();
3113}
3114
3115TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3116
3117 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3118 "attempt to delete them from another.");
3119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121
Cody Northropc31a84f2016-08-22 10:41:47 -06003122 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003123 VkCommandPool command_pool_one;
3124 VkCommandPool command_pool_two;
3125
3126 VkCommandPoolCreateInfo pool_create_info{};
3127 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3128 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3129 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003131 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003133 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003134
3135 VkCommandBuffer command_buffer[9];
3136 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003138 command_buffer_allocate_info.commandPool = command_pool_one;
3139 command_buffer_allocate_info.commandBufferCount = 9;
3140 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003141 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003143 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003144
3145 m_errorMonitor->VerifyFound();
3146
3147 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3148 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3149}
3150
3151TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3152 VkResult err;
3153
3154 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003158
3159 ASSERT_NO_FATAL_FAILURE(InitState());
3160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3161
3162 VkDescriptorPoolSize ds_type_count = {};
3163 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3164 ds_type_count.descriptorCount = 1;
3165
3166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3168 ds_pool_ci.pNext = NULL;
3169 ds_pool_ci.flags = 0;
3170 ds_pool_ci.maxSets = 1;
3171 ds_pool_ci.poolSizeCount = 1;
3172 ds_pool_ci.pPoolSizes = &ds_type_count;
3173
3174 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003176 ASSERT_VK_SUCCESS(err);
3177
3178 // Create a second descriptor pool
3179 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003180 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003181 ASSERT_VK_SUCCESS(err);
3182
3183 VkDescriptorSetLayoutBinding dsl_binding = {};
3184 dsl_binding.binding = 0;
3185 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3186 dsl_binding.descriptorCount = 1;
3187 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3188 dsl_binding.pImmutableSamplers = NULL;
3189
3190 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3191 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3192 ds_layout_ci.pNext = NULL;
3193 ds_layout_ci.bindingCount = 1;
3194 ds_layout_ci.pBindings = &dsl_binding;
3195
3196 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003197 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003198 ASSERT_VK_SUCCESS(err);
3199
3200 VkDescriptorSet descriptorSet;
3201 VkDescriptorSetAllocateInfo alloc_info = {};
3202 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3203 alloc_info.descriptorSetCount = 1;
3204 alloc_info.descriptorPool = ds_pool_one;
3205 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003206 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003207 ASSERT_VK_SUCCESS(err);
3208
3209 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3210
3211 m_errorMonitor->VerifyFound();
3212
3213 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3214 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3215 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3216}
3217
3218TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003222
3223 ASSERT_NO_FATAL_FAILURE(InitState());
3224
3225 // Pass bogus handle into GetImageMemoryRequirements
3226 VkMemoryRequirements mem_reqs;
3227 uint64_t fakeImageHandle = 0xCADECADE;
3228 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3229
3230 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3231
3232 m_errorMonitor->VerifyFound();
3233}
3234
Karl Schultz6addd812016-02-02 17:17:23 -07003235TEST_F(VkLayerTest, PipelineNotBound) {
3236 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003238 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003241
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003242 ASSERT_NO_FATAL_FAILURE(InitState());
3243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003245 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003246 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3247 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003248
3249 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003250 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3251 ds_pool_ci.pNext = NULL;
3252 ds_pool_ci.maxSets = 1;
3253 ds_pool_ci.poolSizeCount = 1;
3254 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003258 ASSERT_VK_SUCCESS(err);
3259
3260 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003261 dsl_binding.binding = 0;
3262 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3263 dsl_binding.descriptorCount = 1;
3264 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3265 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003266
3267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3269 ds_layout_ci.pNext = NULL;
3270 ds_layout_ci.bindingCount = 1;
3271 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003272
3273 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003275 ASSERT_VK_SUCCESS(err);
3276
3277 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003278 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003279 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003280 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003281 alloc_info.descriptorPool = ds_pool;
3282 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003284 ASSERT_VK_SUCCESS(err);
3285
3286 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003287 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3288 pipeline_layout_ci.pNext = NULL;
3289 pipeline_layout_ci.setLayoutCount = 1;
3290 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003291
3292 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003294 ASSERT_VK_SUCCESS(err);
3295
Mark Youngad779052016-01-06 14:26:04 -07003296 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003297
3298 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003299 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003300
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003301 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003302
Chia-I Wuf7458c52015-10-26 21:10:41 +08003303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003306}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003307
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003308TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3309 VkResult err;
3310
3311 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3312 "during bind[Buffer|Image]Memory time");
3313
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003314 ASSERT_NO_FATAL_FAILURE(InitState());
3315
3316 // Create an image, allocate memory, set a bad typeIndex and then try to
3317 // bind it
3318 VkImage image;
3319 VkDeviceMemory mem;
3320 VkMemoryRequirements mem_reqs;
3321 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3322 const int32_t tex_width = 32;
3323 const int32_t tex_height = 32;
3324
3325 VkImageCreateInfo image_create_info = {};
3326 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3327 image_create_info.pNext = NULL;
3328 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3329 image_create_info.format = tex_format;
3330 image_create_info.extent.width = tex_width;
3331 image_create_info.extent.height = tex_height;
3332 image_create_info.extent.depth = 1;
3333 image_create_info.mipLevels = 1;
3334 image_create_info.arrayLayers = 1;
3335 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3336 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3337 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3338 image_create_info.flags = 0;
3339
3340 VkMemoryAllocateInfo mem_alloc = {};
3341 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3342 mem_alloc.pNext = NULL;
3343 mem_alloc.allocationSize = 0;
3344 mem_alloc.memoryTypeIndex = 0;
3345
3346 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3347 ASSERT_VK_SUCCESS(err);
3348
3349 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3350 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003351
3352 // Introduce Failure, select invalid TypeIndex
3353 VkPhysicalDeviceMemoryProperties memory_info;
3354
3355 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3356 unsigned int i;
3357 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3358 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3359 mem_alloc.memoryTypeIndex = i;
3360 break;
3361 }
3362 }
3363 if (i >= memory_info.memoryTypeCount) {
3364 printf("No invalid memory type index could be found; skipped.\n");
3365 vkDestroyImage(m_device->device(), image, NULL);
3366 return;
3367 }
3368
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003369 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 -06003370
3371 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3372 ASSERT_VK_SUCCESS(err);
3373
3374 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3375 (void)err;
3376
3377 m_errorMonitor->VerifyFound();
3378
3379 vkDestroyImage(m_device->device(), image, NULL);
3380 vkFreeMemory(m_device->device(), mem, NULL);
3381}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003382
Karl Schultz6addd812016-02-02 17:17:23 -07003383TEST_F(VkLayerTest, BindInvalidMemory) {
3384 VkResult err;
3385 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003388
Tobin Ehlisec598302015-09-15 15:02:17 -06003389 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003390
3391 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003392 VkImage image;
3393 VkDeviceMemory mem;
3394 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003395
Karl Schultz6addd812016-02-02 17:17:23 -07003396 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3397 const int32_t tex_width = 32;
3398 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003399
3400 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003401 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3402 image_create_info.pNext = NULL;
3403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3404 image_create_info.format = tex_format;
3405 image_create_info.extent.width = tex_width;
3406 image_create_info.extent.height = tex_height;
3407 image_create_info.extent.depth = 1;
3408 image_create_info.mipLevels = 1;
3409 image_create_info.arrayLayers = 1;
3410 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3411 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3412 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3413 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003415 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003416 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3417 mem_alloc.pNext = NULL;
3418 mem_alloc.allocationSize = 0;
3419 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003420
Chia-I Wuf7458c52015-10-26 21:10:41 +08003421 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003422 ASSERT_VK_SUCCESS(err);
3423
Karl Schultz6addd812016-02-02 17:17:23 -07003424 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003425
3426 mem_alloc.allocationSize = mem_reqs.size;
3427
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003428 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003429 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003430
3431 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003432 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003433 ASSERT_VK_SUCCESS(err);
3434
3435 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003436 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003437
3438 // Try to bind free memory that has been freed
3439 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3440 // This may very well return an error.
3441 (void)err;
3442
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003443 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003444
Chia-I Wuf7458c52015-10-26 21:10:41 +08003445 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003446}
3447
Karl Schultz6addd812016-02-02 17:17:23 -07003448TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3449 VkResult err;
3450 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003453
Tobin Ehlisec598302015-09-15 15:02:17 -06003454 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003455
Karl Schultz6addd812016-02-02 17:17:23 -07003456 // Create an image object, allocate memory, destroy the object and then try
3457 // to bind it
3458 VkImage image;
3459 VkDeviceMemory mem;
3460 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003461
Karl Schultz6addd812016-02-02 17:17:23 -07003462 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3463 const int32_t tex_width = 32;
3464 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003465
3466 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003467 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3468 image_create_info.pNext = NULL;
3469 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3470 image_create_info.format = tex_format;
3471 image_create_info.extent.width = tex_width;
3472 image_create_info.extent.height = tex_height;
3473 image_create_info.extent.depth = 1;
3474 image_create_info.mipLevels = 1;
3475 image_create_info.arrayLayers = 1;
3476 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3477 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3478 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3479 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003480
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003481 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003482 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3483 mem_alloc.pNext = NULL;
3484 mem_alloc.allocationSize = 0;
3485 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003486
Chia-I Wuf7458c52015-10-26 21:10:41 +08003487 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003488 ASSERT_VK_SUCCESS(err);
3489
Karl Schultz6addd812016-02-02 17:17:23 -07003490 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491
3492 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003494 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003495
3496 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003497 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003498 ASSERT_VK_SUCCESS(err);
3499
3500 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003501 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003502 ASSERT_VK_SUCCESS(err);
3503
3504 // Now Try to bind memory to this destroyed object
3505 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3506 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003507 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003508
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003509 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003510
Chia-I Wuf7458c52015-10-26 21:10:41 +08003511 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003512}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003513
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003514#endif // OBJ_TRACKER_TESTS
3515
Tobin Ehlis0788f522015-05-26 16:11:58 -06003516#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003517
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003518TEST_F(VkLayerTest, ImageSampleCounts) {
3519
3520 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3521 "validation errors.");
3522 ASSERT_NO_FATAL_FAILURE(InitState());
3523
3524 VkMemoryPropertyFlags reqs = 0;
3525 VkImageCreateInfo image_create_info = {};
3526 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3527 image_create_info.pNext = NULL;
3528 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3529 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3530 image_create_info.extent.width = 256;
3531 image_create_info.extent.height = 256;
3532 image_create_info.extent.depth = 1;
3533 image_create_info.mipLevels = 1;
3534 image_create_info.arrayLayers = 1;
3535 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3536 image_create_info.flags = 0;
3537
3538 VkImageBlit blit_region = {};
3539 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3540 blit_region.srcSubresource.baseArrayLayer = 0;
3541 blit_region.srcSubresource.layerCount = 1;
3542 blit_region.srcSubresource.mipLevel = 0;
3543 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3544 blit_region.dstSubresource.baseArrayLayer = 0;
3545 blit_region.dstSubresource.layerCount = 1;
3546 blit_region.dstSubresource.mipLevel = 0;
3547
3548 // Create two images, the source with sampleCount = 2, and attempt to blit
3549 // between them
3550 {
3551 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003552 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003553 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003555 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003557 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003558 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003559 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3561 "of VK_SAMPLE_COUNT_2_BIT but "
3562 "must be VK_SAMPLE_COUNT_1_BIT");
3563 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3564 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003565 m_errorMonitor->VerifyFound();
3566 m_commandBuffer->EndCommandBuffer();
3567 }
3568
3569 // Create two images, the dest with sampleCount = 4, and attempt to blit
3570 // between them
3571 {
3572 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003574 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003576 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003577 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003578 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003579 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003580 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3582 "of VK_SAMPLE_COUNT_4_BIT but "
3583 "must be VK_SAMPLE_COUNT_1_BIT");
3584 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3585 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003586 m_errorMonitor->VerifyFound();
3587 m_commandBuffer->EndCommandBuffer();
3588 }
3589
3590 VkBufferImageCopy copy_region = {};
3591 copy_region.bufferRowLength = 128;
3592 copy_region.bufferImageHeight = 128;
3593 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3594 copy_region.imageSubresource.layerCount = 1;
3595 copy_region.imageExtent.height = 64;
3596 copy_region.imageExtent.width = 64;
3597 copy_region.imageExtent.depth = 1;
3598
3599 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3600 // buffer to image
3601 {
3602 vk_testing::Buffer src_buffer;
3603 VkMemoryPropertyFlags reqs = 0;
3604 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3605 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003607 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003609 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3611 "of VK_SAMPLE_COUNT_8_BIT but "
3612 "must be VK_SAMPLE_COUNT_1_BIT");
3613 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3614 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003615 m_errorMonitor->VerifyFound();
3616 m_commandBuffer->EndCommandBuffer();
3617 }
3618
3619 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3620 // image to buffer
3621 {
3622 vk_testing::Buffer dst_buffer;
3623 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3624 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003626 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003628 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3630 "of VK_SAMPLE_COUNT_2_BIT but "
3631 "must be VK_SAMPLE_COUNT_1_BIT");
3632 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003633 dst_buffer.handle(), 1, &copy_region);
3634 m_errorMonitor->VerifyFound();
3635 m_commandBuffer->EndCommandBuffer();
3636 }
3637}
3638
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003639TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3640 VkResult err;
3641 bool pass;
3642
3643 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3644 ASSERT_NO_FATAL_FAILURE(InitState());
3645
3646 // If w/d/h granularity is 1, test is not meaningful
3647 // TODO: When virtual device limits are available, create a set of limits for this test that
3648 // will always have a granularity of > 1 for w, h, and d
3649 auto index = m_device->graphics_queue_node_index_;
3650 auto queue_family_properties = m_device->phy().queue_properties();
3651
3652 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3653 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3654 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3655 return;
3656 }
3657
3658 // Create two images of different types and try to copy between them
3659 VkImage srcImage;
3660 VkImage dstImage;
3661 VkDeviceMemory srcMem;
3662 VkDeviceMemory destMem;
3663 VkMemoryRequirements memReqs;
3664
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003665 VkImageCreateInfo image_create_info = {};
3666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3667 image_create_info.pNext = NULL;
3668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3669 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3670 image_create_info.extent.width = 32;
3671 image_create_info.extent.height = 32;
3672 image_create_info.extent.depth = 1;
3673 image_create_info.mipLevels = 1;
3674 image_create_info.arrayLayers = 4;
3675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3676 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3677 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3678 image_create_info.flags = 0;
3679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003681 ASSERT_VK_SUCCESS(err);
3682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003683 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003684 ASSERT_VK_SUCCESS(err);
3685
3686 // Allocate memory
3687 VkMemoryAllocateInfo memAlloc = {};
3688 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3689 memAlloc.pNext = NULL;
3690 memAlloc.allocationSize = 0;
3691 memAlloc.memoryTypeIndex = 0;
3692
3693 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3694 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003695 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003696 ASSERT_TRUE(pass);
3697 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3698 ASSERT_VK_SUCCESS(err);
3699
3700 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3701 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003703 ASSERT_VK_SUCCESS(err);
3704 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3705 ASSERT_VK_SUCCESS(err);
3706
3707 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3708 ASSERT_VK_SUCCESS(err);
3709 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3710 ASSERT_VK_SUCCESS(err);
3711
3712 BeginCommandBuffer();
3713 VkImageCopy copyRegion;
3714 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3715 copyRegion.srcSubresource.mipLevel = 0;
3716 copyRegion.srcSubresource.baseArrayLayer = 0;
3717 copyRegion.srcSubresource.layerCount = 1;
3718 copyRegion.srcOffset.x = 0;
3719 copyRegion.srcOffset.y = 0;
3720 copyRegion.srcOffset.z = 0;
3721 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3722 copyRegion.dstSubresource.mipLevel = 0;
3723 copyRegion.dstSubresource.baseArrayLayer = 0;
3724 copyRegion.dstSubresource.layerCount = 1;
3725 copyRegion.dstOffset.x = 0;
3726 copyRegion.dstOffset.y = 0;
3727 copyRegion.dstOffset.z = 0;
3728 copyRegion.extent.width = 1;
3729 copyRegion.extent.height = 1;
3730 copyRegion.extent.depth = 1;
3731
3732 // Introduce failure by setting srcOffset to a bad granularity value
3733 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3735 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003736 m_errorMonitor->VerifyFound();
3737
3738 // Introduce failure by setting extent to a bad granularity value
3739 copyRegion.srcOffset.y = 0;
3740 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3742 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003743 m_errorMonitor->VerifyFound();
3744
3745 // Now do some buffer/image copies
3746 vk_testing::Buffer buffer;
3747 VkMemoryPropertyFlags reqs = 0;
3748 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3749 VkBufferImageCopy region = {};
3750 region.bufferOffset = 0;
3751 region.bufferRowLength = 3;
3752 region.bufferImageHeight = 128;
3753 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3754 region.imageSubresource.layerCount = 1;
3755 region.imageExtent.height = 16;
3756 region.imageExtent.width = 16;
3757 region.imageExtent.depth = 1;
3758 region.imageOffset.x = 0;
3759 region.imageOffset.y = 0;
3760 region.imageOffset.z = 0;
3761
3762 // Introduce failure by setting bufferRowLength to a bad granularity value
3763 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3765 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3766 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003767 m_errorMonitor->VerifyFound();
3768 region.bufferRowLength = 128;
3769
3770 // Introduce failure by setting bufferOffset to a bad granularity value
3771 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3773 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3774 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003775 m_errorMonitor->VerifyFound();
3776 region.bufferOffset = 0;
3777
3778 // Introduce failure by setting bufferImageHeight to a bad granularity value
3779 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3781 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3782 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003783 m_errorMonitor->VerifyFound();
3784 region.bufferImageHeight = 128;
3785
3786 // Introduce failure by setting imageExtent to a bad granularity value
3787 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3789 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3790 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003791 m_errorMonitor->VerifyFound();
3792 region.imageExtent.width = 16;
3793
3794 // Introduce failure by setting imageOffset to a bad granularity value
3795 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3797 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3798 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003799 m_errorMonitor->VerifyFound();
3800
3801 EndCommandBuffer();
3802
3803 vkDestroyImage(m_device->device(), srcImage, NULL);
3804 vkDestroyImage(m_device->device(), dstImage, NULL);
3805 vkFreeMemory(m_device->device(), srcMem, NULL);
3806 vkFreeMemory(m_device->device(), destMem, NULL);
3807}
3808
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003809TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003810 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3811 "attempt to submit them on a queue created in a different "
3812 "queue family.");
3813
Cody Northropc31a84f2016-08-22 10:41:47 -06003814 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003815 // This test is meaningless unless we have multiple queue families
3816 auto queue_family_properties = m_device->phy().queue_properties();
3817 if (queue_family_properties.size() < 2) {
3818 return;
3819 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003821 // Get safe index of another queue family
3822 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3823 ASSERT_NO_FATAL_FAILURE(InitState());
3824 // Create a second queue using a different queue family
3825 VkQueue other_queue;
3826 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3827
3828 // Record an empty cmd buffer
3829 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3830 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3831 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3832 vkEndCommandBuffer(m_commandBuffer->handle());
3833
3834 // And submit on the wrong queue
3835 VkSubmitInfo submit_info = {};
3836 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3837 submit_info.commandBufferCount = 1;
3838 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003839 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003840
3841 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003842}
3843
Chris Forbes48a53902016-06-30 11:46:27 +12003844TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3845 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3846 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3847 "the command buffer has prior knowledge of that "
3848 "attachment's layout.");
3849
3850 m_errorMonitor->ExpectSuccess();
3851
3852 ASSERT_NO_FATAL_FAILURE(InitState());
3853
3854 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003855 VkAttachmentDescription attachment = {0,
3856 VK_FORMAT_R8G8B8A8_UNORM,
3857 VK_SAMPLE_COUNT_1_BIT,
3858 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3859 VK_ATTACHMENT_STORE_OP_STORE,
3860 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3861 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3862 VK_IMAGE_LAYOUT_UNDEFINED,
3863 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003865 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003867 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003869 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003870
3871 VkRenderPass rp;
3872 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3873 ASSERT_VK_SUCCESS(err);
3874
3875 // A compatible framebuffer.
3876 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003877 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes48a53902016-06-30 11:46:27 +12003878 ASSERT_TRUE(image.initialized());
3879
3880 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003881 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3882 nullptr,
3883 0,
3884 image.handle(),
3885 VK_IMAGE_VIEW_TYPE_2D,
3886 VK_FORMAT_R8G8B8A8_UNORM,
3887 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3888 VK_COMPONENT_SWIZZLE_IDENTITY},
3889 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003890 };
3891 VkImageView view;
3892 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3893 ASSERT_VK_SUCCESS(err);
3894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003895 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003896 VkFramebuffer fb;
3897 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3898 ASSERT_VK_SUCCESS(err);
3899
3900 // Record a single command buffer which uses this renderpass twice. The
3901 // bug is triggered at the beginning of the second renderpass, when the
3902 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003903 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003904 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003905 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003906 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003907 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003908
3909 m_errorMonitor->VerifyNotFound();
3910
3911 vkCmdEndRenderPass(m_commandBuffer->handle());
3912 EndCommandBuffer();
3913
3914 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3915 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3916 vkDestroyImageView(m_device->device(), view, nullptr);
3917}
3918
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003919TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3920 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3921 "command buffer, bind them together, then destroy "
3922 "command pool and framebuffer and verify there are no "
3923 "errors.");
3924
3925 m_errorMonitor->ExpectSuccess();
3926
3927 ASSERT_NO_FATAL_FAILURE(InitState());
3928
3929 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003930 VkAttachmentDescription attachment = {0,
3931 VK_FORMAT_R8G8B8A8_UNORM,
3932 VK_SAMPLE_COUNT_1_BIT,
3933 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3934 VK_ATTACHMENT_STORE_OP_STORE,
3935 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3936 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3937 VK_IMAGE_LAYOUT_UNDEFINED,
3938 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003940 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003942 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003944 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003945
3946 VkRenderPass rp;
3947 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3948 ASSERT_VK_SUCCESS(err);
3949
3950 // A compatible framebuffer.
3951 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003952 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003953 ASSERT_TRUE(image.initialized());
3954
3955 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003956 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3957 nullptr,
3958 0,
3959 image.handle(),
3960 VK_IMAGE_VIEW_TYPE_2D,
3961 VK_FORMAT_R8G8B8A8_UNORM,
3962 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3963 VK_COMPONENT_SWIZZLE_IDENTITY},
3964 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003965 };
3966 VkImageView view;
3967 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3968 ASSERT_VK_SUCCESS(err);
3969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003970 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003971 VkFramebuffer fb;
3972 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3973 ASSERT_VK_SUCCESS(err);
3974
3975 // Explicitly create a command buffer to bind the FB to so that we can then
3976 // destroy the command pool in order to implicitly free command buffer
3977 VkCommandPool command_pool;
3978 VkCommandPoolCreateInfo pool_create_info{};
3979 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3980 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3981 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003983
3984 VkCommandBuffer command_buffer;
3985 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003986 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003987 command_buffer_allocate_info.commandPool = command_pool;
3988 command_buffer_allocate_info.commandBufferCount = 1;
3989 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003990 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003991
3992 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003993 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003994 VkCommandBufferBeginInfo begin_info{};
3995 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3996 vkBeginCommandBuffer(command_buffer, &begin_info);
3997
3998 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3999 vkCmdEndRenderPass(command_buffer);
4000 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06004001 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06004002 // Destroy command pool to implicitly free command buffer
4003 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4004 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4005 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4006 m_errorMonitor->VerifyNotFound();
4007}
4008
Chris Forbes51bf7c92016-06-30 15:22:08 +12004009TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
4010 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4011 "transitions for the first subpass");
4012
4013 m_errorMonitor->ExpectSuccess();
4014
4015 ASSERT_NO_FATAL_FAILURE(InitState());
4016
4017 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004018 VkAttachmentDescription attachment = {0,
4019 VK_FORMAT_R8G8B8A8_UNORM,
4020 VK_SAMPLE_COUNT_1_BIT,
4021 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4022 VK_ATTACHMENT_STORE_OP_STORE,
4023 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4024 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4025 VK_IMAGE_LAYOUT_UNDEFINED,
4026 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004028 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004030 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004032 VkSubpassDependency dep = {0,
4033 0,
4034 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4035 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4036 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4037 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4038 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004040 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004041
4042 VkResult err;
4043 VkRenderPass rp;
4044 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4045 ASSERT_VK_SUCCESS(err);
4046
4047 // A compatible framebuffer.
4048 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004049 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004050 ASSERT_TRUE(image.initialized());
4051
4052 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004053 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4054 nullptr,
4055 0,
4056 image.handle(),
4057 VK_IMAGE_VIEW_TYPE_2D,
4058 VK_FORMAT_R8G8B8A8_UNORM,
4059 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4060 VK_COMPONENT_SWIZZLE_IDENTITY},
4061 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004062 };
4063 VkImageView view;
4064 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4065 ASSERT_VK_SUCCESS(err);
4066
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004067 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004068 VkFramebuffer fb;
4069 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4070 ASSERT_VK_SUCCESS(err);
4071
4072 // Record a single command buffer which issues a pipeline barrier w/
4073 // image memory barrier for the attachment. This detects the previously
4074 // missing tracking of the subpass layout by throwing a validation error
4075 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004076 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004077 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004078 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004080 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4081 nullptr,
4082 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4083 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4084 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4085 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4086 VK_QUEUE_FAMILY_IGNORED,
4087 VK_QUEUE_FAMILY_IGNORED,
4088 image.handle(),
4089 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4090 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4091 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4092 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004093
4094 vkCmdEndRenderPass(m_commandBuffer->handle());
4095 m_errorMonitor->VerifyNotFound();
4096 EndCommandBuffer();
4097
4098 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4099 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4100 vkDestroyImageView(m_device->device(), view, nullptr);
4101}
4102
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004103TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4104 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4105 "is used as a depth/stencil framebuffer attachment, the "
4106 "aspectMask is ignored and both depth and stencil image "
4107 "subresources are used.");
4108
4109 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004110 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4111 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004112 return;
4113 }
4114
4115 m_errorMonitor->ExpectSuccess();
4116
4117 ASSERT_NO_FATAL_FAILURE(InitState());
4118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004119 VkAttachmentDescription attachment = {0,
4120 VK_FORMAT_D32_SFLOAT_S8_UINT,
4121 VK_SAMPLE_COUNT_1_BIT,
4122 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4123 VK_ATTACHMENT_STORE_OP_STORE,
4124 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4125 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4126 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4127 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004129 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004131 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004132
4133 VkSubpassDependency dep = {0,
4134 0,
4135 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4136 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4137 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4138 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4139 VK_DEPENDENCY_BY_REGION_BIT};
4140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004141 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004142
4143 VkResult err;
4144 VkRenderPass rp;
4145 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4146 ASSERT_VK_SUCCESS(err);
4147
4148 VkImageObj image(m_device);
4149 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4150 0x26, // usage
4151 VK_IMAGE_TILING_OPTIMAL, 0);
4152 ASSERT_TRUE(image.initialized());
4153 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4154
4155 VkImageViewCreateInfo ivci = {
4156 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4157 nullptr,
4158 0,
4159 image.handle(),
4160 VK_IMAGE_VIEW_TYPE_2D,
4161 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004163 {0x2, 0, 1, 0, 1},
4164 };
4165 VkImageView view;
4166 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4167 ASSERT_VK_SUCCESS(err);
4168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004169 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004170 VkFramebuffer fb;
4171 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4172 ASSERT_VK_SUCCESS(err);
4173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004174 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004175 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004176 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004177
4178 VkImageMemoryBarrier imb = {};
4179 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4180 imb.pNext = nullptr;
4181 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4182 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4183 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4184 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4185 imb.srcQueueFamilyIndex = 0;
4186 imb.dstQueueFamilyIndex = 0;
4187 imb.image = image.handle();
4188 imb.subresourceRange.aspectMask = 0x6;
4189 imb.subresourceRange.baseMipLevel = 0;
4190 imb.subresourceRange.levelCount = 0x1;
4191 imb.subresourceRange.baseArrayLayer = 0;
4192 imb.subresourceRange.layerCount = 0x1;
4193
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004194 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4195 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004196 &imb);
4197
4198 vkCmdEndRenderPass(m_commandBuffer->handle());
4199 EndCommandBuffer();
4200 QueueCommandBuffer(false);
4201 m_errorMonitor->VerifyNotFound();
4202
4203 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4204 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4205 vkDestroyImageView(m_device->device(), view, nullptr);
4206}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004207
Tony Barbour4e919972016-08-09 13:27:40 -06004208TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4209 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4210 "with extent outside of framebuffer");
4211 ASSERT_NO_FATAL_FAILURE(InitState());
4212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4215 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004216
4217 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4218 m_renderPassBeginInfo.renderArea.extent.width = 257;
4219 m_renderPassBeginInfo.renderArea.extent.height = 257;
4220 BeginCommandBuffer();
4221 m_errorMonitor->VerifyFound();
4222}
4223
4224TEST_F(VkLayerTest, DisabledIndependentBlend) {
4225 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4226 "blend and then specifying different blend states for two "
4227 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004228 VkPhysicalDeviceFeatures features = {};
4229 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004230 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004231
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4233 "Invalid Pipeline CreateInfo: If independent blend feature not "
4234 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004235
Cody Northropc31a84f2016-08-22 10:41:47 -06004236 VkDescriptorSetObj descriptorSet(m_device);
4237 descriptorSet.AppendDummy();
4238 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004239
Cody Northropc31a84f2016-08-22 10:41:47 -06004240 VkPipelineObj pipeline(m_device);
4241 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004243 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004244
Cody Northropc31a84f2016-08-22 10:41:47 -06004245 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4246 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4247 att_state1.blendEnable = VK_TRUE;
4248 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4249 att_state2.blendEnable = VK_FALSE;
4250 pipeline.AddColorAttachment(0, &att_state1);
4251 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004253 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004254}
4255
4256TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4257 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4258 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004259 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4262 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004263
4264 // Create a renderPass with a single color attachment
4265 VkAttachmentReference attach = {};
4266 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4267 VkSubpassDescription subpass = {};
4268 VkRenderPassCreateInfo rpci = {};
4269 rpci.subpassCount = 1;
4270 rpci.pSubpasses = &subpass;
4271 rpci.attachmentCount = 1;
4272 VkAttachmentDescription attach_desc = {};
4273 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4274 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4275 rpci.pAttachments = &attach_desc;
4276 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4277 VkRenderPass rp;
4278 subpass.pDepthStencilAttachment = &attach;
4279 subpass.pColorAttachments = NULL;
4280 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4281 m_errorMonitor->VerifyFound();
4282}
4283
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004284TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4285 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4286 "errors, when an attachment reference is "
4287 "VK_ATTACHMENT_UNUSED");
4288
4289 m_errorMonitor->ExpectSuccess();
4290
4291 ASSERT_NO_FATAL_FAILURE(InitState());
4292
4293 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004296 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004299
4300 VkRenderPass rp;
4301 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4302 ASSERT_VK_SUCCESS(err);
4303
4304 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004306 VkFramebuffer fb;
4307 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4308 ASSERT_VK_SUCCESS(err);
4309
4310 // Record a command buffer which just begins and ends the renderpass. The
4311 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004313 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004314 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004315 vkCmdEndRenderPass(m_commandBuffer->handle());
4316 m_errorMonitor->VerifyNotFound();
4317 EndCommandBuffer();
4318
4319 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4320 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4321}
4322
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004323// This is a positive test. No errors are expected.
4324TEST_F(VkLayerTest, StencilLoadOp) {
4325 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4326 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4327 VkResult result = VK_SUCCESS;
4328 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4330 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4331 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004332 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4333 return;
4334 }
4335
4336 ASSERT_NO_FATAL_FAILURE(InitState());
4337 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4338 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004339 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004340 VkAttachmentDescription att = {};
4341 VkAttachmentReference ref = {};
4342 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004343 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004344 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4345 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4346 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4347 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4348 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4349 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4350
4351 VkClearValue clear;
4352 clear.depthStencil.depth = 1.0;
4353 clear.depthStencil.stencil = 0;
4354 ref.attachment = 0;
4355 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4356
4357 VkSubpassDescription subpass = {};
4358 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4359 subpass.flags = 0;
4360 subpass.inputAttachmentCount = 0;
4361 subpass.pInputAttachments = NULL;
4362 subpass.colorAttachmentCount = 0;
4363 subpass.pColorAttachments = NULL;
4364 subpass.pResolveAttachments = NULL;
4365 subpass.pDepthStencilAttachment = &ref;
4366 subpass.preserveAttachmentCount = 0;
4367 subpass.pPreserveAttachments = NULL;
4368
4369 VkRenderPass rp;
4370 VkRenderPassCreateInfo rp_info = {};
4371 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4372 rp_info.attachmentCount = 1;
4373 rp_info.pAttachments = &att;
4374 rp_info.subpassCount = 1;
4375 rp_info.pSubpasses = &subpass;
4376 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4377 ASSERT_VK_SUCCESS(result);
4378
4379 VkImageView *depthView = m_depthStencil->BindInfo();
4380 VkFramebufferCreateInfo fb_info = {};
4381 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4382 fb_info.pNext = NULL;
4383 fb_info.renderPass = rp;
4384 fb_info.attachmentCount = 1;
4385 fb_info.pAttachments = depthView;
4386 fb_info.width = 100;
4387 fb_info.height = 100;
4388 fb_info.layers = 1;
4389 VkFramebuffer fb;
4390 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4391 ASSERT_VK_SUCCESS(result);
4392
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004393 VkRenderPassBeginInfo rpbinfo = {};
4394 rpbinfo.clearValueCount = 1;
4395 rpbinfo.pClearValues = &clear;
4396 rpbinfo.pNext = NULL;
4397 rpbinfo.renderPass = rp;
4398 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4399 rpbinfo.renderArea.extent.width = 100;
4400 rpbinfo.renderArea.extent.height = 100;
4401 rpbinfo.renderArea.offset.x = 0;
4402 rpbinfo.renderArea.offset.y = 0;
4403 rpbinfo.framebuffer = fb;
4404
4405 VkFence fence = {};
4406 VkFenceCreateInfo fence_ci = {};
4407 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4408 fence_ci.pNext = nullptr;
4409 fence_ci.flags = 0;
4410 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4411 ASSERT_VK_SUCCESS(result);
4412
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004413 m_commandBuffer->BeginCommandBuffer();
4414 m_commandBuffer->BeginRenderPass(rpbinfo);
4415 m_commandBuffer->EndRenderPass();
4416 m_commandBuffer->EndCommandBuffer();
4417 m_commandBuffer->QueueCommandBuffer(fence);
4418
4419 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004421 VK_IMAGE_TILING_OPTIMAL, 0);
4422 VkImageMemoryBarrier barrier = {};
4423 VkImageSubresourceRange range;
4424 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004425 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4426 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004427 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4428 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4429 barrier.image = m_depthStencil->handle();
4430 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4431 range.baseMipLevel = 0;
4432 range.levelCount = 1;
4433 range.baseArrayLayer = 0;
4434 range.layerCount = 1;
4435 barrier.subresourceRange = range;
4436 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4437 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4438 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004439 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4440 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004441 barrier.srcAccessMask = 0;
4442 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4443 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4444 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4446 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4447 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004448 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004449 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004450 cregion.srcSubresource.mipLevel = 0;
4451 cregion.srcSubresource.baseArrayLayer = 0;
4452 cregion.srcSubresource.layerCount = 1;
4453 cregion.srcOffset.x = 0;
4454 cregion.srcOffset.y = 0;
4455 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004456 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004457 cregion.dstSubresource.mipLevel = 0;
4458 cregion.dstSubresource.baseArrayLayer = 0;
4459 cregion.dstSubresource.layerCount = 1;
4460 cregion.dstOffset.x = 0;
4461 cregion.dstOffset.y = 0;
4462 cregion.dstOffset.z = 0;
4463 cregion.extent.width = 100;
4464 cregion.extent.height = 100;
4465 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004466 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004467 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4468 cmdbuf.EndCommandBuffer();
4469
4470 VkSubmitInfo submit_info;
4471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4472 submit_info.pNext = NULL;
4473 submit_info.waitSemaphoreCount = 0;
4474 submit_info.pWaitSemaphores = NULL;
4475 submit_info.pWaitDstStageMask = NULL;
4476 submit_info.commandBufferCount = 1;
4477 submit_info.pCommandBuffers = &cmdbuf.handle();
4478 submit_info.signalSemaphoreCount = 0;
4479 submit_info.pSignalSemaphores = NULL;
4480
4481 m_errorMonitor->ExpectSuccess();
4482 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4483 m_errorMonitor->VerifyNotFound();
4484
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004485 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004486 vkDestroyFence(m_device->device(), fence, nullptr);
4487 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4488 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4489}
4490
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004491TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4492 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4493 "attachment reference of VK_ATTACHMENT_UNUSED");
4494
4495 ASSERT_NO_FATAL_FAILURE(InitState());
4496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004499
4500 VkAttachmentReference color_attach = {};
4501 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4502 color_attach.attachment = 0;
4503 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4504 VkSubpassDescription subpass = {};
4505 subpass.colorAttachmentCount = 1;
4506 subpass.pColorAttachments = &color_attach;
4507 subpass.preserveAttachmentCount = 1;
4508 subpass.pPreserveAttachments = &preserve_attachment;
4509
4510 VkRenderPassCreateInfo rpci = {};
4511 rpci.subpassCount = 1;
4512 rpci.pSubpasses = &subpass;
4513 rpci.attachmentCount = 1;
4514 VkAttachmentDescription attach_desc = {};
4515 attach_desc.format = VK_FORMAT_UNDEFINED;
4516 rpci.pAttachments = &attach_desc;
4517 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4518 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004519 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004520
4521 m_errorMonitor->VerifyFound();
4522
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004523 if (result == VK_SUCCESS) {
4524 vkDestroyRenderPass(m_device->device(), rp, NULL);
4525 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004526}
4527
Chris Forbesc5389742016-06-29 11:49:23 +12004528TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004529 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4530 "when the source of a subpass multisample resolve "
4531 "does not have multiple samples.");
4532
Chris Forbesc5389742016-06-29 11:49:23 +12004533 ASSERT_NO_FATAL_FAILURE(InitState());
4534
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4536 "Subpass 0 requests multisample resolve from attachment 0 which has "
4537 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004538
4539 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004540 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4541 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4542 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4543 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4544 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4545 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004546 };
4547
4548 VkAttachmentReference color = {
4549 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4550 };
4551
4552 VkAttachmentReference resolve = {
4553 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4554 };
4555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004556 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004557
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004558 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004559
4560 VkRenderPass rp;
4561 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4562
4563 m_errorMonitor->VerifyFound();
4564
4565 if (err == VK_SUCCESS)
4566 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4567}
4568
4569TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004570 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4571 "when a subpass multisample resolve operation is "
4572 "requested, and the destination of that resolve has "
4573 "multiple samples.");
4574
Chris Forbesc5389742016-06-29 11:49:23 +12004575 ASSERT_NO_FATAL_FAILURE(InitState());
4576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4578 "Subpass 0 requests multisample resolve into attachment 1, which "
4579 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004580
4581 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004582 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4583 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4584 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4585 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4586 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4587 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004588 };
4589
4590 VkAttachmentReference color = {
4591 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4592 };
4593
4594 VkAttachmentReference resolve = {
4595 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4596 };
4597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004598 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004600 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004601
4602 VkRenderPass rp;
4603 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4604
4605 m_errorMonitor->VerifyFound();
4606
4607 if (err == VK_SUCCESS)
4608 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4609}
4610
Chris Forbes3f128ef2016-06-29 14:58:53 +12004611TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004612 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4613 "when the color and depth attachments used by a subpass "
4614 "have inconsistent sample counts");
4615
Chris Forbes3f128ef2016-06-29 14:58:53 +12004616 ASSERT_NO_FATAL_FAILURE(InitState());
4617
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4619 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004620
4621 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004622 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4623 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4624 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4625 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4626 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4627 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004628 };
4629
4630 VkAttachmentReference color[] = {
4631 {
4632 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4633 },
4634 {
4635 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4636 },
4637 };
4638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004641 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004642
4643 VkRenderPass rp;
4644 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4645
4646 m_errorMonitor->VerifyFound();
4647
4648 if (err == VK_SUCCESS)
4649 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4650}
4651
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004652TEST_F(VkLayerTest, FramebufferCreateErrors) {
4653 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4654 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004655 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004656 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004657 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004658 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004659 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004660 " 7. FB attachment w/o identity swizzle\n"
4661 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004662
4663 ASSERT_NO_FATAL_FAILURE(InitState());
4664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4665
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4667 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4668 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004669
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004670 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004671 VkAttachmentReference attach = {};
4672 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4673 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004674 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004675 VkRenderPassCreateInfo rpci = {};
4676 rpci.subpassCount = 1;
4677 rpci.pSubpasses = &subpass;
4678 rpci.attachmentCount = 1;
4679 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004680 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004681 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004682 rpci.pAttachments = &attach_desc;
4683 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4684 VkRenderPass rp;
4685 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4686 ASSERT_VK_SUCCESS(err);
4687
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004688 VkImageView ivs[2];
4689 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4690 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004691 VkFramebufferCreateInfo fb_info = {};
4692 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4693 fb_info.pNext = NULL;
4694 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004695 // Set mis-matching attachmentCount
4696 fb_info.attachmentCount = 2;
4697 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004698 fb_info.width = 100;
4699 fb_info.height = 100;
4700 fb_info.layers = 1;
4701
4702 VkFramebuffer fb;
4703 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4704
4705 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004706 if (err == VK_SUCCESS) {
4707 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4708 }
4709 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004710
4711 // Create a renderPass with a depth-stencil attachment created with
4712 // IMAGE_USAGE_COLOR_ATTACHMENT
4713 // Add our color attachment to pDepthStencilAttachment
4714 subpass.pDepthStencilAttachment = &attach;
4715 subpass.pColorAttachments = NULL;
4716 VkRenderPass rp_ds;
4717 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4718 ASSERT_VK_SUCCESS(err);
4719 // Set correct attachment count, but attachment has COLOR usage bit set
4720 fb_info.attachmentCount = 1;
4721 fb_info.renderPass = rp_ds;
4722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004724 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4725
4726 m_errorMonitor->VerifyFound();
4727 if (err == VK_SUCCESS) {
4728 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4729 }
4730 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004731
4732 // Create new renderpass with alternate attachment format from fb
4733 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4734 subpass.pDepthStencilAttachment = NULL;
4735 subpass.pColorAttachments = &attach;
4736 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4737 ASSERT_VK_SUCCESS(err);
4738
4739 // Cause error due to mis-matched formats between rp & fb
4740 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4741 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4743 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004744 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4745
4746 m_errorMonitor->VerifyFound();
4747 if (err == VK_SUCCESS) {
4748 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4749 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004750 vkDestroyRenderPass(m_device->device(), rp, NULL);
4751
4752 // Create new renderpass with alternate sample count from fb
4753 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4754 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4755 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4756 ASSERT_VK_SUCCESS(err);
4757
4758 // Cause error due to mis-matched sample count between rp & fb
4759 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4761 "that do not match the "
4762 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004763 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4764
4765 m_errorMonitor->VerifyFound();
4766 if (err == VK_SUCCESS) {
4767 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4768 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004769
4770 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004771
4772 // Create a custom imageView with non-1 mip levels
4773 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004774 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 -06004775 ASSERT_TRUE(image.initialized());
4776
4777 VkImageView view;
4778 VkImageViewCreateInfo ivci = {};
4779 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4780 ivci.image = image.handle();
4781 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4782 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4783 ivci.subresourceRange.layerCount = 1;
4784 ivci.subresourceRange.baseMipLevel = 0;
4785 // Set level count 2 (only 1 is allowed for FB attachment)
4786 ivci.subresourceRange.levelCount = 2;
4787 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4788 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4789 ASSERT_VK_SUCCESS(err);
4790 // Re-create renderpass to have matching sample count
4791 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4792 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4793 ASSERT_VK_SUCCESS(err);
4794
4795 fb_info.renderPass = rp;
4796 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004798 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4799
4800 m_errorMonitor->VerifyFound();
4801 if (err == VK_SUCCESS) {
4802 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4803 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004804 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004805 // Update view to original color buffer and grow FB dimensions too big
4806 fb_info.pAttachments = ivs;
4807 fb_info.height = 1024;
4808 fb_info.width = 1024;
4809 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4811 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004812 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4813
4814 m_errorMonitor->VerifyFound();
4815 if (err == VK_SUCCESS) {
4816 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4817 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004818 // Create view attachment with non-identity swizzle
4819 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4820 ivci.image = image.handle();
4821 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4822 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4823 ivci.subresourceRange.layerCount = 1;
4824 ivci.subresourceRange.baseMipLevel = 0;
4825 ivci.subresourceRange.levelCount = 1;
4826 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4827 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4828 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4829 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4830 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4831 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4832 ASSERT_VK_SUCCESS(err);
4833
4834 fb_info.pAttachments = &view;
4835 fb_info.height = 100;
4836 fb_info.width = 100;
4837 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4839 "framebuffer attachments must have "
4840 "been created with the identity "
4841 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004842 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4843
4844 m_errorMonitor->VerifyFound();
4845 if (err == VK_SUCCESS) {
4846 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4847 }
4848 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004849 // Request fb that exceeds max dimensions
4850 // reset attachment to color attachment
4851 fb_info.pAttachments = ivs;
4852 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4853 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4854 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4856 "dimensions exceed physical device "
4857 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004858 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4859
4860 m_errorMonitor->VerifyFound();
4861 if (err == VK_SUCCESS) {
4862 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4863 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004864
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004865 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004866}
4867
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004868// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004869TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004870 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004871
Michael Lentine860b0fe2016-05-20 10:14:00 -05004872 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004873 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004874
4875 VkEvent event;
4876 VkEventCreateInfo event_create_info{};
4877 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4878 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4879
4880 VkCommandPool command_pool;
4881 VkCommandPoolCreateInfo pool_create_info{};
4882 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4883 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4884 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004886
4887 VkCommandBuffer command_buffer;
4888 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004890 command_buffer_allocate_info.commandPool = command_pool;
4891 command_buffer_allocate_info.commandBufferCount = 1;
4892 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004894
4895 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004897
4898 {
4899 VkCommandBufferBeginInfo begin_info{};
4900 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4901 vkBeginCommandBuffer(command_buffer, &begin_info);
4902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004903 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
Michael Lentine860b0fe2016-05-20 10:14:00 -05004904 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004905 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004906 vkEndCommandBuffer(command_buffer);
4907 }
4908 {
4909 VkSubmitInfo submit_info{};
4910 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4911 submit_info.commandBufferCount = 1;
4912 submit_info.pCommandBuffers = &command_buffer;
4913 submit_info.signalSemaphoreCount = 0;
4914 submit_info.pSignalSemaphores = nullptr;
4915 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4916 }
4917 { vkSetEvent(m_device->device(), event); }
4918
4919 vkQueueWaitIdle(queue);
4920
4921 vkDestroyEvent(m_device->device(), event, nullptr);
4922 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4923 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4924
4925 m_errorMonitor->VerifyNotFound();
4926}
Michael Lentine5627e692016-05-20 17:45:02 -05004927// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004928TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004929 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004930
Cody Northropc31a84f2016-08-22 10:41:47 -06004931 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004932 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004933 return;
4934
4935 m_errorMonitor->ExpectSuccess();
4936
4937 VkQueryPool query_pool;
4938 VkQueryPoolCreateInfo query_pool_create_info{};
4939 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4940 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4941 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004943
4944 VkCommandPool command_pool;
4945 VkCommandPoolCreateInfo pool_create_info{};
4946 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4947 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4948 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004950
4951 VkCommandBuffer command_buffer;
4952 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004954 command_buffer_allocate_info.commandPool = command_pool;
4955 command_buffer_allocate_info.commandBufferCount = 1;
4956 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004957 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004958
4959 VkCommandBuffer secondary_command_buffer;
4960 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004962
4963 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004965
4966 uint32_t qfi = 0;
4967 VkBufferCreateInfo buff_create_info = {};
4968 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4969 buff_create_info.size = 1024;
4970 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4971 buff_create_info.queueFamilyIndexCount = 1;
4972 buff_create_info.pQueueFamilyIndices = &qfi;
4973
4974 VkResult err;
4975 VkBuffer buffer;
4976 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4977 ASSERT_VK_SUCCESS(err);
4978 VkMemoryAllocateInfo mem_alloc = {};
4979 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4980 mem_alloc.pNext = NULL;
4981 mem_alloc.allocationSize = 1024;
4982 mem_alloc.memoryTypeIndex = 0;
4983
4984 VkMemoryRequirements memReqs;
4985 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004987 if (!pass) {
4988 vkDestroyBuffer(m_device->device(), buffer, NULL);
4989 return;
4990 }
4991
4992 VkDeviceMemory mem;
4993 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4994 ASSERT_VK_SUCCESS(err);
4995 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4996 ASSERT_VK_SUCCESS(err);
4997
4998 VkCommandBufferInheritanceInfo hinfo = {};
4999 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
5000 hinfo.renderPass = VK_NULL_HANDLE;
5001 hinfo.subpass = 0;
5002 hinfo.framebuffer = VK_NULL_HANDLE;
5003 hinfo.occlusionQueryEnable = VK_FALSE;
5004 hinfo.queryFlags = 0;
5005 hinfo.pipelineStatistics = 0;
5006
5007 {
5008 VkCommandBufferBeginInfo begin_info{};
5009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5010 begin_info.pInheritanceInfo = &hinfo;
5011 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5012
5013 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005015
5016 vkEndCommandBuffer(secondary_command_buffer);
5017
5018 begin_info.pInheritanceInfo = nullptr;
5019 vkBeginCommandBuffer(command_buffer, &begin_info);
5020
5021 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005023
5024 vkEndCommandBuffer(command_buffer);
5025 }
5026 {
5027 VkSubmitInfo submit_info{};
5028 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5029 submit_info.commandBufferCount = 1;
5030 submit_info.pCommandBuffers = &command_buffer;
5031 submit_info.signalSemaphoreCount = 0;
5032 submit_info.pSignalSemaphores = nullptr;
5033 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5034 }
5035
5036 vkQueueWaitIdle(queue);
5037
5038 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5039 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5040 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5041 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5042 vkDestroyBuffer(m_device->device(), buffer, NULL);
5043 vkFreeMemory(m_device->device(), mem, NULL);
5044
5045 m_errorMonitor->VerifyNotFound();
5046}
5047
5048// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005049TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005050 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005051
Cody Northropc31a84f2016-08-22 10:41:47 -06005052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005053 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005054 return;
5055
5056 m_errorMonitor->ExpectSuccess();
5057
5058 VkQueryPool query_pool;
5059 VkQueryPoolCreateInfo query_pool_create_info{};
5060 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5061 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5062 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005064
5065 VkCommandPool command_pool;
5066 VkCommandPoolCreateInfo pool_create_info{};
5067 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5068 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5069 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005071
5072 VkCommandBuffer command_buffer[2];
5073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005075 command_buffer_allocate_info.commandPool = command_pool;
5076 command_buffer_allocate_info.commandBufferCount = 2;
5077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005079
5080 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005081 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005082
5083 uint32_t qfi = 0;
5084 VkBufferCreateInfo buff_create_info = {};
5085 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5086 buff_create_info.size = 1024;
5087 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5088 buff_create_info.queueFamilyIndexCount = 1;
5089 buff_create_info.pQueueFamilyIndices = &qfi;
5090
5091 VkResult err;
5092 VkBuffer buffer;
5093 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5094 ASSERT_VK_SUCCESS(err);
5095 VkMemoryAllocateInfo mem_alloc = {};
5096 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5097 mem_alloc.pNext = NULL;
5098 mem_alloc.allocationSize = 1024;
5099 mem_alloc.memoryTypeIndex = 0;
5100
5101 VkMemoryRequirements memReqs;
5102 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005103 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005104 if (!pass) {
5105 vkDestroyBuffer(m_device->device(), buffer, NULL);
5106 return;
5107 }
5108
5109 VkDeviceMemory mem;
5110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5111 ASSERT_VK_SUCCESS(err);
5112 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5113 ASSERT_VK_SUCCESS(err);
5114
5115 {
5116 VkCommandBufferBeginInfo begin_info{};
5117 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5118 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5119
5120 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005121 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005122
5123 vkEndCommandBuffer(command_buffer[0]);
5124
5125 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005127 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005128
5129 vkEndCommandBuffer(command_buffer[1]);
5130 }
5131 {
5132 VkSubmitInfo submit_info{};
5133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5134 submit_info.commandBufferCount = 2;
5135 submit_info.pCommandBuffers = command_buffer;
5136 submit_info.signalSemaphoreCount = 0;
5137 submit_info.pSignalSemaphores = nullptr;
5138 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5139 }
5140
5141 vkQueueWaitIdle(queue);
5142
5143 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5144 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5145 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005146 vkDestroyBuffer(m_device->device(), buffer, NULL);
5147 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005148
5149 m_errorMonitor->VerifyNotFound();
5150}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005151
5152TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005153 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005154
Michael Lentine860b0fe2016-05-20 10:14:00 -05005155 m_errorMonitor->ExpectSuccess();
5156
Cody Northropc31a84f2016-08-22 10:41:47 -06005157 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005158 VkEvent event;
5159 VkEventCreateInfo event_create_info{};
5160 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5161 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5162
5163 VkCommandPool command_pool;
5164 VkCommandPoolCreateInfo pool_create_info{};
5165 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5166 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5167 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005169
5170 VkCommandBuffer command_buffer;
5171 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005173 command_buffer_allocate_info.commandPool = command_pool;
5174 command_buffer_allocate_info.commandBufferCount = 1;
5175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005176 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005177
5178 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005179 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005180
5181 {
5182 VkCommandBufferBeginInfo begin_info{};
5183 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5184 vkBeginCommandBuffer(command_buffer, &begin_info);
5185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005186 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5187 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5188 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005189 vkEndCommandBuffer(command_buffer);
5190 }
5191 {
5192 VkSubmitInfo submit_info{};
5193 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5194 submit_info.commandBufferCount = 1;
5195 submit_info.pCommandBuffers = &command_buffer;
5196 submit_info.signalSemaphoreCount = 0;
5197 submit_info.pSignalSemaphores = nullptr;
5198 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5199 }
5200 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5202 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005203 vkSetEvent(m_device->device(), event);
5204 m_errorMonitor->VerifyFound();
5205 }
5206
5207 vkQueueWaitIdle(queue);
5208
5209 vkDestroyEvent(m_device->device(), event, nullptr);
5210 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5211 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5212}
5213
5214// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005215TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5216 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5217 "run through a Submit & WaitForFences cycle 3 times. This "
5218 "previously revealed a bug so running this positive test "
5219 "to prevent a regression.");
5220 m_errorMonitor->ExpectSuccess();
5221
5222 ASSERT_NO_FATAL_FAILURE(InitState());
5223 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005224 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005225
5226 static const uint32_t NUM_OBJECTS = 2;
5227 static const uint32_t NUM_FRAMES = 3;
5228 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5229 VkFence fences[NUM_OBJECTS] = {};
5230
5231 VkCommandPool cmd_pool;
5232 VkCommandPoolCreateInfo cmd_pool_ci = {};
5233 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5234 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5235 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005236 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005237 ASSERT_VK_SUCCESS(err);
5238
5239 VkCommandBufferAllocateInfo cmd_buf_info = {};
5240 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5241 cmd_buf_info.commandPool = cmd_pool;
5242 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5243 cmd_buf_info.commandBufferCount = 1;
5244
5245 VkFenceCreateInfo fence_ci = {};
5246 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5247 fence_ci.pNext = nullptr;
5248 fence_ci.flags = 0;
5249
5250 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005251 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005252 ASSERT_VK_SUCCESS(err);
5253 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5254 ASSERT_VK_SUCCESS(err);
5255 }
5256
5257 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005258 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5259 // Create empty cmd buffer
5260 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5261 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005262
Tobin Ehlisf9025162016-05-26 06:55:21 -06005263 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5264 ASSERT_VK_SUCCESS(err);
5265 err = vkEndCommandBuffer(cmd_buffers[obj]);
5266 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005267
Tobin Ehlisf9025162016-05-26 06:55:21 -06005268 VkSubmitInfo submit_info = {};
5269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5270 submit_info.commandBufferCount = 1;
5271 submit_info.pCommandBuffers = &cmd_buffers[obj];
5272 // Submit cmd buffer and wait for fence
5273 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5274 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005275 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005276 ASSERT_VK_SUCCESS(err);
5277 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5278 ASSERT_VK_SUCCESS(err);
5279 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005280 }
5281 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005282 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5283 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5284 vkDestroyFence(m_device->device(), fences[i], nullptr);
5285 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005286}
5287// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005288TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5289
5290 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005292
Cody Northropc31a84f2016-08-22 10:41:47 -06005293 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005294 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005295 return;
5296
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005297 m_errorMonitor->ExpectSuccess();
5298
5299 VkSemaphore semaphore;
5300 VkSemaphoreCreateInfo semaphore_create_info{};
5301 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303
5304 VkCommandPool command_pool;
5305 VkCommandPoolCreateInfo pool_create_info{};
5306 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5307 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5308 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005310
5311 VkCommandBuffer command_buffer[2];
5312 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005313 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005314 command_buffer_allocate_info.commandPool = command_pool;
5315 command_buffer_allocate_info.commandBufferCount = 2;
5316 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005317 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005318
5319 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005320 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005321
5322 {
5323 VkCommandBufferBeginInfo begin_info{};
5324 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5325 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5326
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5328 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005329
5330 VkViewport viewport{};
5331 viewport.maxDepth = 1.0f;
5332 viewport.minDepth = 0.0f;
5333 viewport.width = 512;
5334 viewport.height = 512;
5335 viewport.x = 0;
5336 viewport.y = 0;
5337 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5338 vkEndCommandBuffer(command_buffer[0]);
5339 }
5340 {
5341 VkCommandBufferBeginInfo begin_info{};
5342 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5343 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5344
5345 VkViewport viewport{};
5346 viewport.maxDepth = 1.0f;
5347 viewport.minDepth = 0.0f;
5348 viewport.width = 512;
5349 viewport.height = 512;
5350 viewport.x = 0;
5351 viewport.y = 0;
5352 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5353 vkEndCommandBuffer(command_buffer[1]);
5354 }
5355 {
5356 VkSubmitInfo submit_info{};
5357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5358 submit_info.commandBufferCount = 1;
5359 submit_info.pCommandBuffers = &command_buffer[0];
5360 submit_info.signalSemaphoreCount = 1;
5361 submit_info.pSignalSemaphores = &semaphore;
5362 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5363 }
5364 {
5365 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5366 VkSubmitInfo submit_info{};
5367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5368 submit_info.commandBufferCount = 1;
5369 submit_info.pCommandBuffers = &command_buffer[1];
5370 submit_info.waitSemaphoreCount = 1;
5371 submit_info.pWaitSemaphores = &semaphore;
5372 submit_info.pWaitDstStageMask = flags;
5373 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5374 }
5375
5376 vkQueueWaitIdle(m_device->m_queue);
5377
5378 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005379 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005380 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5381
5382 m_errorMonitor->VerifyNotFound();
5383}
5384
5385// This is a positive test. No errors should be generated.
5386TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5387
5388 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5389 "submitted on separate queues, the second having a fence"
5390 "followed by a QueueWaitIdle.");
5391
Cody Northropc31a84f2016-08-22 10:41:47 -06005392 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005393 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005394 return;
5395
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005396 m_errorMonitor->ExpectSuccess();
5397
5398 VkFence fence;
5399 VkFenceCreateInfo fence_create_info{};
5400 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5401 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5402
5403 VkSemaphore semaphore;
5404 VkSemaphoreCreateInfo semaphore_create_info{};
5405 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407
5408 VkCommandPool command_pool;
5409 VkCommandPoolCreateInfo pool_create_info{};
5410 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5411 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5412 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005414
5415 VkCommandBuffer command_buffer[2];
5416 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005418 command_buffer_allocate_info.commandPool = command_pool;
5419 command_buffer_allocate_info.commandBufferCount = 2;
5420 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005421 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005422
5423 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005424 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005425
5426 {
5427 VkCommandBufferBeginInfo begin_info{};
5428 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5429 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5430
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005431 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5432 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005433
5434 VkViewport viewport{};
5435 viewport.maxDepth = 1.0f;
5436 viewport.minDepth = 0.0f;
5437 viewport.width = 512;
5438 viewport.height = 512;
5439 viewport.x = 0;
5440 viewport.y = 0;
5441 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5442 vkEndCommandBuffer(command_buffer[0]);
5443 }
5444 {
5445 VkCommandBufferBeginInfo begin_info{};
5446 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5447 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5448
5449 VkViewport viewport{};
5450 viewport.maxDepth = 1.0f;
5451 viewport.minDepth = 0.0f;
5452 viewport.width = 512;
5453 viewport.height = 512;
5454 viewport.x = 0;
5455 viewport.y = 0;
5456 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5457 vkEndCommandBuffer(command_buffer[1]);
5458 }
5459 {
5460 VkSubmitInfo submit_info{};
5461 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5462 submit_info.commandBufferCount = 1;
5463 submit_info.pCommandBuffers = &command_buffer[0];
5464 submit_info.signalSemaphoreCount = 1;
5465 submit_info.pSignalSemaphores = &semaphore;
5466 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5467 }
5468 {
5469 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5470 VkSubmitInfo submit_info{};
5471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5472 submit_info.commandBufferCount = 1;
5473 submit_info.pCommandBuffers = &command_buffer[1];
5474 submit_info.waitSemaphoreCount = 1;
5475 submit_info.pWaitSemaphores = &semaphore;
5476 submit_info.pWaitDstStageMask = flags;
5477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5478 }
5479
5480 vkQueueWaitIdle(m_device->m_queue);
5481
5482 vkDestroyFence(m_device->device(), fence, nullptr);
5483 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005484 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005485 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5486
5487 m_errorMonitor->VerifyNotFound();
5488}
5489
5490// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005491TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005492
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005493 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5494 "submitted on separate queues, the second having a fence"
5495 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005496
Cody Northropc31a84f2016-08-22 10:41:47 -06005497 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005499 return;
5500
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005501 m_errorMonitor->ExpectSuccess();
5502
5503 VkFence fence;
5504 VkFenceCreateInfo fence_create_info{};
5505 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5506 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5507
5508 VkSemaphore semaphore;
5509 VkSemaphoreCreateInfo semaphore_create_info{};
5510 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512
5513 VkCommandPool command_pool;
5514 VkCommandPoolCreateInfo pool_create_info{};
5515 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5516 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5517 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005519
5520 VkCommandBuffer command_buffer[2];
5521 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005522 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005523 command_buffer_allocate_info.commandPool = command_pool;
5524 command_buffer_allocate_info.commandBufferCount = 2;
5525 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005526 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005527
5528 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005529 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005530
5531 {
5532 VkCommandBufferBeginInfo begin_info{};
5533 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5534 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005536 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5537 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005538
5539 VkViewport viewport{};
5540 viewport.maxDepth = 1.0f;
5541 viewport.minDepth = 0.0f;
5542 viewport.width = 512;
5543 viewport.height = 512;
5544 viewport.x = 0;
5545 viewport.y = 0;
5546 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5547 vkEndCommandBuffer(command_buffer[0]);
5548 }
5549 {
5550 VkCommandBufferBeginInfo begin_info{};
5551 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5552 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5553
5554 VkViewport viewport{};
5555 viewport.maxDepth = 1.0f;
5556 viewport.minDepth = 0.0f;
5557 viewport.width = 512;
5558 viewport.height = 512;
5559 viewport.x = 0;
5560 viewport.y = 0;
5561 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5562 vkEndCommandBuffer(command_buffer[1]);
5563 }
5564 {
5565 VkSubmitInfo submit_info{};
5566 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5567 submit_info.commandBufferCount = 1;
5568 submit_info.pCommandBuffers = &command_buffer[0];
5569 submit_info.signalSemaphoreCount = 1;
5570 submit_info.pSignalSemaphores = &semaphore;
5571 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5572 }
5573 {
5574 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5575 VkSubmitInfo submit_info{};
5576 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5577 submit_info.commandBufferCount = 1;
5578 submit_info.pCommandBuffers = &command_buffer[1];
5579 submit_info.waitSemaphoreCount = 1;
5580 submit_info.pWaitSemaphores = &semaphore;
5581 submit_info.pWaitDstStageMask = flags;
5582 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5583 }
5584
5585 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5586 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5587
5588 vkDestroyFence(m_device->device(), fence, nullptr);
5589 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005590 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005591 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5592
5593 m_errorMonitor->VerifyNotFound();
5594}
5595
Chris Forbes0f8126b2016-06-20 17:48:22 +12005596TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005597
5598 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005599 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005600 printf("Test requires two queues, skipping\n");
5601 return;
5602 }
5603
5604 VkResult err;
5605
5606 m_errorMonitor->ExpectSuccess();
5607
5608 VkQueue q0 = m_device->m_queue;
5609 VkQueue q1 = nullptr;
5610 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5611 ASSERT_NE(q1, nullptr);
5612
5613 // An (empty) command buffer. We must have work in the first submission --
5614 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005615 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005616 VkCommandPool pool;
5617 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5618 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5620 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621 VkCommandBuffer cb;
5622 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5623 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005625 err = vkBeginCommandBuffer(cb, &cbbi);
5626 ASSERT_VK_SUCCESS(err);
5627 err = vkEndCommandBuffer(cb);
5628 ASSERT_VK_SUCCESS(err);
5629
5630 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005631 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005632 VkSemaphore s;
5633 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5634 ASSERT_VK_SUCCESS(err);
5635
5636 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005638
5639 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5640 ASSERT_VK_SUCCESS(err);
5641
5642 // Second submission, to q1, waiting on s
5643 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005645
5646 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5647 ASSERT_VK_SUCCESS(err);
5648
5649 // Wait for q0 idle
5650 err = vkQueueWaitIdle(q0);
5651 ASSERT_VK_SUCCESS(err);
5652
5653 // Command buffer should have been completed (it was on q0); reset the pool.
5654 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5655
5656 m_errorMonitor->VerifyNotFound();
5657
5658 // Force device completely idle and clean up resources
5659 vkDeviceWaitIdle(m_device->device());
5660 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5661 vkDestroySemaphore(m_device->device(), s, nullptr);
5662}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005663
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005664// This is a positive test. No errors should be generated.
5665TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5666
5667 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5668 "submitted on separate queues, the second having a fence, "
5669 "followed by a WaitForFences call.");
5670
Cody Northropc31a84f2016-08-22 10:41:47 -06005671 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005672 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005673 return;
5674
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005675 m_errorMonitor->ExpectSuccess();
5676
Cody Northropc31a84f2016-08-22 10:41:47 -06005677 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005678 VkFence fence;
5679 VkFenceCreateInfo fence_create_info{};
5680 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5681 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5682
5683 VkSemaphore semaphore;
5684 VkSemaphoreCreateInfo semaphore_create_info{};
5685 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687
5688 VkCommandPool command_pool;
5689 VkCommandPoolCreateInfo pool_create_info{};
5690 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5691 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5692 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005694
5695 VkCommandBuffer command_buffer[2];
5696 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005698 command_buffer_allocate_info.commandPool = command_pool;
5699 command_buffer_allocate_info.commandBufferCount = 2;
5700 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005701 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005702
5703 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005705
5706 {
5707 VkCommandBufferBeginInfo begin_info{};
5708 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5709 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5712 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005713
5714 VkViewport viewport{};
5715 viewport.maxDepth = 1.0f;
5716 viewport.minDepth = 0.0f;
5717 viewport.width = 512;
5718 viewport.height = 512;
5719 viewport.x = 0;
5720 viewport.y = 0;
5721 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5722 vkEndCommandBuffer(command_buffer[0]);
5723 }
5724 {
5725 VkCommandBufferBeginInfo begin_info{};
5726 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5727 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5728
5729 VkViewport viewport{};
5730 viewport.maxDepth = 1.0f;
5731 viewport.minDepth = 0.0f;
5732 viewport.width = 512;
5733 viewport.height = 512;
5734 viewport.x = 0;
5735 viewport.y = 0;
5736 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5737 vkEndCommandBuffer(command_buffer[1]);
5738 }
5739 {
5740 VkSubmitInfo submit_info{};
5741 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5742 submit_info.commandBufferCount = 1;
5743 submit_info.pCommandBuffers = &command_buffer[0];
5744 submit_info.signalSemaphoreCount = 1;
5745 submit_info.pSignalSemaphores = &semaphore;
5746 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5747 }
5748 {
5749 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5750 VkSubmitInfo submit_info{};
5751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5752 submit_info.commandBufferCount = 1;
5753 submit_info.pCommandBuffers = &command_buffer[1];
5754 submit_info.waitSemaphoreCount = 1;
5755 submit_info.pWaitSemaphores = &semaphore;
5756 submit_info.pWaitDstStageMask = flags;
5757 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5758 }
5759
5760 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5761
5762 vkDestroyFence(m_device->device(), fence, nullptr);
5763 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005764 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005765 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5766
5767 m_errorMonitor->VerifyNotFound();
5768}
5769
5770// This is a positive test. No errors should be generated.
5771TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5772
5773 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5774 "on the same queue, sharing a signal/wait semaphore, the "
5775 "second having a fence, "
5776 "followed by a WaitForFences call.");
5777
5778 m_errorMonitor->ExpectSuccess();
5779
Cody Northropc31a84f2016-08-22 10:41:47 -06005780 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005781 VkFence fence;
5782 VkFenceCreateInfo fence_create_info{};
5783 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5784 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5785
5786 VkSemaphore semaphore;
5787 VkSemaphoreCreateInfo semaphore_create_info{};
5788 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005790
5791 VkCommandPool command_pool;
5792 VkCommandPoolCreateInfo pool_create_info{};
5793 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5794 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5795 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005797
5798 VkCommandBuffer command_buffer[2];
5799 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005801 command_buffer_allocate_info.commandPool = command_pool;
5802 command_buffer_allocate_info.commandBufferCount = 2;
5803 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005804 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005805
5806 {
5807 VkCommandBufferBeginInfo begin_info{};
5808 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5809 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5812 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005813
5814 VkViewport viewport{};
5815 viewport.maxDepth = 1.0f;
5816 viewport.minDepth = 0.0f;
5817 viewport.width = 512;
5818 viewport.height = 512;
5819 viewport.x = 0;
5820 viewport.y = 0;
5821 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5822 vkEndCommandBuffer(command_buffer[0]);
5823 }
5824 {
5825 VkCommandBufferBeginInfo begin_info{};
5826 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5827 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5828
5829 VkViewport viewport{};
5830 viewport.maxDepth = 1.0f;
5831 viewport.minDepth = 0.0f;
5832 viewport.width = 512;
5833 viewport.height = 512;
5834 viewport.x = 0;
5835 viewport.y = 0;
5836 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5837 vkEndCommandBuffer(command_buffer[1]);
5838 }
5839 {
5840 VkSubmitInfo submit_info{};
5841 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5842 submit_info.commandBufferCount = 1;
5843 submit_info.pCommandBuffers = &command_buffer[0];
5844 submit_info.signalSemaphoreCount = 1;
5845 submit_info.pSignalSemaphores = &semaphore;
5846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5847 }
5848 {
5849 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5850 VkSubmitInfo submit_info{};
5851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5852 submit_info.commandBufferCount = 1;
5853 submit_info.pCommandBuffers = &command_buffer[1];
5854 submit_info.waitSemaphoreCount = 1;
5855 submit_info.pWaitSemaphores = &semaphore;
5856 submit_info.pWaitDstStageMask = flags;
5857 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5858 }
5859
5860 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5861
5862 vkDestroyFence(m_device->device(), fence, nullptr);
5863 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005864 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005865 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5866
5867 m_errorMonitor->VerifyNotFound();
5868}
5869
5870// This is a positive test. No errors should be generated.
5871TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5874 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5875 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005876
5877 m_errorMonitor->ExpectSuccess();
5878
Cody Northropc31a84f2016-08-22 10:41:47 -06005879 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005880 VkFence fence;
5881 VkFenceCreateInfo fence_create_info{};
5882 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5883 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5884
5885 VkCommandPool command_pool;
5886 VkCommandPoolCreateInfo pool_create_info{};
5887 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5888 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5889 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005890 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005891
5892 VkCommandBuffer command_buffer[2];
5893 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005895 command_buffer_allocate_info.commandPool = command_pool;
5896 command_buffer_allocate_info.commandBufferCount = 2;
5897 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005898 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005899
5900 {
5901 VkCommandBufferBeginInfo begin_info{};
5902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5903 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5906 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005907
5908 VkViewport viewport{};
5909 viewport.maxDepth = 1.0f;
5910 viewport.minDepth = 0.0f;
5911 viewport.width = 512;
5912 viewport.height = 512;
5913 viewport.x = 0;
5914 viewport.y = 0;
5915 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5916 vkEndCommandBuffer(command_buffer[0]);
5917 }
5918 {
5919 VkCommandBufferBeginInfo begin_info{};
5920 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5921 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5922
5923 VkViewport viewport{};
5924 viewport.maxDepth = 1.0f;
5925 viewport.minDepth = 0.0f;
5926 viewport.width = 512;
5927 viewport.height = 512;
5928 viewport.x = 0;
5929 viewport.y = 0;
5930 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5931 vkEndCommandBuffer(command_buffer[1]);
5932 }
5933 {
5934 VkSubmitInfo submit_info{};
5935 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5936 submit_info.commandBufferCount = 1;
5937 submit_info.pCommandBuffers = &command_buffer[0];
5938 submit_info.signalSemaphoreCount = 0;
5939 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5941 }
5942 {
5943 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5944 VkSubmitInfo submit_info{};
5945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5946 submit_info.commandBufferCount = 1;
5947 submit_info.pCommandBuffers = &command_buffer[1];
5948 submit_info.waitSemaphoreCount = 0;
5949 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5950 submit_info.pWaitDstStageMask = flags;
5951 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5952 }
5953
5954 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005956 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005957 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005958
5959 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005961 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5962
5963 m_errorMonitor->VerifyNotFound();
5964}
5965
5966// This is a positive test. No errors should be generated.
5967TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5968
5969 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5970 "on the same queue, the second having a fence, followed "
5971 "by a WaitForFences call.");
5972
5973 m_errorMonitor->ExpectSuccess();
5974
Cody Northropc31a84f2016-08-22 10:41:47 -06005975 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005976 VkFence fence;
5977 VkFenceCreateInfo fence_create_info{};
5978 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5979 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5980
5981 VkCommandPool command_pool;
5982 VkCommandPoolCreateInfo pool_create_info{};
5983 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5984 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5985 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005986 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005987
5988 VkCommandBuffer command_buffer[2];
5989 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005991 command_buffer_allocate_info.commandPool = command_pool;
5992 command_buffer_allocate_info.commandBufferCount = 2;
5993 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005994 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005995
5996 {
5997 VkCommandBufferBeginInfo begin_info{};
5998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5999 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6000
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006001 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6002 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006003
6004 VkViewport viewport{};
6005 viewport.maxDepth = 1.0f;
6006 viewport.minDepth = 0.0f;
6007 viewport.width = 512;
6008 viewport.height = 512;
6009 viewport.x = 0;
6010 viewport.y = 0;
6011 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6012 vkEndCommandBuffer(command_buffer[0]);
6013 }
6014 {
6015 VkCommandBufferBeginInfo begin_info{};
6016 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6017 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6018
6019 VkViewport viewport{};
6020 viewport.maxDepth = 1.0f;
6021 viewport.minDepth = 0.0f;
6022 viewport.width = 512;
6023 viewport.height = 512;
6024 viewport.x = 0;
6025 viewport.y = 0;
6026 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6027 vkEndCommandBuffer(command_buffer[1]);
6028 }
6029 {
6030 VkSubmitInfo submit_info{};
6031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6032 submit_info.commandBufferCount = 1;
6033 submit_info.pCommandBuffers = &command_buffer[0];
6034 submit_info.signalSemaphoreCount = 0;
6035 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6036 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6037 }
6038 {
6039 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6040 VkSubmitInfo submit_info{};
6041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6042 submit_info.commandBufferCount = 1;
6043 submit_info.pCommandBuffers = &command_buffer[1];
6044 submit_info.waitSemaphoreCount = 0;
6045 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6046 submit_info.pWaitDstStageMask = flags;
6047 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6048 }
6049
6050 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6051
6052 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006053 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006054 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6055
6056 m_errorMonitor->VerifyNotFound();
6057}
6058
6059// This is a positive test. No errors should be generated.
6060TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006062 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6063 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006064 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006065
6066 m_errorMonitor->ExpectSuccess();
6067
6068 VkFence fence;
6069 VkFenceCreateInfo fence_create_info{};
6070 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6071 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6072
6073 VkSemaphore semaphore;
6074 VkSemaphoreCreateInfo semaphore_create_info{};
6075 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006077
6078 VkCommandPool command_pool;
6079 VkCommandPoolCreateInfo pool_create_info{};
6080 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6081 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6082 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006083 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006084
6085 VkCommandBuffer command_buffer[2];
6086 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006088 command_buffer_allocate_info.commandPool = command_pool;
6089 command_buffer_allocate_info.commandBufferCount = 2;
6090 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006091 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006092
6093 {
6094 VkCommandBufferBeginInfo begin_info{};
6095 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6096 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006098 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6099 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006100
6101 VkViewport viewport{};
6102 viewport.maxDepth = 1.0f;
6103 viewport.minDepth = 0.0f;
6104 viewport.width = 512;
6105 viewport.height = 512;
6106 viewport.x = 0;
6107 viewport.y = 0;
6108 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6109 vkEndCommandBuffer(command_buffer[0]);
6110 }
6111 {
6112 VkCommandBufferBeginInfo begin_info{};
6113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6115
6116 VkViewport viewport{};
6117 viewport.maxDepth = 1.0f;
6118 viewport.minDepth = 0.0f;
6119 viewport.width = 512;
6120 viewport.height = 512;
6121 viewport.x = 0;
6122 viewport.y = 0;
6123 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6124 vkEndCommandBuffer(command_buffer[1]);
6125 }
6126 {
6127 VkSubmitInfo submit_info[2];
6128 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6129
6130 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6131 submit_info[0].pNext = NULL;
6132 submit_info[0].commandBufferCount = 1;
6133 submit_info[0].pCommandBuffers = &command_buffer[0];
6134 submit_info[0].signalSemaphoreCount = 1;
6135 submit_info[0].pSignalSemaphores = &semaphore;
6136 submit_info[0].waitSemaphoreCount = 0;
6137 submit_info[0].pWaitSemaphores = NULL;
6138 submit_info[0].pWaitDstStageMask = 0;
6139
6140 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6141 submit_info[1].pNext = NULL;
6142 submit_info[1].commandBufferCount = 1;
6143 submit_info[1].pCommandBuffers = &command_buffer[1];
6144 submit_info[1].waitSemaphoreCount = 1;
6145 submit_info[1].pWaitSemaphores = &semaphore;
6146 submit_info[1].pWaitDstStageMask = flags;
6147 submit_info[1].signalSemaphoreCount = 0;
6148 submit_info[1].pSignalSemaphores = NULL;
6149 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6150 }
6151
6152 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6153
6154 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006155 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006156 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006157 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006158
6159 m_errorMonitor->VerifyNotFound();
6160}
6161
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006162TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6164 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006165
Cody Northropc31a84f2016-08-22 10:41:47 -06006166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006167 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006170 m_errorMonitor->VerifyFound();
6171}
6172
6173TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6175 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006176
Cody Northropc31a84f2016-08-22 10:41:47 -06006177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006178 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006181 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006182}
6183
6184TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006185 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6186 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006187
Cody Northropc31a84f2016-08-22 10:41:47 -06006188 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006189 // Dynamic viewport state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006192 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006193}
6194
6195TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006196 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6197 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006198
Cody Northropc31a84f2016-08-22 10:41:47 -06006199 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006200 // Dynamic scissor state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006202 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006203 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006204}
6205
Cortd713fe82016-07-27 09:51:27 -07006206TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006207 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6208 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006209
6210 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006211 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6213 "Dynamic blend constants state not set for this command buffer");
6214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006215 m_errorMonitor->VerifyFound();
6216}
6217
6218TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006219 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6220 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006221
6222 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006223 if (!m_device->phy().features().depthBounds) {
6224 printf("Device does not support depthBounds test; skipped.\n");
6225 return;
6226 }
6227 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6229 "Dynamic depth bounds state not set for this command buffer");
6230 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006231 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006232}
6233
6234TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6236 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006237
6238 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006239 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6241 "Dynamic stencil read mask state not set for this command buffer");
6242 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006243 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006244}
6245
6246TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006247 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6248 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006249
6250 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006251 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6253 "Dynamic stencil write mask state not set for this command buffer");
6254 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006255 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006256}
6257
6258TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6260 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006261
6262 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006263 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6265 "Dynamic stencil reference state not set for this command buffer");
6266 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006267 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006268}
6269
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006270TEST_F(VkLayerTest, IndexBufferNotBound) {
6271 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006272
6273 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6275 "Index buffer object not bound to this command buffer when Indexed ");
6276 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006277 m_errorMonitor->VerifyFound();
6278}
6279
Karl Schultz6addd812016-02-02 17:17:23 -07006280TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6282 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6283 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006284
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006285 ASSERT_NO_FATAL_FAILURE(InitState());
6286 ASSERT_NO_FATAL_FAILURE(InitViewport());
6287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6288
Karl Schultz6addd812016-02-02 17:17:23 -07006289 // We luck out b/c by default the framework creates CB w/ the
6290 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006291 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006292 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006293 EndCommandBuffer();
6294
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006295 // Bypass framework since it does the waits automatically
6296 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006297 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006298 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6299 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006300 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006301 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006302 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006303 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006304 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006305 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006306 submit_info.pSignalSemaphores = NULL;
6307
Chris Forbes40028e22016-06-13 09:59:34 +12006308 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006309 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006310
Karl Schultz6addd812016-02-02 17:17:23 -07006311 // Cause validation error by re-submitting cmd buffer that should only be
6312 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006313 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006314
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006315 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006316}
6317
Karl Schultz6addd812016-02-02 17:17:23 -07006318TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006319 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006320 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6323 "type "
6324 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006325
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006326 ASSERT_NO_FATAL_FAILURE(InitState());
6327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006328
Karl Schultz6addd812016-02-02 17:17:23 -07006329 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6330 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006331 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6333 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006334
6335 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006336 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6337 ds_pool_ci.pNext = NULL;
6338 ds_pool_ci.flags = 0;
6339 ds_pool_ci.maxSets = 1;
6340 ds_pool_ci.poolSizeCount = 1;
6341 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006342
6343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006345 ASSERT_VK_SUCCESS(err);
6346
6347 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006348 dsl_binding.binding = 0;
6349 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6350 dsl_binding.descriptorCount = 1;
6351 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6352 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006353
6354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6356 ds_layout_ci.pNext = NULL;
6357 ds_layout_ci.bindingCount = 1;
6358 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006359
6360 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006361 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006362 ASSERT_VK_SUCCESS(err);
6363
6364 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006365 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006366 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006367 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006368 alloc_info.descriptorPool = ds_pool;
6369 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006371
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006372 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006373
Chia-I Wuf7458c52015-10-26 21:10:41 +08006374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006376}
6377
Karl Schultz6addd812016-02-02 17:17:23 -07006378TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6379 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006380
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6382 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6383 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006384
Tobin Ehlise735c692015-10-08 13:13:50 -06006385 ASSERT_NO_FATAL_FAILURE(InitState());
6386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006387
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006388 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006389 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6390 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006391
6392 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006393 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6394 ds_pool_ci.pNext = NULL;
6395 ds_pool_ci.maxSets = 1;
6396 ds_pool_ci.poolSizeCount = 1;
6397 ds_pool_ci.flags = 0;
6398 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6399 // app can only call vkResetDescriptorPool on this pool.;
6400 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006401
6402 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006404 ASSERT_VK_SUCCESS(err);
6405
6406 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006407 dsl_binding.binding = 0;
6408 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6409 dsl_binding.descriptorCount = 1;
6410 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6411 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006412
6413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6415 ds_layout_ci.pNext = NULL;
6416 ds_layout_ci.bindingCount = 1;
6417 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006418
6419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006421 ASSERT_VK_SUCCESS(err);
6422
6423 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006424 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006426 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006427 alloc_info.descriptorPool = ds_pool;
6428 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006430 ASSERT_VK_SUCCESS(err);
6431
6432 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006433 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006434
Chia-I Wuf7458c52015-10-26 21:10:41 +08006435 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006437}
6438
Karl Schultz6addd812016-02-02 17:17:23 -07006439TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006440 // Attempt to clear Descriptor Pool with bad object.
6441 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006442
6443 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006445 uint64_t fake_pool_handle = 0xbaad6001;
6446 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6447 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006449}
6450
Karl Schultz6addd812016-02-02 17:17:23 -07006451TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006452 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6453 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006454 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006455 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006456
6457 uint64_t fake_set_handle = 0xbaad6001;
6458 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006459 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006461
6462 ASSERT_NO_FATAL_FAILURE(InitState());
6463
6464 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6465 layout_bindings[0].binding = 0;
6466 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6467 layout_bindings[0].descriptorCount = 1;
6468 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6469 layout_bindings[0].pImmutableSamplers = NULL;
6470
6471 VkDescriptorSetLayout descriptor_set_layout;
6472 VkDescriptorSetLayoutCreateInfo dslci = {};
6473 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6474 dslci.pNext = NULL;
6475 dslci.bindingCount = 1;
6476 dslci.pBindings = layout_bindings;
6477 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006478 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006479
6480 VkPipelineLayout pipeline_layout;
6481 VkPipelineLayoutCreateInfo plci = {};
6482 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6483 plci.pNext = NULL;
6484 plci.setLayoutCount = 1;
6485 plci.pSetLayouts = &descriptor_set_layout;
6486 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006487 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006488
6489 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006490 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6491 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006492 m_errorMonitor->VerifyFound();
6493 EndCommandBuffer();
6494 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6495 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006496}
6497
Karl Schultz6addd812016-02-02 17:17:23 -07006498TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006499 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6500 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006501 uint64_t fake_layout_handle = 0xbaad6001;
6502 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006504 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006505 VkPipelineLayout pipeline_layout;
6506 VkPipelineLayoutCreateInfo plci = {};
6507 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6508 plci.pNext = NULL;
6509 plci.setLayoutCount = 1;
6510 plci.pSetLayouts = &bad_layout;
6511 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6512
6513 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006514}
6515
Mark Muellerd4914412016-06-13 17:52:06 -06006516TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6517 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6518 "1) A uniform buffer update must have a valid buffer index."
6519 "2) When using an array of descriptors in a single WriteDescriptor,"
6520 " the descriptor types and stageflags must all be the same."
6521 "3) Immutable Sampler state must match across descriptors");
6522
6523 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6525 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6526 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6527 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6528 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006529
Mark Muellerd4914412016-06-13 17:52:06 -06006530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6531
6532 ASSERT_NO_FATAL_FAILURE(InitState());
6533 VkDescriptorPoolSize ds_type_count[4] = {};
6534 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6535 ds_type_count[0].descriptorCount = 1;
6536 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6537 ds_type_count[1].descriptorCount = 1;
6538 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6539 ds_type_count[2].descriptorCount = 1;
6540 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6541 ds_type_count[3].descriptorCount = 1;
6542
6543 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6544 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6545 ds_pool_ci.maxSets = 1;
6546 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6547 ds_pool_ci.pPoolSizes = ds_type_count;
6548
6549 VkDescriptorPool ds_pool;
6550 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6551 ASSERT_VK_SUCCESS(err);
6552
Mark Muellerb9896722016-06-16 09:54:29 -06006553 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006554 layout_binding[0].binding = 0;
6555 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6556 layout_binding[0].descriptorCount = 1;
6557 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6558 layout_binding[0].pImmutableSamplers = NULL;
6559
6560 layout_binding[1].binding = 1;
6561 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6562 layout_binding[1].descriptorCount = 1;
6563 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6564 layout_binding[1].pImmutableSamplers = NULL;
6565
6566 VkSamplerCreateInfo sampler_ci = {};
6567 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6568 sampler_ci.pNext = NULL;
6569 sampler_ci.magFilter = VK_FILTER_NEAREST;
6570 sampler_ci.minFilter = VK_FILTER_NEAREST;
6571 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6572 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6573 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6574 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6575 sampler_ci.mipLodBias = 1.0;
6576 sampler_ci.anisotropyEnable = VK_FALSE;
6577 sampler_ci.maxAnisotropy = 1;
6578 sampler_ci.compareEnable = VK_FALSE;
6579 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6580 sampler_ci.minLod = 1.0;
6581 sampler_ci.maxLod = 1.0;
6582 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6583 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6584 VkSampler sampler;
6585
6586 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6587 ASSERT_VK_SUCCESS(err);
6588
6589 layout_binding[2].binding = 2;
6590 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6591 layout_binding[2].descriptorCount = 1;
6592 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6593 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6594
Mark Muellerd4914412016-06-13 17:52:06 -06006595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6597 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6598 ds_layout_ci.pBindings = layout_binding;
6599 VkDescriptorSetLayout ds_layout;
6600 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6601 ASSERT_VK_SUCCESS(err);
6602
6603 VkDescriptorSetAllocateInfo alloc_info = {};
6604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6605 alloc_info.descriptorSetCount = 1;
6606 alloc_info.descriptorPool = ds_pool;
6607 alloc_info.pSetLayouts = &ds_layout;
6608 VkDescriptorSet descriptorSet;
6609 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6610 ASSERT_VK_SUCCESS(err);
6611
6612 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6613 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6614 pipeline_layout_ci.pNext = NULL;
6615 pipeline_layout_ci.setLayoutCount = 1;
6616 pipeline_layout_ci.pSetLayouts = &ds_layout;
6617
6618 VkPipelineLayout pipeline_layout;
6619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6620 ASSERT_VK_SUCCESS(err);
6621
Mark Mueller5c838ce2016-06-16 09:54:29 -06006622 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006623 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6624 descriptor_write.dstSet = descriptorSet;
6625 descriptor_write.dstBinding = 0;
6626 descriptor_write.descriptorCount = 1;
6627 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6628
Mark Mueller5c838ce2016-06-16 09:54:29 -06006629 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006630 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6631 m_errorMonitor->VerifyFound();
6632
6633 // Create a buffer to update the descriptor with
6634 uint32_t qfi = 0;
6635 VkBufferCreateInfo buffCI = {};
6636 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6637 buffCI.size = 1024;
6638 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6639 buffCI.queueFamilyIndexCount = 1;
6640 buffCI.pQueueFamilyIndices = &qfi;
6641
6642 VkBuffer dyub;
6643 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6644 ASSERT_VK_SUCCESS(err);
6645 VkDescriptorBufferInfo buffInfo = {};
6646 buffInfo.buffer = dyub;
6647 buffInfo.offset = 0;
6648 buffInfo.range = 1024;
6649
6650 descriptor_write.pBufferInfo = &buffInfo;
6651 descriptor_write.descriptorCount = 2;
6652
Mark Mueller5c838ce2016-06-16 09:54:29 -06006653 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6655 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6656 m_errorMonitor->VerifyFound();
6657
Mark Mueller5c838ce2016-06-16 09:54:29 -06006658 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6659 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006660 descriptor_write.dstBinding = 1;
6661 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006662
Mark Mueller5c838ce2016-06-16 09:54:29 -06006663 // Make pImageInfo index non-null to avoid complaints of it missing
6664 VkDescriptorImageInfo imageInfo = {};
6665 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6666 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6669 m_errorMonitor->VerifyFound();
6670
Mark Muellerd4914412016-06-13 17:52:06 -06006671 vkDestroyBuffer(m_device->device(), dyub, NULL);
6672 vkDestroySampler(m_device->device(), sampler, NULL);
6673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6676}
6677
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006678TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6679 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6680 "due to a buffer dependency being destroyed.");
6681 ASSERT_NO_FATAL_FAILURE(InitState());
6682
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006683 VkBuffer buffer;
6684 VkDeviceMemory mem;
6685 VkMemoryRequirements mem_reqs;
6686
6687 VkBufferCreateInfo buf_info = {};
6688 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12006689 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006690 buf_info.size = 256;
6691 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6692 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6693 ASSERT_VK_SUCCESS(err);
6694
6695 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6696
6697 VkMemoryAllocateInfo alloc_info = {};
6698 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6699 alloc_info.allocationSize = 256;
6700 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006701 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 -06006702 if (!pass) {
6703 vkDestroyBuffer(m_device->device(), buffer, NULL);
6704 return;
6705 }
6706 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6707 ASSERT_VK_SUCCESS(err);
6708
6709 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6710 ASSERT_VK_SUCCESS(err);
6711
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006712 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12006713 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006714 m_commandBuffer->EndCommandBuffer();
6715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006717 // Destroy buffer dependency prior to submit to cause ERROR
6718 vkDestroyBuffer(m_device->device(), buffer, NULL);
6719
6720 VkSubmitInfo submit_info = {};
6721 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6722 submit_info.commandBufferCount = 1;
6723 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6724 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6725
6726 m_errorMonitor->VerifyFound();
6727 vkFreeMemory(m_device->handle(), mem, NULL);
6728}
6729
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006730TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6731 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6732 "due to an image dependency being destroyed.");
6733 ASSERT_NO_FATAL_FAILURE(InitState());
6734
6735 VkImage image;
6736 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6737 VkImageCreateInfo image_create_info = {};
6738 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6739 image_create_info.pNext = NULL;
6740 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6741 image_create_info.format = tex_format;
6742 image_create_info.extent.width = 32;
6743 image_create_info.extent.height = 32;
6744 image_create_info.extent.depth = 1;
6745 image_create_info.mipLevels = 1;
6746 image_create_info.arrayLayers = 1;
6747 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6748 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006750 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006752 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006753 // Have to bind memory to image before recording cmd in cmd buffer using it
6754 VkMemoryRequirements mem_reqs;
6755 VkDeviceMemory image_mem;
6756 bool pass;
6757 VkMemoryAllocateInfo mem_alloc = {};
6758 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6759 mem_alloc.pNext = NULL;
6760 mem_alloc.memoryTypeIndex = 0;
6761 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6762 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006763 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006764 ASSERT_TRUE(pass);
6765 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6766 ASSERT_VK_SUCCESS(err);
6767 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6768 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006769
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006770 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006771 VkClearColorValue ccv;
6772 ccv.float32[0] = 1.0f;
6773 ccv.float32[1] = 1.0f;
6774 ccv.float32[2] = 1.0f;
6775 ccv.float32[3] = 1.0f;
6776 VkImageSubresourceRange isr = {};
6777 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006778 isr.baseArrayLayer = 0;
6779 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006780 isr.layerCount = 1;
6781 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006782 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006783 m_commandBuffer->EndCommandBuffer();
6784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006786 // Destroy image dependency prior to submit to cause ERROR
6787 vkDestroyImage(m_device->device(), image, NULL);
6788
6789 VkSubmitInfo submit_info = {};
6790 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6791 submit_info.commandBufferCount = 1;
6792 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6793 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6794
6795 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006796 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006797}
6798
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006799TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6800 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6801 "due to a framebuffer image dependency being destroyed.");
6802 VkFormatProperties format_properties;
6803 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6805 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006806 return;
6807 }
6808
6809 ASSERT_NO_FATAL_FAILURE(InitState());
6810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6811
6812 VkImageCreateInfo image_ci = {};
6813 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6814 image_ci.pNext = NULL;
6815 image_ci.imageType = VK_IMAGE_TYPE_2D;
6816 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6817 image_ci.extent.width = 32;
6818 image_ci.extent.height = 32;
6819 image_ci.extent.depth = 1;
6820 image_ci.mipLevels = 1;
6821 image_ci.arrayLayers = 1;
6822 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6823 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006824 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006825 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6826 image_ci.flags = 0;
6827 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006828 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006829
6830 VkMemoryRequirements memory_reqs;
6831 VkDeviceMemory image_memory;
6832 bool pass;
6833 VkMemoryAllocateInfo memory_info = {};
6834 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6835 memory_info.pNext = NULL;
6836 memory_info.allocationSize = 0;
6837 memory_info.memoryTypeIndex = 0;
6838 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6839 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006840 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006841 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006842 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006843 ASSERT_VK_SUCCESS(err);
6844 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6845 ASSERT_VK_SUCCESS(err);
6846
6847 VkImageViewCreateInfo ivci = {
6848 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6849 nullptr,
6850 0,
6851 image,
6852 VK_IMAGE_VIEW_TYPE_2D,
6853 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006854 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006855 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6856 };
6857 VkImageView view;
6858 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6859 ASSERT_VK_SUCCESS(err);
6860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006861 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006862 VkFramebuffer fb;
6863 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6864 ASSERT_VK_SUCCESS(err);
6865
6866 // Just use default renderpass with our framebuffer
6867 m_renderPassBeginInfo.framebuffer = fb;
6868 // Create Null cmd buffer for submit
6869 BeginCommandBuffer();
6870 EndCommandBuffer();
6871 // Destroy image attached to framebuffer to invalidate cmd buffer
6872 vkDestroyImage(m_device->device(), image, NULL);
6873 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006875 QueueCommandBuffer(false);
6876 m_errorMonitor->VerifyFound();
6877
6878 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6879 vkDestroyImageView(m_device->device(), view, nullptr);
6880 vkFreeMemory(m_device->device(), image_memory, nullptr);
6881}
6882
Tobin Ehlis88becd72016-09-21 14:33:41 -06006883TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
6884 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
6885 VkFormatProperties format_properties;
6886 VkResult err = VK_SUCCESS;
6887 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06006888
6889 ASSERT_NO_FATAL_FAILURE(InitState());
6890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6891
6892 VkImageCreateInfo image_ci = {};
6893 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6894 image_ci.pNext = NULL;
6895 image_ci.imageType = VK_IMAGE_TYPE_2D;
6896 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6897 image_ci.extent.width = 256;
6898 image_ci.extent.height = 256;
6899 image_ci.extent.depth = 1;
6900 image_ci.mipLevels = 1;
6901 image_ci.arrayLayers = 1;
6902 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6903 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06006904 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06006905 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6906 image_ci.flags = 0;
6907 VkImage image;
6908 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
6909
6910 VkMemoryRequirements memory_reqs;
6911 VkDeviceMemory image_memory;
6912 bool pass;
6913 VkMemoryAllocateInfo memory_info = {};
6914 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6915 memory_info.pNext = NULL;
6916 memory_info.allocationSize = 0;
6917 memory_info.memoryTypeIndex = 0;
6918 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6919 memory_info.allocationSize = memory_reqs.size;
6920 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6921 ASSERT_TRUE(pass);
6922 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6923 ASSERT_VK_SUCCESS(err);
6924 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6925 ASSERT_VK_SUCCESS(err);
6926
6927 VkImageViewCreateInfo ivci = {
6928 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6929 nullptr,
6930 0,
6931 image,
6932 VK_IMAGE_VIEW_TYPE_2D,
6933 VK_FORMAT_B8G8R8A8_UNORM,
6934 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
6935 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6936 };
6937 VkImageView view;
6938 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6939 ASSERT_VK_SUCCESS(err);
6940
6941 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
6942 VkFramebuffer fb;
6943 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6944 ASSERT_VK_SUCCESS(err);
6945
6946 // Just use default renderpass with our framebuffer
6947 m_renderPassBeginInfo.framebuffer = fb;
6948 // Create Null cmd buffer for submit
6949 BeginCommandBuffer();
6950 EndCommandBuffer();
6951 // Submit cmd buffer to put it (and attached imageView) in-flight
6952 VkSubmitInfo submit_info = {};
6953 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6954 submit_info.commandBufferCount = 1;
6955 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6956 // Submit cmd buffer to put framebuffer and children in-flight
6957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6958 // Destroy image attached to framebuffer while in-flight
6959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
6960 vkDestroyImage(m_device->device(), image, NULL);
6961 m_errorMonitor->VerifyFound();
6962 // Wait for queue to complete so we can safely destroy image and other objects
6963 vkQueueWaitIdle(m_device->m_queue);
6964 vkDestroyImage(m_device->device(), image, NULL);
6965 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6966 vkDestroyImageView(m_device->device(), view, nullptr);
6967 vkFreeMemory(m_device->device(), image_memory, nullptr);
6968}
6969
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006970TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006971 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006972 ASSERT_NO_FATAL_FAILURE(InitState());
6973
6974 VkImage image;
6975 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6976 VkImageCreateInfo image_create_info = {};
6977 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6978 image_create_info.pNext = NULL;
6979 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6980 image_create_info.format = tex_format;
6981 image_create_info.extent.width = 32;
6982 image_create_info.extent.height = 32;
6983 image_create_info.extent.depth = 1;
6984 image_create_info.mipLevels = 1;
6985 image_create_info.arrayLayers = 1;
6986 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6987 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006988 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006989 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006990 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006991 ASSERT_VK_SUCCESS(err);
6992 // Have to bind memory to image before recording cmd in cmd buffer using it
6993 VkMemoryRequirements mem_reqs;
6994 VkDeviceMemory image_mem;
6995 bool pass;
6996 VkMemoryAllocateInfo mem_alloc = {};
6997 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6998 mem_alloc.pNext = NULL;
6999 mem_alloc.memoryTypeIndex = 0;
7000 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7001 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007003 ASSERT_TRUE(pass);
7004 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7005 ASSERT_VK_SUCCESS(err);
7006
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007007 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
7008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007009 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007010
7011 m_commandBuffer->BeginCommandBuffer();
7012 VkClearColorValue ccv;
7013 ccv.float32[0] = 1.0f;
7014 ccv.float32[1] = 1.0f;
7015 ccv.float32[2] = 1.0f;
7016 ccv.float32[3] = 1.0f;
7017 VkImageSubresourceRange isr = {};
7018 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7019 isr.baseArrayLayer = 0;
7020 isr.baseMipLevel = 0;
7021 isr.layerCount = 1;
7022 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007023 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007024 m_commandBuffer->EndCommandBuffer();
7025
7026 m_errorMonitor->VerifyFound();
7027 vkDestroyImage(m_device->device(), image, NULL);
7028 vkFreeMemory(m_device->device(), image_mem, nullptr);
7029}
7030
7031TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007033 ASSERT_NO_FATAL_FAILURE(InitState());
7034
7035 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007036 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 -06007037 VK_IMAGE_TILING_OPTIMAL, 0);
7038 ASSERT_TRUE(image.initialized());
7039
7040 VkBuffer buffer;
7041 VkDeviceMemory mem;
7042 VkMemoryRequirements mem_reqs;
7043
7044 VkBufferCreateInfo buf_info = {};
7045 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12007046 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007047 buf_info.size = 256;
7048 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7049 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
7050 ASSERT_VK_SUCCESS(err);
7051
7052 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
7053
7054 VkMemoryAllocateInfo alloc_info = {};
7055 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7056 alloc_info.allocationSize = 256;
7057 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007058 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 -06007059 if (!pass) {
7060 vkDestroyBuffer(m_device->device(), buffer, NULL);
7061 return;
7062 }
7063 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
7064 ASSERT_VK_SUCCESS(err);
7065
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007066 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007068 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007069 VkBufferImageCopy region = {};
7070 region.bufferRowLength = 128;
7071 region.bufferImageHeight = 128;
7072 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7073
7074 region.imageSubresource.layerCount = 1;
7075 region.imageExtent.height = 4;
7076 region.imageExtent.width = 4;
7077 region.imageExtent.depth = 1;
7078 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007079 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
7080 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007081 m_commandBuffer->EndCommandBuffer();
7082
7083 m_errorMonitor->VerifyFound();
7084
7085 vkDestroyBuffer(m_device->device(), buffer, NULL);
7086 vkFreeMemory(m_device->handle(), mem, NULL);
7087}
7088
Tobin Ehlis85940f52016-07-07 16:57:21 -06007089TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7090 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7091 "due to an event dependency being destroyed.");
7092 ASSERT_NO_FATAL_FAILURE(InitState());
7093
7094 VkEvent event;
7095 VkEventCreateInfo evci = {};
7096 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7097 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7098 ASSERT_VK_SUCCESS(result);
7099
7100 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007101 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007102 m_commandBuffer->EndCommandBuffer();
7103
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007105 // Destroy event dependency prior to submit to cause ERROR
7106 vkDestroyEvent(m_device->device(), event, NULL);
7107
7108 VkSubmitInfo submit_info = {};
7109 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7110 submit_info.commandBufferCount = 1;
7111 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7112 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7113
7114 m_errorMonitor->VerifyFound();
7115}
7116
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007117TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7118 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7119 "due to a query pool dependency being destroyed.");
7120 ASSERT_NO_FATAL_FAILURE(InitState());
7121
7122 VkQueryPool query_pool;
7123 VkQueryPoolCreateInfo qpci{};
7124 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7125 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7126 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007127 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007128 ASSERT_VK_SUCCESS(result);
7129
7130 m_commandBuffer->BeginCommandBuffer();
7131 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7132 m_commandBuffer->EndCommandBuffer();
7133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007135 // Destroy query pool dependency prior to submit to cause ERROR
7136 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7137
7138 VkSubmitInfo submit_info = {};
7139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7140 submit_info.commandBufferCount = 1;
7141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7143
7144 m_errorMonitor->VerifyFound();
7145}
7146
Tobin Ehlis24130d92016-07-08 15:50:53 -06007147TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7148 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7149 "due to a pipeline dependency being destroyed.");
7150 ASSERT_NO_FATAL_FAILURE(InitState());
7151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7152
7153 VkResult err;
7154
7155 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7156 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7157
7158 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007159 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007160 ASSERT_VK_SUCCESS(err);
7161
7162 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7163 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7164 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007166 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007167 vp_state_ci.scissorCount = 1;
7168 VkRect2D scissors = {}; // Dummy scissors to point to
7169 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007170
7171 VkPipelineShaderStageCreateInfo shaderStages[2];
7172 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7175 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7176 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007177 shaderStages[0] = vs.GetStageCreateInfo();
7178 shaderStages[1] = fs.GetStageCreateInfo();
7179
7180 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7181 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7182
7183 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7184 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7185 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7186
7187 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7188 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12007189 rs_ci.rasterizerDiscardEnable = true;
7190 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007191
7192 VkPipelineColorBlendAttachmentState att = {};
7193 att.blendEnable = VK_FALSE;
7194 att.colorWriteMask = 0xf;
7195
7196 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7197 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7198 cb_ci.attachmentCount = 1;
7199 cb_ci.pAttachments = &att;
7200
7201 VkGraphicsPipelineCreateInfo gp_ci = {};
7202 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7203 gp_ci.stageCount = 2;
7204 gp_ci.pStages = shaderStages;
7205 gp_ci.pVertexInputState = &vi_ci;
7206 gp_ci.pInputAssemblyState = &ia_ci;
7207 gp_ci.pViewportState = &vp_state_ci;
7208 gp_ci.pRasterizationState = &rs_ci;
7209 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007210 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7211 gp_ci.layout = pipeline_layout;
7212 gp_ci.renderPass = renderPass();
7213
7214 VkPipelineCacheCreateInfo pc_ci = {};
7215 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7216
7217 VkPipeline pipeline;
7218 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007219 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007220 ASSERT_VK_SUCCESS(err);
7221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007223 ASSERT_VK_SUCCESS(err);
7224
7225 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007226 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007227 m_commandBuffer->EndCommandBuffer();
7228 // Now destroy pipeline in order to cause error when submitting
7229 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007232
7233 VkSubmitInfo submit_info = {};
7234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7235 submit_info.commandBufferCount = 1;
7236 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7238
7239 m_errorMonitor->VerifyFound();
7240 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7241 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7242}
7243
Tobin Ehlis31289162016-08-17 14:57:58 -06007244TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7245 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7246 "due to a bound descriptor set with a buffer dependency "
7247 "being destroyed.");
7248 ASSERT_NO_FATAL_FAILURE(InitState());
7249 ASSERT_NO_FATAL_FAILURE(InitViewport());
7250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7251
7252 VkDescriptorPoolSize ds_type_count = {};
7253 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7254 ds_type_count.descriptorCount = 1;
7255
7256 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7257 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7258 ds_pool_ci.pNext = NULL;
7259 ds_pool_ci.maxSets = 1;
7260 ds_pool_ci.poolSizeCount = 1;
7261 ds_pool_ci.pPoolSizes = &ds_type_count;
7262
7263 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007264 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007265 ASSERT_VK_SUCCESS(err);
7266
7267 VkDescriptorSetLayoutBinding dsl_binding = {};
7268 dsl_binding.binding = 0;
7269 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7270 dsl_binding.descriptorCount = 1;
7271 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7272 dsl_binding.pImmutableSamplers = NULL;
7273
7274 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7275 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7276 ds_layout_ci.pNext = NULL;
7277 ds_layout_ci.bindingCount = 1;
7278 ds_layout_ci.pBindings = &dsl_binding;
7279 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007280 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007281 ASSERT_VK_SUCCESS(err);
7282
7283 VkDescriptorSet descriptorSet;
7284 VkDescriptorSetAllocateInfo alloc_info = {};
7285 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7286 alloc_info.descriptorSetCount = 1;
7287 alloc_info.descriptorPool = ds_pool;
7288 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007289 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007290 ASSERT_VK_SUCCESS(err);
7291
7292 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7293 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7294 pipeline_layout_ci.pNext = NULL;
7295 pipeline_layout_ci.setLayoutCount = 1;
7296 pipeline_layout_ci.pSetLayouts = &ds_layout;
7297
7298 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007299 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007300 ASSERT_VK_SUCCESS(err);
7301
7302 // Create a buffer to update the descriptor with
7303 uint32_t qfi = 0;
7304 VkBufferCreateInfo buffCI = {};
7305 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7306 buffCI.size = 1024;
7307 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7308 buffCI.queueFamilyIndexCount = 1;
7309 buffCI.pQueueFamilyIndices = &qfi;
7310
7311 VkBuffer buffer;
7312 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7313 ASSERT_VK_SUCCESS(err);
7314 // Allocate memory and bind to buffer so we can make it to the appropriate
7315 // error
7316 VkMemoryAllocateInfo mem_alloc = {};
7317 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7318 mem_alloc.pNext = NULL;
7319 mem_alloc.allocationSize = 1024;
7320 mem_alloc.memoryTypeIndex = 0;
7321
7322 VkMemoryRequirements memReqs;
7323 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007325 if (!pass) {
7326 vkDestroyBuffer(m_device->device(), buffer, NULL);
7327 return;
7328 }
7329
7330 VkDeviceMemory mem;
7331 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7332 ASSERT_VK_SUCCESS(err);
7333 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7334 ASSERT_VK_SUCCESS(err);
7335 // Correctly update descriptor to avoid "NOT_UPDATED" error
7336 VkDescriptorBufferInfo buffInfo = {};
7337 buffInfo.buffer = buffer;
7338 buffInfo.offset = 0;
7339 buffInfo.range = 1024;
7340
7341 VkWriteDescriptorSet descriptor_write;
7342 memset(&descriptor_write, 0, sizeof(descriptor_write));
7343 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7344 descriptor_write.dstSet = descriptorSet;
7345 descriptor_write.dstBinding = 0;
7346 descriptor_write.descriptorCount = 1;
7347 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7348 descriptor_write.pBufferInfo = &buffInfo;
7349
7350 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7351
7352 // Create PSO to be used for draw-time errors below
7353 char const *vsSource = "#version 450\n"
7354 "\n"
7355 "out gl_PerVertex { \n"
7356 " vec4 gl_Position;\n"
7357 "};\n"
7358 "void main(){\n"
7359 " gl_Position = vec4(1);\n"
7360 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007361 char const *fsSource = "#version 450\n"
7362 "\n"
7363 "layout(location=0) out vec4 x;\n"
7364 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7365 "void main(){\n"
7366 " x = vec4(bar.y);\n"
7367 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7370 VkPipelineObj pipe(m_device);
7371 pipe.AddShader(&vs);
7372 pipe.AddShader(&fs);
7373 pipe.AddColorAttachment();
7374 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7375
7376 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007377 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7378 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7379 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007380 Draw(1, 0, 0, 0);
7381 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007383 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7384 vkDestroyBuffer(m_device->device(), buffer, NULL);
7385 // Attempt to submit cmd buffer
7386 VkSubmitInfo submit_info = {};
7387 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7388 submit_info.commandBufferCount = 1;
7389 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7390 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7391 m_errorMonitor->VerifyFound();
7392 // Cleanup
7393 vkFreeMemory(m_device->device(), mem, NULL);
7394
7395 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7396 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7397 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7398}
7399
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007400TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7401 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7402 "due to a bound descriptor sets with a combined image "
7403 "sampler having their image, sampler, and descriptor set "
7404 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007405 "submit associated cmd buffers. Attempt to destroy a "
7406 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007407 ASSERT_NO_FATAL_FAILURE(InitState());
7408 ASSERT_NO_FATAL_FAILURE(InitViewport());
7409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7410
7411 VkDescriptorPoolSize ds_type_count = {};
7412 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7413 ds_type_count.descriptorCount = 1;
7414
7415 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7416 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7417 ds_pool_ci.pNext = NULL;
7418 ds_pool_ci.maxSets = 1;
7419 ds_pool_ci.poolSizeCount = 1;
7420 ds_pool_ci.pPoolSizes = &ds_type_count;
7421
7422 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007424 ASSERT_VK_SUCCESS(err);
7425
7426 VkDescriptorSetLayoutBinding dsl_binding = {};
7427 dsl_binding.binding = 0;
7428 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7429 dsl_binding.descriptorCount = 1;
7430 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7431 dsl_binding.pImmutableSamplers = NULL;
7432
7433 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7434 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7435 ds_layout_ci.pNext = NULL;
7436 ds_layout_ci.bindingCount = 1;
7437 ds_layout_ci.pBindings = &dsl_binding;
7438 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007440 ASSERT_VK_SUCCESS(err);
7441
7442 VkDescriptorSet descriptorSet;
7443 VkDescriptorSetAllocateInfo alloc_info = {};
7444 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7445 alloc_info.descriptorSetCount = 1;
7446 alloc_info.descriptorPool = ds_pool;
7447 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007449 ASSERT_VK_SUCCESS(err);
7450
7451 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7452 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7453 pipeline_layout_ci.pNext = NULL;
7454 pipeline_layout_ci.setLayoutCount = 1;
7455 pipeline_layout_ci.pSetLayouts = &ds_layout;
7456
7457 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007458 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007459 ASSERT_VK_SUCCESS(err);
7460
7461 // Create images to update the descriptor with
7462 VkImage image;
7463 VkImage image2;
7464 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7465 const int32_t tex_width = 32;
7466 const int32_t tex_height = 32;
7467 VkImageCreateInfo image_create_info = {};
7468 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7469 image_create_info.pNext = NULL;
7470 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7471 image_create_info.format = tex_format;
7472 image_create_info.extent.width = tex_width;
7473 image_create_info.extent.height = tex_height;
7474 image_create_info.extent.depth = 1;
7475 image_create_info.mipLevels = 1;
7476 image_create_info.arrayLayers = 1;
7477 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7478 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7479 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7480 image_create_info.flags = 0;
7481 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7482 ASSERT_VK_SUCCESS(err);
7483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7484 ASSERT_VK_SUCCESS(err);
7485
7486 VkMemoryRequirements memory_reqs;
7487 VkDeviceMemory image_memory;
7488 bool pass;
7489 VkMemoryAllocateInfo memory_info = {};
7490 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7491 memory_info.pNext = NULL;
7492 memory_info.allocationSize = 0;
7493 memory_info.memoryTypeIndex = 0;
7494 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7495 // Allocate enough memory for both images
7496 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007498 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007499 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007500 ASSERT_VK_SUCCESS(err);
7501 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7502 ASSERT_VK_SUCCESS(err);
7503 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007504 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007505 ASSERT_VK_SUCCESS(err);
7506
7507 VkImageViewCreateInfo image_view_create_info = {};
7508 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7509 image_view_create_info.image = image;
7510 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7511 image_view_create_info.format = tex_format;
7512 image_view_create_info.subresourceRange.layerCount = 1;
7513 image_view_create_info.subresourceRange.baseMipLevel = 0;
7514 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007515 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007516
7517 VkImageView view;
7518 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007519 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007520 ASSERT_VK_SUCCESS(err);
7521 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007522 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007523 ASSERT_VK_SUCCESS(err);
7524 // Create Samplers
7525 VkSamplerCreateInfo sampler_ci = {};
7526 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7527 sampler_ci.pNext = NULL;
7528 sampler_ci.magFilter = VK_FILTER_NEAREST;
7529 sampler_ci.minFilter = VK_FILTER_NEAREST;
7530 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7531 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7532 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7533 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7534 sampler_ci.mipLodBias = 1.0;
7535 sampler_ci.anisotropyEnable = VK_FALSE;
7536 sampler_ci.maxAnisotropy = 1;
7537 sampler_ci.compareEnable = VK_FALSE;
7538 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7539 sampler_ci.minLod = 1.0;
7540 sampler_ci.maxLod = 1.0;
7541 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7542 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7543 VkSampler sampler;
7544 VkSampler sampler2;
7545 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7546 ASSERT_VK_SUCCESS(err);
7547 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7548 ASSERT_VK_SUCCESS(err);
7549 // Update descriptor with image and sampler
7550 VkDescriptorImageInfo img_info = {};
7551 img_info.sampler = sampler;
7552 img_info.imageView = view;
7553 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7554
7555 VkWriteDescriptorSet descriptor_write;
7556 memset(&descriptor_write, 0, sizeof(descriptor_write));
7557 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7558 descriptor_write.dstSet = descriptorSet;
7559 descriptor_write.dstBinding = 0;
7560 descriptor_write.descriptorCount = 1;
7561 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7562 descriptor_write.pImageInfo = &img_info;
7563
7564 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7565
7566 // Create PSO to be used for draw-time errors below
7567 char const *vsSource = "#version 450\n"
7568 "\n"
7569 "out gl_PerVertex { \n"
7570 " vec4 gl_Position;\n"
7571 "};\n"
7572 "void main(){\n"
7573 " gl_Position = vec4(1);\n"
7574 "}\n";
7575 char const *fsSource = "#version 450\n"
7576 "\n"
7577 "layout(set=0, binding=0) uniform sampler2D s;\n"
7578 "layout(location=0) out vec4 x;\n"
7579 "void main(){\n"
7580 " x = texture(s, vec2(1));\n"
7581 "}\n";
7582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7584 VkPipelineObj pipe(m_device);
7585 pipe.AddShader(&vs);
7586 pipe.AddShader(&fs);
7587 pipe.AddColorAttachment();
7588 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7589
7590 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007592 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007593 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7594 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7595 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007596 Draw(1, 0, 0, 0);
7597 EndCommandBuffer();
7598 // Destroy sampler invalidates the cmd buffer, causing error on submit
7599 vkDestroySampler(m_device->device(), sampler, NULL);
7600 // Attempt to submit cmd buffer
7601 VkSubmitInfo submit_info = {};
7602 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7603 submit_info.commandBufferCount = 1;
7604 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7605 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7606 m_errorMonitor->VerifyFound();
7607 // Now re-update descriptor with valid sampler and delete image
7608 img_info.sampler = sampler2;
7609 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007611 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007612 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7613 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7614 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007615 Draw(1, 0, 0, 0);
7616 EndCommandBuffer();
7617 // Destroy image invalidates the cmd buffer, causing error on submit
7618 vkDestroyImage(m_device->device(), image, NULL);
7619 // Attempt to submit cmd buffer
7620 submit_info = {};
7621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7622 submit_info.commandBufferCount = 1;
7623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7625 m_errorMonitor->VerifyFound();
7626 // Now update descriptor to be valid, but then free descriptor
7627 img_info.imageView = view2;
7628 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007630 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007631 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7632 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7633 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007634 Draw(1, 0, 0, 0);
7635 EndCommandBuffer();
7636 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007638 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007639 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007640 // Attempt to submit cmd buffer
7641 submit_info = {};
7642 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7643 submit_info.commandBufferCount = 1;
7644 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7645 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7646 m_errorMonitor->VerifyFound();
7647 // Cleanup
7648 vkFreeMemory(m_device->device(), image_memory, NULL);
7649 vkDestroySampler(m_device->device(), sampler2, NULL);
7650 vkDestroyImage(m_device->device(), image2, NULL);
7651 vkDestroyImageView(m_device->device(), view, NULL);
7652 vkDestroyImageView(m_device->device(), view2, NULL);
7653 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7656}
7657
Tobin Ehlis50a095d2016-09-21 17:32:49 -06007658TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
7659 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
7660 ASSERT_NO_FATAL_FAILURE(InitState());
7661 ASSERT_NO_FATAL_FAILURE(InitViewport());
7662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7663
7664 VkDescriptorPoolSize ds_type_count = {};
7665 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7666 ds_type_count.descriptorCount = 1;
7667
7668 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7669 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7670 ds_pool_ci.pNext = NULL;
7671 ds_pool_ci.maxSets = 1;
7672 ds_pool_ci.poolSizeCount = 1;
7673 ds_pool_ci.pPoolSizes = &ds_type_count;
7674
7675 VkDescriptorPool ds_pool;
7676 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7677 ASSERT_VK_SUCCESS(err);
7678
7679 VkDescriptorSetLayoutBinding dsl_binding = {};
7680 dsl_binding.binding = 0;
7681 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7682 dsl_binding.descriptorCount = 1;
7683 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7684 dsl_binding.pImmutableSamplers = NULL;
7685
7686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7688 ds_layout_ci.pNext = NULL;
7689 ds_layout_ci.bindingCount = 1;
7690 ds_layout_ci.pBindings = &dsl_binding;
7691 VkDescriptorSetLayout ds_layout;
7692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
7693 ASSERT_VK_SUCCESS(err);
7694
7695 VkDescriptorSet descriptorSet;
7696 VkDescriptorSetAllocateInfo alloc_info = {};
7697 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7698 alloc_info.descriptorSetCount = 1;
7699 alloc_info.descriptorPool = ds_pool;
7700 alloc_info.pSetLayouts = &ds_layout;
7701 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
7702 ASSERT_VK_SUCCESS(err);
7703
7704 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7705 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7706 pipeline_layout_ci.pNext = NULL;
7707 pipeline_layout_ci.setLayoutCount = 1;
7708 pipeline_layout_ci.pSetLayouts = &ds_layout;
7709
7710 VkPipelineLayout pipeline_layout;
7711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
7712 ASSERT_VK_SUCCESS(err);
7713
7714 // Create images to update the descriptor with
7715 VkImage image;
7716 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7717 const int32_t tex_width = 32;
7718 const int32_t tex_height = 32;
7719 VkImageCreateInfo image_create_info = {};
7720 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7721 image_create_info.pNext = NULL;
7722 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7723 image_create_info.format = tex_format;
7724 image_create_info.extent.width = tex_width;
7725 image_create_info.extent.height = tex_height;
7726 image_create_info.extent.depth = 1;
7727 image_create_info.mipLevels = 1;
7728 image_create_info.arrayLayers = 1;
7729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7730 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7731 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7732 image_create_info.flags = 0;
7733 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7734 ASSERT_VK_SUCCESS(err);
7735 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
7736 VkMemoryRequirements memory_reqs;
7737 VkDeviceMemory image_memory;
7738 bool pass;
7739 VkMemoryAllocateInfo memory_info = {};
7740 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7741 memory_info.pNext = NULL;
7742 memory_info.allocationSize = 0;
7743 memory_info.memoryTypeIndex = 0;
7744 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7745 // Allocate enough memory for image
7746 memory_info.allocationSize = memory_reqs.size;
7747 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
7748 ASSERT_TRUE(pass);
7749 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
7750 ASSERT_VK_SUCCESS(err);
7751 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7752 ASSERT_VK_SUCCESS(err);
7753
7754 VkImageViewCreateInfo image_view_create_info = {};
7755 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7756 image_view_create_info.image = image;
7757 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7758 image_view_create_info.format = tex_format;
7759 image_view_create_info.subresourceRange.layerCount = 1;
7760 image_view_create_info.subresourceRange.baseMipLevel = 0;
7761 image_view_create_info.subresourceRange.levelCount = 1;
7762 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7763
7764 VkImageView view;
7765 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
7766 ASSERT_VK_SUCCESS(err);
7767 // Create Samplers
7768 VkSamplerCreateInfo sampler_ci = {};
7769 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7770 sampler_ci.pNext = NULL;
7771 sampler_ci.magFilter = VK_FILTER_NEAREST;
7772 sampler_ci.minFilter = VK_FILTER_NEAREST;
7773 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7774 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7775 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7776 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7777 sampler_ci.mipLodBias = 1.0;
7778 sampler_ci.anisotropyEnable = VK_FALSE;
7779 sampler_ci.maxAnisotropy = 1;
7780 sampler_ci.compareEnable = VK_FALSE;
7781 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7782 sampler_ci.minLod = 1.0;
7783 sampler_ci.maxLod = 1.0;
7784 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7785 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7786 VkSampler sampler;
7787 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7788 ASSERT_VK_SUCCESS(err);
7789 // Update descriptor with image and sampler
7790 VkDescriptorImageInfo img_info = {};
7791 img_info.sampler = sampler;
7792 img_info.imageView = view;
7793 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7794
7795 VkWriteDescriptorSet descriptor_write;
7796 memset(&descriptor_write, 0, sizeof(descriptor_write));
7797 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7798 descriptor_write.dstSet = descriptorSet;
7799 descriptor_write.dstBinding = 0;
7800 descriptor_write.descriptorCount = 1;
7801 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7802 descriptor_write.pImageInfo = &img_info;
7803 // Break memory binding and attempt update
7804 vkFreeMemory(m_device->device(), image_memory, nullptr);
7805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007806 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06007807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7808 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
7809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7810 m_errorMonitor->VerifyFound();
7811 // Cleanup
7812 vkDestroyImage(m_device->device(), image, NULL);
7813 vkDestroySampler(m_device->device(), sampler, NULL);
7814 vkDestroyImageView(m_device->device(), view, NULL);
7815 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7816 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7817 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7818}
7819
Karl Schultz6addd812016-02-02 17:17:23 -07007820TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007821 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7822 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007823 // Create a valid cmd buffer
7824 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007825 uint64_t fake_pipeline_handle = 0xbaad6001;
7826 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06007827 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7829
7830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007831 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007832 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007833 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007834
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007835 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 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 -06007837 Draw(1, 0, 0, 0);
7838 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007839
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007840 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007841 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 +12007842 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007843 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7844 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007845}
7846
Karl Schultz6addd812016-02-02 17:17:23 -07007847TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007848 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007849 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007852
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007853 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007854 ASSERT_NO_FATAL_FAILURE(InitViewport());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007856 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007857 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7858 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007859
7860 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007861 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7862 ds_pool_ci.pNext = NULL;
7863 ds_pool_ci.maxSets = 1;
7864 ds_pool_ci.poolSizeCount = 1;
7865 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007866
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007869 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007870
Tony Barboureb254902015-07-15 12:50:33 -06007871 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 dsl_binding.binding = 0;
7873 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7874 dsl_binding.descriptorCount = 1;
7875 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7876 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007877
Tony Barboureb254902015-07-15 12:50:33 -06007878 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007879 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7880 ds_layout_ci.pNext = NULL;
7881 ds_layout_ci.bindingCount = 1;
7882 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007883 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007885 ASSERT_VK_SUCCESS(err);
7886
7887 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007888 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007890 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007891 alloc_info.descriptorPool = ds_pool;
7892 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007893 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007894 ASSERT_VK_SUCCESS(err);
7895
Tony Barboureb254902015-07-15 12:50:33 -06007896 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007897 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7898 pipeline_layout_ci.pNext = NULL;
7899 pipeline_layout_ci.setLayoutCount = 1;
7900 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007901
7902 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007903 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007904 ASSERT_VK_SUCCESS(err);
7905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007906 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007907 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007908 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007910
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007911 VkPipelineObj pipe(m_device);
7912 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007913 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007914 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007915 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007916
7917 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007918 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7919 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7920 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007922 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007923
Chia-I Wuf7458c52015-10-26 21:10:41 +08007924 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7925 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7926 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007927}
7928
Karl Schultz6addd812016-02-02 17:17:23 -07007929TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007930 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007931 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7934 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007935
7936 ASSERT_NO_FATAL_FAILURE(InitState());
7937 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007938 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7939 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007940
7941 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007942 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7943 ds_pool_ci.pNext = NULL;
7944 ds_pool_ci.maxSets = 1;
7945 ds_pool_ci.poolSizeCount = 1;
7946 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007947
7948 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007950 ASSERT_VK_SUCCESS(err);
7951
7952 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007953 dsl_binding.binding = 0;
7954 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7955 dsl_binding.descriptorCount = 1;
7956 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7957 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007958
7959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7961 ds_layout_ci.pNext = NULL;
7962 ds_layout_ci.bindingCount = 1;
7963 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007964 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007966 ASSERT_VK_SUCCESS(err);
7967
7968 VkDescriptorSet descriptorSet;
7969 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007971 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007972 alloc_info.descriptorPool = ds_pool;
7973 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007975 ASSERT_VK_SUCCESS(err);
7976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007978 VkWriteDescriptorSet descriptor_write;
7979 memset(&descriptor_write, 0, sizeof(descriptor_write));
7980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7981 descriptor_write.dstSet = descriptorSet;
7982 descriptor_write.dstBinding = 0;
7983 descriptor_write.descriptorCount = 1;
7984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7985 descriptor_write.pTexelBufferView = &view;
7986
7987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7988
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007989 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007990
7991 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7992 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7993}
7994
Mark Youngd339ba32016-05-30 13:28:35 -06007995TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007996 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 -06007997
7998 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06008000 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06008001
8002 ASSERT_NO_FATAL_FAILURE(InitState());
8003
8004 // Create a buffer with no bound memory and then attempt to create
8005 // a buffer view.
8006 VkBufferCreateInfo buff_ci = {};
8007 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12008008 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06008009 buff_ci.size = 256;
8010 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8011 VkBuffer buffer;
8012 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8013 ASSERT_VK_SUCCESS(err);
8014
8015 VkBufferViewCreateInfo buff_view_ci = {};
8016 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8017 buff_view_ci.buffer = buffer;
8018 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8019 buff_view_ci.range = VK_WHOLE_SIZE;
8020 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06008022
8023 m_errorMonitor->VerifyFound();
8024 vkDestroyBuffer(m_device->device(), buffer, NULL);
8025 // If last error is success, it still created the view, so delete it.
8026 if (err == VK_SUCCESS) {
8027 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8028 }
8029}
8030
Karl Schultz6addd812016-02-02 17:17:23 -07008031TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
8032 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
8033 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07008034 // 1. No dynamicOffset supplied
8035 // 2. Too many dynamicOffsets supplied
8036 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07008037 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
8039 "0 dynamicOffsets are left in "
8040 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008041
8042 ASSERT_NO_FATAL_FAILURE(InitState());
8043 ASSERT_NO_FATAL_FAILURE(InitViewport());
8044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8045
8046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8048 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008049
8050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8052 ds_pool_ci.pNext = NULL;
8053 ds_pool_ci.maxSets = 1;
8054 ds_pool_ci.poolSizeCount = 1;
8055 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008056
8057 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008059 ASSERT_VK_SUCCESS(err);
8060
8061 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008062 dsl_binding.binding = 0;
8063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8064 dsl_binding.descriptorCount = 1;
8065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8066 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008067
8068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8070 ds_layout_ci.pNext = NULL;
8071 ds_layout_ci.bindingCount = 1;
8072 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008073 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008074 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008075 ASSERT_VK_SUCCESS(err);
8076
8077 VkDescriptorSet descriptorSet;
8078 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008080 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008081 alloc_info.descriptorPool = ds_pool;
8082 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008083 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008084 ASSERT_VK_SUCCESS(err);
8085
8086 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008087 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8088 pipeline_layout_ci.pNext = NULL;
8089 pipeline_layout_ci.setLayoutCount = 1;
8090 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008091
8092 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008094 ASSERT_VK_SUCCESS(err);
8095
8096 // Create a buffer to update the descriptor with
8097 uint32_t qfi = 0;
8098 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008099 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8100 buffCI.size = 1024;
8101 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8102 buffCI.queueFamilyIndexCount = 1;
8103 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008104
8105 VkBuffer dyub;
8106 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8107 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008108 // Allocate memory and bind to buffer so we can make it to the appropriate
8109 // error
8110 VkMemoryAllocateInfo mem_alloc = {};
8111 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8112 mem_alloc.pNext = NULL;
8113 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12008114 mem_alloc.memoryTypeIndex = 0;
8115
8116 VkMemoryRequirements memReqs;
8117 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008118 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12008119 if (!pass) {
8120 vkDestroyBuffer(m_device->device(), dyub, NULL);
8121 return;
8122 }
8123
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008124 VkDeviceMemory mem;
8125 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8126 ASSERT_VK_SUCCESS(err);
8127 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
8128 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008129 // Correctly update descriptor to avoid "NOT_UPDATED" error
8130 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008131 buffInfo.buffer = dyub;
8132 buffInfo.offset = 0;
8133 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008134
8135 VkWriteDescriptorSet descriptor_write;
8136 memset(&descriptor_write, 0, sizeof(descriptor_write));
8137 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8138 descriptor_write.dstSet = descriptorSet;
8139 descriptor_write.dstBinding = 0;
8140 descriptor_write.descriptorCount = 1;
8141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8142 descriptor_write.pBufferInfo = &buffInfo;
8143
8144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8145
8146 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008147 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8148 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008149 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07008150 uint32_t pDynOff[2] = {512, 756};
8151 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8153 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
8154 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8155 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12008156 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07008157 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
8159 "offset 0 and range 1024 that "
8160 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07008161 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 char const *vsSource = "#version 450\n"
8163 "\n"
8164 "out gl_PerVertex { \n"
8165 " vec4 gl_Position;\n"
8166 "};\n"
8167 "void main(){\n"
8168 " gl_Position = vec4(1);\n"
8169 "}\n";
8170 char const *fsSource = "#version 450\n"
8171 "\n"
8172 "layout(location=0) out vec4 x;\n"
8173 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8174 "void main(){\n"
8175 " x = vec4(bar.y);\n"
8176 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07008177 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8178 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8179 VkPipelineObj pipe(m_device);
8180 pipe.AddShader(&vs);
8181 pipe.AddShader(&fs);
8182 pipe.AddColorAttachment();
8183 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008186 // This update should succeed, but offset size of 512 will overstep buffer
8187 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8189 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07008190 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008191 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008192
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008193 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06008194 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008195
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008196 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008198 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8199}
8200
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008201TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
8202 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
8203 "that doesn't have memory bound");
8204 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06008206 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8208 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008209
8210 ASSERT_NO_FATAL_FAILURE(InitState());
8211 ASSERT_NO_FATAL_FAILURE(InitViewport());
8212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8213
8214 VkDescriptorPoolSize ds_type_count = {};
8215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8216 ds_type_count.descriptorCount = 1;
8217
8218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8220 ds_pool_ci.pNext = NULL;
8221 ds_pool_ci.maxSets = 1;
8222 ds_pool_ci.poolSizeCount = 1;
8223 ds_pool_ci.pPoolSizes = &ds_type_count;
8224
8225 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008226 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008227 ASSERT_VK_SUCCESS(err);
8228
8229 VkDescriptorSetLayoutBinding dsl_binding = {};
8230 dsl_binding.binding = 0;
8231 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8232 dsl_binding.descriptorCount = 1;
8233 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8234 dsl_binding.pImmutableSamplers = NULL;
8235
8236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8238 ds_layout_ci.pNext = NULL;
8239 ds_layout_ci.bindingCount = 1;
8240 ds_layout_ci.pBindings = &dsl_binding;
8241 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008243 ASSERT_VK_SUCCESS(err);
8244
8245 VkDescriptorSet descriptorSet;
8246 VkDescriptorSetAllocateInfo alloc_info = {};
8247 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8248 alloc_info.descriptorSetCount = 1;
8249 alloc_info.descriptorPool = ds_pool;
8250 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008252 ASSERT_VK_SUCCESS(err);
8253
8254 // Create a buffer to update the descriptor with
8255 uint32_t qfi = 0;
8256 VkBufferCreateInfo buffCI = {};
8257 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8258 buffCI.size = 1024;
8259 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8260 buffCI.queueFamilyIndexCount = 1;
8261 buffCI.pQueueFamilyIndices = &qfi;
8262
8263 VkBuffer dyub;
8264 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8265 ASSERT_VK_SUCCESS(err);
8266
8267 // Attempt to update descriptor without binding memory to it
8268 VkDescriptorBufferInfo buffInfo = {};
8269 buffInfo.buffer = dyub;
8270 buffInfo.offset = 0;
8271 buffInfo.range = 1024;
8272
8273 VkWriteDescriptorSet descriptor_write;
8274 memset(&descriptor_write, 0, sizeof(descriptor_write));
8275 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8276 descriptor_write.dstSet = descriptorSet;
8277 descriptor_write.dstBinding = 0;
8278 descriptor_write.descriptorCount = 1;
8279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8280 descriptor_write.pBufferInfo = &buffInfo;
8281
8282 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8283 m_errorMonitor->VerifyFound();
8284
8285 vkDestroyBuffer(m_device->device(), dyub, NULL);
8286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8288}
8289
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008290TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008291 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008292 ASSERT_NO_FATAL_FAILURE(InitState());
8293 ASSERT_NO_FATAL_FAILURE(InitViewport());
8294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8295
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008296 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008297 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008298 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8299 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8300 pipeline_layout_ci.pushConstantRangeCount = 1;
8301 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8302
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008303 //
8304 // Check for invalid push constant ranges in pipeline layouts.
8305 //
8306 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008307 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008308 char const *msg;
8309 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008310
Karl Schultzc81037d2016-05-12 08:11:23 -06008311 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8312 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8313 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8314 "vkCreatePipelineLayout() call has push constants index 0 with "
8315 "size 0."},
8316 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8317 "vkCreatePipelineLayout() call has push constants index 0 with "
8318 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008319 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008320 "vkCreatePipelineLayout() call has push constants index 0 with "
8321 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008322 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008323 "vkCreatePipelineLayout() call has push constants index 0 with "
8324 "size 0."},
8325 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8326 "vkCreatePipelineLayout() call has push constants index 0 with "
8327 "offset 1. Offset must"},
8328 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8329 "vkCreatePipelineLayout() call has push constants index 0 "
8330 "with offset "},
8331 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8332 "vkCreatePipelineLayout() call has push constants "
8333 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008334 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008335 "vkCreatePipelineLayout() call has push constants index 0 "
8336 "with offset "},
8337 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8338 "vkCreatePipelineLayout() call has push "
8339 "constants index 0 with offset "},
8340 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8341 "vkCreatePipelineLayout() call has push "
8342 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008343 }};
8344
8345 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008346 for (const auto &iter : range_tests) {
8347 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8349 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008350 m_errorMonitor->VerifyFound();
8351 if (VK_SUCCESS == err) {
8352 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8353 }
8354 }
8355
8356 // Check for invalid stage flag
8357 pc_range.offset = 0;
8358 pc_range.size = 16;
8359 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008360 m_errorMonitor->SetDesiredFailureMsg(
8361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8362 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008364 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008365 if (VK_SUCCESS == err) {
8366 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8367 }
8368
8369 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008370 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008371 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008372 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008373 char const *msg;
8374 };
8375
Karl Schultzc81037d2016-05-12 08:11:23 -06008376 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008377 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8378 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8379 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8380 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8381 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008382 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008383 {
8384 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8385 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8386 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8387 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8388 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008389 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008390 },
8391 {
8392 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8393 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8394 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8395 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8396 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008397 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008398 },
8399 {
8400 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8401 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8402 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8403 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8404 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008405 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008406 },
8407 {
8408 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8409 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8410 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8411 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8412 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008413 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008414 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008415
Karl Schultzc81037d2016-05-12 08:11:23 -06008416 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008417 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008418 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008421 m_errorMonitor->VerifyFound();
8422 if (VK_SUCCESS == err) {
8423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8424 }
8425 }
8426
8427 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008428 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8429 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8430 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8431 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8432 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8433 ""},
8434 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8435 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8436 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8437 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8438 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8439 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008440 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008441 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8442 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008444 m_errorMonitor->VerifyNotFound();
8445 if (VK_SUCCESS == err) {
8446 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8447 }
8448 }
8449
8450 //
8451 // CmdPushConstants tests
8452 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008453 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008454
8455 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008456 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8457 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008458 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8459 "vkCmdPushConstants() call has push constants with size 1. Size "
8460 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008461 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008462 "vkCmdPushConstants() call has push constants with size 1. Size "
8463 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008464 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008465 "vkCmdPushConstants() call has push constants with offset 1. "
8466 "Offset must be a multiple of 4."},
8467 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8468 "vkCmdPushConstants() call has push constants with offset 1. "
8469 "Offset must be a multiple of 4."},
8470 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8471 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8472 "0x1 not within flag-matching ranges in pipeline layout"},
8473 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8474 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8475 "0x1 not within flag-matching ranges in pipeline layout"},
8476 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8477 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8478 "0x1 not within flag-matching ranges in pipeline layout"},
8479 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8480 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8481 "0x1 not within flag-matching ranges in pipeline layout"},
8482 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8483 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8484 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008485 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008486 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8487 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008488 }};
8489
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008490 BeginCommandBuffer();
8491
8492 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008493 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008495 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008497 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008499 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008500 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8502 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008503 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008504 m_errorMonitor->VerifyFound();
8505 }
8506
8507 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008510 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008511 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008512
Karl Schultzc81037d2016-05-12 08:11:23 -06008513 // overlapping range tests with cmd
8514 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8515 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8516 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8517 "0x1 not within flag-matching ranges in pipeline layout"},
8518 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8519 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8520 "0x1 not within flag-matching ranges in pipeline layout"},
8521 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8522 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8523 "0x1 not within flag-matching ranges in pipeline layout"},
8524 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008525 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008526 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008527 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8528 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008529 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008531 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008532 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008533 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008534 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8536 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008537 iter.range.size, dummy_values);
8538 m_errorMonitor->VerifyFound();
8539 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8541
8542 // positive overlapping range tests with cmd
8543 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8544 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8545 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8546 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8547 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8548 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008549 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008550 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008551 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8552 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Karl Schultzc81037d2016-05-12 08:11:23 -06008553 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008554 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008555 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008557 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008558 for (const auto &iter : cmd_overlap_tests_pos) {
8559 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008560 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008561 iter.range.size, dummy_values);
8562 m_errorMonitor->VerifyNotFound();
8563 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008564 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008565
8566 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008567}
8568
Karl Schultz6addd812016-02-02 17:17:23 -07008569TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008570 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008571 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008572
8573 ASSERT_NO_FATAL_FAILURE(InitState());
8574 ASSERT_NO_FATAL_FAILURE(InitViewport());
8575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8576
Mike Stroyanb8a61002016-06-20 16:00:28 -06008577 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8578 VkImageTiling tiling;
8579 VkFormatProperties format_properties;
8580 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008581 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008582 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008583 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008584 tiling = VK_IMAGE_TILING_OPTIMAL;
8585 } else {
8586 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8587 "skipped.\n");
8588 return;
8589 }
8590
Tobin Ehlis559c6382015-11-05 09:52:49 -07008591 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8592 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008593 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8594 ds_type_count[0].descriptorCount = 10;
8595 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8596 ds_type_count[1].descriptorCount = 2;
8597 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8598 ds_type_count[2].descriptorCount = 2;
8599 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8600 ds_type_count[3].descriptorCount = 5;
8601 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8602 // type
8603 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8604 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8605 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008606
8607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8609 ds_pool_ci.pNext = NULL;
8610 ds_pool_ci.maxSets = 5;
8611 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8612 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008613
8614 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008615 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008616 ASSERT_VK_SUCCESS(err);
8617
8618 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8619 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008620 dsl_binding[0].binding = 0;
8621 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8622 dsl_binding[0].descriptorCount = 5;
8623 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8624 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008625
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008626 // Create layout identical to set0 layout but w/ different stageFlags
8627 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008628 dsl_fs_stage_only.binding = 0;
8629 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8630 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008631 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8632 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008633 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8636 ds_layout_ci.pNext = NULL;
8637 ds_layout_ci.bindingCount = 1;
8638 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008639 static const uint32_t NUM_LAYOUTS = 4;
8640 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008641 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008642 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8643 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008645 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008646 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008648 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008649 dsl_binding[0].binding = 0;
8650 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008651 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008652 dsl_binding[1].binding = 1;
8653 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8654 dsl_binding[1].descriptorCount = 2;
8655 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8656 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008657 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008658 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008659 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008660 ASSERT_VK_SUCCESS(err);
8661 dsl_binding[0].binding = 0;
8662 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008663 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008664 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008666 ASSERT_VK_SUCCESS(err);
8667 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008668 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008670 ASSERT_VK_SUCCESS(err);
8671
8672 static const uint32_t NUM_SETS = 4;
8673 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8674 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008676 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008677 alloc_info.descriptorPool = ds_pool;
8678 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008680 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008681 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008682 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008683 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008685 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008686
8687 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008688 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8689 pipeline_layout_ci.pNext = NULL;
8690 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8691 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008692
8693 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008695 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008696 // Create pipelineLayout with only one setLayout
8697 pipeline_layout_ci.setLayoutCount = 1;
8698 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008700 ASSERT_VK_SUCCESS(err);
8701 // Create pipelineLayout with 2 descriptor setLayout at index 0
8702 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8703 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008704 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008705 ASSERT_VK_SUCCESS(err);
8706 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8707 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8708 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008709 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008710 ASSERT_VK_SUCCESS(err);
8711 // Create pipelineLayout with UB type, but stageFlags for FS only
8712 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8713 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008715 ASSERT_VK_SUCCESS(err);
8716 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8717 VkDescriptorSetLayout pl_bad_s0[2] = {};
8718 pl_bad_s0[0] = ds_layout_fs_only;
8719 pl_bad_s0[1] = ds_layout[1];
8720 pipeline_layout_ci.setLayoutCount = 2;
8721 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8722 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008724 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008725
8726 // Create a buffer to update the descriptor with
8727 uint32_t qfi = 0;
8728 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008729 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8730 buffCI.size = 1024;
8731 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8732 buffCI.queueFamilyIndexCount = 1;
8733 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008734
8735 VkBuffer dyub;
8736 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8737 ASSERT_VK_SUCCESS(err);
8738 // Correctly update descriptor to avoid "NOT_UPDATED" error
8739 static const uint32_t NUM_BUFFS = 5;
8740 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008741 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008742 buffInfo[i].buffer = dyub;
8743 buffInfo[i].offset = 0;
8744 buffInfo[i].range = 1024;
8745 }
Karl Schultz6addd812016-02-02 17:17:23 -07008746 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008747 const int32_t tex_width = 32;
8748 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008749 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008750 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8751 image_create_info.pNext = NULL;
8752 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8753 image_create_info.format = tex_format;
8754 image_create_info.extent.width = tex_width;
8755 image_create_info.extent.height = tex_height;
8756 image_create_info.extent.depth = 1;
8757 image_create_info.mipLevels = 1;
8758 image_create_info.arrayLayers = 1;
8759 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008760 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008761 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008762 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8764 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008765
Karl Schultz6addd812016-02-02 17:17:23 -07008766 VkMemoryRequirements memReqs;
8767 VkDeviceMemory imageMem;
8768 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008769 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008770 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8771 memAlloc.pNext = NULL;
8772 memAlloc.allocationSize = 0;
8773 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008774 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8775 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008777 ASSERT_TRUE(pass);
8778 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8779 ASSERT_VK_SUCCESS(err);
8780 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8781 ASSERT_VK_SUCCESS(err);
8782
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008783 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008784 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8785 image_view_create_info.image = image;
8786 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8787 image_view_create_info.format = tex_format;
8788 image_view_create_info.subresourceRange.layerCount = 1;
8789 image_view_create_info.subresourceRange.baseMipLevel = 0;
8790 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008792
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008793 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008794 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008796 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008797 imageInfo[0].imageView = view;
8798 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8799 imageInfo[1].imageView = view;
8800 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008801 imageInfo[2].imageView = view;
8802 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8803 imageInfo[3].imageView = view;
8804 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008805
8806 static const uint32_t NUM_SET_UPDATES = 3;
8807 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8808 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8809 descriptor_write[0].dstSet = descriptorSet[0];
8810 descriptor_write[0].dstBinding = 0;
8811 descriptor_write[0].descriptorCount = 5;
8812 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8813 descriptor_write[0].pBufferInfo = buffInfo;
8814 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8815 descriptor_write[1].dstSet = descriptorSet[1];
8816 descriptor_write[1].dstBinding = 0;
8817 descriptor_write[1].descriptorCount = 2;
8818 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8819 descriptor_write[1].pImageInfo = imageInfo;
8820 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8821 descriptor_write[2].dstSet = descriptorSet[1];
8822 descriptor_write[2].dstBinding = 1;
8823 descriptor_write[2].descriptorCount = 2;
8824 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008825 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008826
8827 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008828
Tobin Ehlis88452832015-12-03 09:40:56 -07008829 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 char const *vsSource = "#version 450\n"
8831 "\n"
8832 "out gl_PerVertex {\n"
8833 " vec4 gl_Position;\n"
8834 "};\n"
8835 "void main(){\n"
8836 " gl_Position = vec4(1);\n"
8837 "}\n";
8838 char const *fsSource = "#version 450\n"
8839 "\n"
8840 "layout(location=0) out vec4 x;\n"
8841 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8842 "void main(){\n"
8843 " x = vec4(bar.y);\n"
8844 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008845 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8846 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008847 VkPipelineObj pipe(m_device);
8848 pipe.AddShader(&vs);
8849 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008850 pipe.AddColorAttachment();
8851 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008852
8853 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008856 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8857 // of PSO
8858 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8859 // cmd_pipeline.c
8860 // due to the fact that cmd_alloc_dset_data() has not been called in
8861 // cmd_bind_graphics_pipeline()
8862 // TODO : Want to cause various binding incompatibility issues here to test
8863 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008864 // First cause various verify_layout_compatibility() fails
8865 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008866 // verify_set_layout_compatibility fail cases:
8867 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8869 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8870 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008871 m_errorMonitor->VerifyFound();
8872
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008873 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8875 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8876 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008877 m_errorMonitor->VerifyFound();
8878
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008879 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008880 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8881 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8883 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8884 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008885 m_errorMonitor->VerifyFound();
8886
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008887 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8888 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8891 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008892 m_errorMonitor->VerifyFound();
8893
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008894 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8895 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8897 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8899 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008900 m_errorMonitor->VerifyFound();
8901
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008902 // Cause INFO messages due to disturbing previously bound Sets
8903 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8905 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008906 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8908 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8909 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008910 m_errorMonitor->VerifyFound();
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8913 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008914 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8916 "any subsequent sets were disturbed ");
8917 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8918 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008919 m_errorMonitor->VerifyFound();
8920
Tobin Ehlis10fad692016-07-07 12:00:36 -06008921 // Now that we're done actively using the pipelineLayout that gfx pipeline
8922 // was created with, we should be able to delete it. Do that now to verify
8923 // that validation obeys pipelineLayout lifetime
8924 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8925
Tobin Ehlis88452832015-12-03 09:40:56 -07008926 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008927 // 1. Error due to not binding required set (we actually use same code as
8928 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008929 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8930 &descriptorSet[0], 0, NULL);
8931 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8932 &descriptorSet[1], 0, NULL);
8933 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 -07008934 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008935 m_errorMonitor->VerifyFound();
8936
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008937 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008938 // 2. Error due to bound set not being compatible with PSO's
8939 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8941 &descriptorSet[0], 0, NULL);
8942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008943 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008944 m_errorMonitor->VerifyFound();
8945
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008946 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008947 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008948 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8949 }
8950 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008951 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8952 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008953 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008954 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008956 vkFreeMemory(m_device->device(), imageMem, NULL);
8957 vkDestroyImage(m_device->device(), image, NULL);
8958 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008959}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008960
Karl Schultz6addd812016-02-02 17:17:23 -07008961TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8964 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008965
8966 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008967 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008968 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008969 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008970
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008971 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008972}
8973
Karl Schultz6addd812016-02-02 17:17:23 -07008974TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8975 VkResult err;
8976 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008979
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008980 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008981
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008982 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008983 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008984 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008985 cmd.commandPool = m_commandPool;
8986 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008987 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008988
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008989 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008990 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008991
8992 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008993 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008994 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008995 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008996 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008997 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 -07008998 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008999
9000 // The error should be caught by validation of the BeginCommandBuffer call
9001 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
9002
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009003 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009004 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06009005}
9006
Karl Schultz6addd812016-02-02 17:17:23 -07009007TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009008 // Cause error due to Begin while recording CB
9009 // Then cause 2 errors for attempting to reset CB w/o having
9010 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
9011 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009013
9014 ASSERT_NO_FATAL_FAILURE(InitState());
9015
9016 // Calls AllocateCommandBuffers
9017 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
9018
Karl Schultz6addd812016-02-02 17:17:23 -07009019 // Force the failure by setting the Renderpass and Framebuffer fields with
9020 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009021 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07009022 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009023 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9024 cmd_buf_info.pNext = NULL;
9025 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009026 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009027
9028 // Begin CB to transition to recording state
9029 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
9030 // Can't re-begin. This should trigger error
9031 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009032 m_errorMonitor->VerifyFound();
9033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009035 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
9036 // Reset attempt will trigger error due to incorrect CommandPool state
9037 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009038 m_errorMonitor->VerifyFound();
9039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009041 // Transition CB to RECORDED state
9042 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
9043 // Now attempting to Begin will implicitly reset, which triggers error
9044 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009045 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009046}
9047
Karl Schultz6addd812016-02-02 17:17:23 -07009048TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009049 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009050 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009053
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009054 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009056
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009057 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009058 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9059 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009060
9061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9063 ds_pool_ci.pNext = NULL;
9064 ds_pool_ci.maxSets = 1;
9065 ds_pool_ci.poolSizeCount = 1;
9066 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009067
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009068 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009069 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009070 ASSERT_VK_SUCCESS(err);
9071
Tony Barboureb254902015-07-15 12:50:33 -06009072 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009073 dsl_binding.binding = 0;
9074 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9075 dsl_binding.descriptorCount = 1;
9076 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9077 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009078
Tony Barboureb254902015-07-15 12:50:33 -06009079 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009080 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9081 ds_layout_ci.pNext = NULL;
9082 ds_layout_ci.bindingCount = 1;
9083 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009084
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009085 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009087 ASSERT_VK_SUCCESS(err);
9088
9089 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009090 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009091 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009092 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009093 alloc_info.descriptorPool = ds_pool;
9094 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009096 ASSERT_VK_SUCCESS(err);
9097
Tony Barboureb254902015-07-15 12:50:33 -06009098 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009099 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9100 pipeline_layout_ci.setLayoutCount = 1;
9101 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009102
9103 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009104 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009105 ASSERT_VK_SUCCESS(err);
9106
Tobin Ehlise68360f2015-10-01 11:15:13 -06009107 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07009108 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06009109
9110 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009111 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9112 vp_state_ci.scissorCount = 1;
9113 vp_state_ci.pScissors = &sc;
9114 vp_state_ci.viewportCount = 1;
9115 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009116
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009117 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9118 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9119 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9120 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9121 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9122 rs_state_ci.depthClampEnable = VK_FALSE;
9123 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9124 rs_state_ci.depthBiasEnable = VK_FALSE;
9125
Tony Barboureb254902015-07-15 12:50:33 -06009126 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009127 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9128 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009129 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009130 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9131 gp_ci.layout = pipeline_layout;
9132 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06009133
9134 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009135 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9136 pc_ci.initialDataSize = 0;
9137 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009138
9139 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06009140 VkPipelineCache pipelineCache;
9141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06009143 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009144 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06009145
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009146 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009147
Chia-I Wuf7458c52015-10-26 21:10:41 +08009148 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9151 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009152}
Tobin Ehlis912df022015-09-17 08:46:18 -06009153/*// TODO : This test should be good, but needs Tess support in compiler to run
9154TEST_F(VkLayerTest, InvalidPatchControlPoints)
9155{
9156 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06009157 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009158
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009160 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
9161primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009162
Tobin Ehlis912df022015-09-17 08:46:18 -06009163 ASSERT_NO_FATAL_FAILURE(InitState());
9164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06009165
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009166 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06009167 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009168 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009169
9170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9172 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009173 ds_pool_ci.poolSizeCount = 1;
9174 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06009175
9176 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009177 err = vkCreateDescriptorPool(m_device->device(),
9178VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06009179 ASSERT_VK_SUCCESS(err);
9180
9181 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009182 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06009183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009184 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9186 dsl_binding.pImmutableSamplers = NULL;
9187
9188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009189 ds_layout_ci.sType =
9190VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009191 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009192 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009193 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06009194
9195 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009196 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9197&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009198 ASSERT_VK_SUCCESS(err);
9199
9200 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009201 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
9202VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06009203 ASSERT_VK_SUCCESS(err);
9204
9205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009206 pipeline_layout_ci.sType =
9207VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009208 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009209 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009210 pipeline_layout_ci.pSetLayouts = &ds_layout;
9211
9212 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009213 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9214&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009215 ASSERT_VK_SUCCESS(err);
9216
9217 VkPipelineShaderStageCreateInfo shaderStages[3];
9218 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
9219
Karl Schultz6addd812016-02-02 17:17:23 -07009220 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
9221this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009222 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07009223 VkShaderObj
9224tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
9225this);
9226 VkShaderObj
9227te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
9228this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009229
Karl Schultz6addd812016-02-02 17:17:23 -07009230 shaderStages[0].sType =
9231VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009232 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009233 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009234 shaderStages[1].sType =
9235VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009236 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009237 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009238 shaderStages[2].sType =
9239VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009240 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009241 shaderStages[2].shader = te.handle();
9242
9243 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 iaCI.sType =
9245VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009246 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009247
9248 VkPipelineTessellationStateCreateInfo tsCI = {};
9249 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9250 tsCI.patchControlPoints = 0; // This will cause an error
9251
9252 VkGraphicsPipelineCreateInfo gp_ci = {};
9253 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9254 gp_ci.pNext = NULL;
9255 gp_ci.stageCount = 3;
9256 gp_ci.pStages = shaderStages;
9257 gp_ci.pVertexInputState = NULL;
9258 gp_ci.pInputAssemblyState = &iaCI;
9259 gp_ci.pTessellationState = &tsCI;
9260 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009261 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009262 gp_ci.pMultisampleState = NULL;
9263 gp_ci.pDepthStencilState = NULL;
9264 gp_ci.pColorBlendState = NULL;
9265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9266 gp_ci.layout = pipeline_layout;
9267 gp_ci.renderPass = renderPass();
9268
9269 VkPipelineCacheCreateInfo pc_ci = {};
9270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9271 pc_ci.pNext = NULL;
9272 pc_ci.initialSize = 0;
9273 pc_ci.initialData = 0;
9274 pc_ci.maxSize = 0;
9275
9276 VkPipeline pipeline;
9277 VkPipelineCache pipelineCache;
9278
Karl Schultz6addd812016-02-02 17:17:23 -07009279 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9280&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009281 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009282 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9283&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009284
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009285 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009286
Chia-I Wuf7458c52015-10-26 21:10:41 +08009287 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9289 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9290 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009291}
9292*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009293// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009294TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009295 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009296
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9298 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009299
Tobin Ehlise68360f2015-10-01 11:15:13 -06009300 ASSERT_NO_FATAL_FAILURE(InitState());
9301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009302
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009303 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009304 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9305 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009306
9307 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009308 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9309 ds_pool_ci.maxSets = 1;
9310 ds_pool_ci.poolSizeCount = 1;
9311 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009312
9313 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009315 ASSERT_VK_SUCCESS(err);
9316
9317 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009318 dsl_binding.binding = 0;
9319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9320 dsl_binding.descriptorCount = 1;
9321 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322
9323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9325 ds_layout_ci.bindingCount = 1;
9326 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009327
9328 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009330 ASSERT_VK_SUCCESS(err);
9331
9332 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009333 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009335 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009336 alloc_info.descriptorPool = ds_pool;
9337 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009339 ASSERT_VK_SUCCESS(err);
9340
9341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9343 pipeline_layout_ci.setLayoutCount = 1;
9344 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009345
9346 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009347 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009348 ASSERT_VK_SUCCESS(err);
9349
9350 VkViewport vp = {}; // Just need dummy vp to point to
9351
9352 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009353 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9354 vp_state_ci.scissorCount = 0;
9355 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9356 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009357
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009358 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9359 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9360 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9361 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9362 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9363 rs_state_ci.depthClampEnable = VK_FALSE;
9364 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9365 rs_state_ci.depthBiasEnable = VK_FALSE;
9366
Cody Northropeb3a6c12015-10-05 14:44:45 -06009367 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009368 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9371 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9372 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009373 shaderStages[0] = vs.GetStageCreateInfo();
9374 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009375
9376 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009377 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9378 gp_ci.stageCount = 2;
9379 gp_ci.pStages = shaderStages;
9380 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009381 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009382 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9383 gp_ci.layout = pipeline_layout;
9384 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009385
9386 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009387 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009388
9389 VkPipeline pipeline;
9390 VkPipelineCache pipelineCache;
9391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009392 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009393 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009394 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009395
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009396 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009397
Chia-I Wuf7458c52015-10-26 21:10:41 +08009398 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9399 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9401 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009402}
Karl Schultz6addd812016-02-02 17:17:23 -07009403// Don't set viewport state in PSO. This is an error b/c we always need this
9404// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009405// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009406TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009407 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009408 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009411
Tobin Ehlise68360f2015-10-01 11:15:13 -06009412 ASSERT_NO_FATAL_FAILURE(InitState());
9413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009414
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009415 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009416 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9417 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009418
9419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9421 ds_pool_ci.maxSets = 1;
9422 ds_pool_ci.poolSizeCount = 1;
9423 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009424
9425 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009426 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009427 ASSERT_VK_SUCCESS(err);
9428
9429 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009430 dsl_binding.binding = 0;
9431 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9432 dsl_binding.descriptorCount = 1;
9433 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009434
9435 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009436 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9437 ds_layout_ci.bindingCount = 1;
9438 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009439
9440 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009441 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009442 ASSERT_VK_SUCCESS(err);
9443
9444 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009445 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009446 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009447 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009448 alloc_info.descriptorPool = ds_pool;
9449 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009451 ASSERT_VK_SUCCESS(err);
9452
9453 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009454 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9455 pipeline_layout_ci.setLayoutCount = 1;
9456 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009457
9458 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009460 ASSERT_VK_SUCCESS(err);
9461
9462 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9463 // Set scissor as dynamic to avoid second error
9464 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009465 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9466 dyn_state_ci.dynamicStateCount = 1;
9467 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009468
Cody Northropeb3a6c12015-10-05 14:44:45 -06009469 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009470 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009471
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009472 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9473 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9474 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009475 shaderStages[0] = vs.GetStageCreateInfo();
9476 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009477
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009478 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9479 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9480 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9481 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9482 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9483 rs_state_ci.depthClampEnable = VK_FALSE;
9484 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9485 rs_state_ci.depthBiasEnable = VK_FALSE;
9486
Tobin Ehlise68360f2015-10-01 11:15:13 -06009487 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009488 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9489 gp_ci.stageCount = 2;
9490 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009491 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009492 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9493 // should cause validation error
9494 gp_ci.pDynamicState = &dyn_state_ci;
9495 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9496 gp_ci.layout = pipeline_layout;
9497 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009498
9499 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009500 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009501
9502 VkPipeline pipeline;
9503 VkPipelineCache pipelineCache;
9504
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009506 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009507 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009508
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009509 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009510
Chia-I Wuf7458c52015-10-26 21:10:41 +08009511 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9513 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9514 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009515}
9516// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009517// Then run second test where dynamic scissor count doesn't match PSO scissor
9518// count
9519TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9520 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9523 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009524
Tobin Ehlise68360f2015-10-01 11:15:13 -06009525 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009526
9527 if (!m_device->phy().features().multiViewport) {
9528 printf("Device does not support multiple viewports/scissors; skipped.\n");
9529 return;
9530 }
9531
Tobin Ehlise68360f2015-10-01 11:15:13 -06009532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009533
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009534 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009535 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9536 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009537
9538 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009539 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9540 ds_pool_ci.maxSets = 1;
9541 ds_pool_ci.poolSizeCount = 1;
9542 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009543
9544 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009545 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009546 ASSERT_VK_SUCCESS(err);
9547
9548 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009549 dsl_binding.binding = 0;
9550 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9551 dsl_binding.descriptorCount = 1;
9552 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009553
9554 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009555 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9556 ds_layout_ci.bindingCount = 1;
9557 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009558
9559 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009560 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009561 ASSERT_VK_SUCCESS(err);
9562
9563 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009564 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009565 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009566 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009567 alloc_info.descriptorPool = ds_pool;
9568 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009570 ASSERT_VK_SUCCESS(err);
9571
9572 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.setLayoutCount = 1;
9575 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009576
9577 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009579 ASSERT_VK_SUCCESS(err);
9580
9581 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009582 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9583 vp_state_ci.viewportCount = 1;
9584 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9585 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009587
9588 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9589 // Set scissor as dynamic to avoid that error
9590 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009591 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9592 dyn_state_ci.dynamicStateCount = 1;
9593 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009594
Cody Northropeb3a6c12015-10-05 14:44:45 -06009595 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009596 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009598 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9599 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9600 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009601 shaderStages[0] = vs.GetStageCreateInfo();
9602 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009603
Cody Northropf6622dc2015-10-06 10:33:21 -06009604 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9605 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9606 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009607 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009608 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009609 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009610 vi_ci.pVertexAttributeDescriptions = nullptr;
9611
9612 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9613 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9614 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9615
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009616 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009617 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009618 rs_ci.pNext = nullptr;
9619
Mark Youngc89c6312016-03-31 16:03:20 -06009620 VkPipelineColorBlendAttachmentState att = {};
9621 att.blendEnable = VK_FALSE;
9622 att.colorWriteMask = 0xf;
9623
Cody Northropf6622dc2015-10-06 10:33:21 -06009624 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9625 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9626 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009627 cb_ci.attachmentCount = 1;
9628 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009629
Tobin Ehlise68360f2015-10-01 11:15:13 -06009630 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009631 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9632 gp_ci.stageCount = 2;
9633 gp_ci.pStages = shaderStages;
9634 gp_ci.pVertexInputState = &vi_ci;
9635 gp_ci.pInputAssemblyState = &ia_ci;
9636 gp_ci.pViewportState = &vp_state_ci;
9637 gp_ci.pRasterizationState = &rs_ci;
9638 gp_ci.pColorBlendState = &cb_ci;
9639 gp_ci.pDynamicState = &dyn_state_ci;
9640 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9641 gp_ci.layout = pipeline_layout;
9642 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009643
9644 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009645 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009646
9647 VkPipeline pipeline;
9648 VkPipelineCache pipelineCache;
9649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009651 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009653
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009654 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009655
Tobin Ehlisd332f282015-10-02 11:00:56 -06009656 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009657 // First need to successfully create the PSO from above by setting
9658 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009660
9661 VkViewport vp = {}; // Just need dummy vp to point to
9662 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009663 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009664 ASSERT_VK_SUCCESS(err);
9665 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009666 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009667 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009668 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009669 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009670 Draw(1, 0, 0, 0);
9671
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009672 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009673
9674 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9675 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9677 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009678 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009679}
9680// Create PSO w/o non-zero scissorCount but no scissor data
9681// Then run second test where dynamic viewportCount doesn't match PSO
9682// viewportCount
9683TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9684 VkResult err;
9685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 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 -07009687
9688 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009689
9690 if (!m_device->phy().features().multiViewport) {
9691 printf("Device does not support multiple viewports/scissors; skipped.\n");
9692 return;
9693 }
9694
Karl Schultz6addd812016-02-02 17:17:23 -07009695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9696
9697 VkDescriptorPoolSize ds_type_count = {};
9698 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9699 ds_type_count.descriptorCount = 1;
9700
9701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9703 ds_pool_ci.maxSets = 1;
9704 ds_pool_ci.poolSizeCount = 1;
9705 ds_pool_ci.pPoolSizes = &ds_type_count;
9706
9707 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009709 ASSERT_VK_SUCCESS(err);
9710
9711 VkDescriptorSetLayoutBinding dsl_binding = {};
9712 dsl_binding.binding = 0;
9713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9714 dsl_binding.descriptorCount = 1;
9715 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9716
9717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9719 ds_layout_ci.bindingCount = 1;
9720 ds_layout_ci.pBindings = &dsl_binding;
9721
9722 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009724 ASSERT_VK_SUCCESS(err);
9725
9726 VkDescriptorSet descriptorSet;
9727 VkDescriptorSetAllocateInfo alloc_info = {};
9728 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9729 alloc_info.descriptorSetCount = 1;
9730 alloc_info.descriptorPool = ds_pool;
9731 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009733 ASSERT_VK_SUCCESS(err);
9734
9735 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9736 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9737 pipeline_layout_ci.setLayoutCount = 1;
9738 pipeline_layout_ci.pSetLayouts = &ds_layout;
9739
9740 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009742 ASSERT_VK_SUCCESS(err);
9743
9744 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9745 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9746 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009747 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009748 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009750
9751 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9752 // Set scissor as dynamic to avoid that error
9753 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9754 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9755 dyn_state_ci.dynamicStateCount = 1;
9756 dyn_state_ci.pDynamicStates = &vp_state;
9757
9758 VkPipelineShaderStageCreateInfo shaderStages[2];
9759 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009761 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9762 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9763 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009764 shaderStages[0] = vs.GetStageCreateInfo();
9765 shaderStages[1] = fs.GetStageCreateInfo();
9766
9767 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9768 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9769 vi_ci.pNext = nullptr;
9770 vi_ci.vertexBindingDescriptionCount = 0;
9771 vi_ci.pVertexBindingDescriptions = nullptr;
9772 vi_ci.vertexAttributeDescriptionCount = 0;
9773 vi_ci.pVertexAttributeDescriptions = nullptr;
9774
9775 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9776 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9777 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9778
9779 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9780 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9781 rs_ci.pNext = nullptr;
9782
Mark Youngc89c6312016-03-31 16:03:20 -06009783 VkPipelineColorBlendAttachmentState att = {};
9784 att.blendEnable = VK_FALSE;
9785 att.colorWriteMask = 0xf;
9786
Karl Schultz6addd812016-02-02 17:17:23 -07009787 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9788 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9789 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009790 cb_ci.attachmentCount = 1;
9791 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009792
9793 VkGraphicsPipelineCreateInfo gp_ci = {};
9794 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9795 gp_ci.stageCount = 2;
9796 gp_ci.pStages = shaderStages;
9797 gp_ci.pVertexInputState = &vi_ci;
9798 gp_ci.pInputAssemblyState = &ia_ci;
9799 gp_ci.pViewportState = &vp_state_ci;
9800 gp_ci.pRasterizationState = &rs_ci;
9801 gp_ci.pColorBlendState = &cb_ci;
9802 gp_ci.pDynamicState = &dyn_state_ci;
9803 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9804 gp_ci.layout = pipeline_layout;
9805 gp_ci.renderPass = renderPass();
9806
9807 VkPipelineCacheCreateInfo pc_ci = {};
9808 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9809
9810 VkPipeline pipeline;
9811 VkPipelineCache pipelineCache;
9812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009813 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009814 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009817 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009818
9819 // Now hit second fail case where we set scissor w/ different count than PSO
9820 // First need to successfully create the PSO from above by setting
9821 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009823
Tobin Ehlisd332f282015-10-02 11:00:56 -06009824 VkRect2D sc = {}; // Just need dummy vp to point to
9825 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009826 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009827 ASSERT_VK_SUCCESS(err);
9828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009830 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009831 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009832 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009833 Draw(1, 0, 0, 0);
9834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009835 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009836
Chia-I Wuf7458c52015-10-26 21:10:41 +08009837 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009841 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009842}
9843
Mark Young7394fdd2016-03-31 14:56:43 -06009844TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9845 VkResult err;
9846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009848
9849 ASSERT_NO_FATAL_FAILURE(InitState());
9850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9851
9852 VkDescriptorPoolSize ds_type_count = {};
9853 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9854 ds_type_count.descriptorCount = 1;
9855
9856 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9857 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9858 ds_pool_ci.maxSets = 1;
9859 ds_pool_ci.poolSizeCount = 1;
9860 ds_pool_ci.pPoolSizes = &ds_type_count;
9861
9862 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009864 ASSERT_VK_SUCCESS(err);
9865
9866 VkDescriptorSetLayoutBinding dsl_binding = {};
9867 dsl_binding.binding = 0;
9868 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9869 dsl_binding.descriptorCount = 1;
9870 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9871
9872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9874 ds_layout_ci.bindingCount = 1;
9875 ds_layout_ci.pBindings = &dsl_binding;
9876
9877 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009879 ASSERT_VK_SUCCESS(err);
9880
9881 VkDescriptorSet descriptorSet;
9882 VkDescriptorSetAllocateInfo alloc_info = {};
9883 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9884 alloc_info.descriptorSetCount = 1;
9885 alloc_info.descriptorPool = ds_pool;
9886 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009888 ASSERT_VK_SUCCESS(err);
9889
9890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9892 pipeline_layout_ci.setLayoutCount = 1;
9893 pipeline_layout_ci.pSetLayouts = &ds_layout;
9894
9895 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009897 ASSERT_VK_SUCCESS(err);
9898
9899 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9900 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9901 vp_state_ci.scissorCount = 1;
9902 vp_state_ci.pScissors = NULL;
9903 vp_state_ci.viewportCount = 1;
9904 vp_state_ci.pViewports = NULL;
9905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009906 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009907 // Set scissor as dynamic to avoid that error
9908 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9909 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9910 dyn_state_ci.dynamicStateCount = 2;
9911 dyn_state_ci.pDynamicStates = dynamic_states;
9912
9913 VkPipelineShaderStageCreateInfo shaderStages[2];
9914 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9917 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009918 this); // TODO - We shouldn't need a fragment shader
9919 // but add it to be able to run on more devices
9920 shaderStages[0] = vs.GetStageCreateInfo();
9921 shaderStages[1] = fs.GetStageCreateInfo();
9922
9923 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9924 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9925 vi_ci.pNext = nullptr;
9926 vi_ci.vertexBindingDescriptionCount = 0;
9927 vi_ci.pVertexBindingDescriptions = nullptr;
9928 vi_ci.vertexAttributeDescriptionCount = 0;
9929 vi_ci.pVertexAttributeDescriptions = nullptr;
9930
9931 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9932 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9933 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9934
9935 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9936 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9937 rs_ci.pNext = nullptr;
9938
Mark Young47107952016-05-02 15:59:55 -06009939 // Check too low (line width of -1.0f).
9940 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009941
9942 VkPipelineColorBlendAttachmentState att = {};
9943 att.blendEnable = VK_FALSE;
9944 att.colorWriteMask = 0xf;
9945
9946 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9947 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9948 cb_ci.pNext = nullptr;
9949 cb_ci.attachmentCount = 1;
9950 cb_ci.pAttachments = &att;
9951
9952 VkGraphicsPipelineCreateInfo gp_ci = {};
9953 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9954 gp_ci.stageCount = 2;
9955 gp_ci.pStages = shaderStages;
9956 gp_ci.pVertexInputState = &vi_ci;
9957 gp_ci.pInputAssemblyState = &ia_ci;
9958 gp_ci.pViewportState = &vp_state_ci;
9959 gp_ci.pRasterizationState = &rs_ci;
9960 gp_ci.pColorBlendState = &cb_ci;
9961 gp_ci.pDynamicState = &dyn_state_ci;
9962 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9963 gp_ci.layout = pipeline_layout;
9964 gp_ci.renderPass = renderPass();
9965
9966 VkPipelineCacheCreateInfo pc_ci = {};
9967 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9968
9969 VkPipeline pipeline;
9970 VkPipelineCache pipelineCache;
9971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009973 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009975
9976 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009977 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009980
9981 // Check too high (line width of 65536.0f).
9982 rs_ci.lineWidth = 65536.0f;
9983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009985 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009987
9988 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009989 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009992
9993 dyn_state_ci.dynamicStateCount = 3;
9994
9995 rs_ci.lineWidth = 1.0f;
9996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009997 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009998 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -060010000 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -060010002
10003 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -060010004 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -060010005 m_errorMonitor->VerifyFound();
10006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -060010008
10009 // Check too high with dynamic setting.
10010 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
10011 m_errorMonitor->VerifyFound();
10012 EndCommandBuffer();
10013
10014 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
10015 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010018 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -060010019}
10020
Karl Schultz6addd812016-02-02 17:17:23 -070010021TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010022 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10024 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010025
10026 ASSERT_NO_FATAL_FAILURE(InitState());
10027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010028
Tony Barbourfe3351b2015-07-28 10:17:20 -060010029 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -070010030 // Don't care about RenderPass handle b/c error should be flagged before
10031 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010033
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010034 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010035}
10036
Karl Schultz6addd812016-02-02 17:17:23 -070010037TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010038 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10040 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010041
10042 ASSERT_NO_FATAL_FAILURE(InitState());
10043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010044
Tony Barbourfe3351b2015-07-28 10:17:20 -060010045 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -070010046 // Just create a dummy Renderpass that's non-NULL so we can get to the
10047 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010048 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010049
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010050 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010051}
10052
Chris Forbes2eeabe32016-06-21 20:52:34 +120010053TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
10054 m_errorMonitor->ExpectSuccess();
10055
10056 ASSERT_NO_FATAL_FAILURE(InitState());
10057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +120010060 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
10061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +120010063 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10064 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010065 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +120010066 m_errorMonitor->VerifyNotFound();
10067 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10068 m_errorMonitor->VerifyNotFound();
10069
10070 m_commandBuffer->EndCommandBuffer();
10071 m_errorMonitor->VerifyNotFound();
10072}
10073
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010074TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
10075 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
10076 "the number of renderPass attachments that use loadOp"
10077 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
10078
10079 ASSERT_NO_FATAL_FAILURE(InitState());
10080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10081
10082 // Create a renderPass with a single attachment that uses loadOp CLEAR
10083 VkAttachmentReference attach = {};
10084 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10085 VkSubpassDescription subpass = {};
10086 subpass.inputAttachmentCount = 1;
10087 subpass.pInputAttachments = &attach;
10088 VkRenderPassCreateInfo rpci = {};
10089 rpci.subpassCount = 1;
10090 rpci.pSubpasses = &subpass;
10091 rpci.attachmentCount = 1;
10092 VkAttachmentDescription attach_desc = {};
10093 attach_desc.format = VK_FORMAT_UNDEFINED;
10094 // Set loadOp to CLEAR
10095 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10096 rpci.pAttachments = &attach_desc;
10097 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10098 VkRenderPass rp;
10099 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10100
10101 VkCommandBufferInheritanceInfo hinfo = {};
10102 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10103 hinfo.renderPass = VK_NULL_HANDLE;
10104 hinfo.subpass = 0;
10105 hinfo.framebuffer = VK_NULL_HANDLE;
10106 hinfo.occlusionQueryEnable = VK_FALSE;
10107 hinfo.queryFlags = 0;
10108 hinfo.pipelineStatistics = 0;
10109 VkCommandBufferBeginInfo info = {};
10110 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
10111 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10112 info.pInheritanceInfo = &hinfo;
10113
10114 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
10115 VkRenderPassBeginInfo rp_begin = {};
10116 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10117 rp_begin.pNext = NULL;
10118 rp_begin.renderPass = renderPass();
10119 rp_begin.framebuffer = framebuffer();
10120 rp_begin.clearValueCount = 0; // Should be 1
10121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
10123 "there must be at least 1 entries in "
10124 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010127
10128 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -060010129
10130 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010131}
10132
Cody Northrop3bb4d962016-05-09 16:15:57 -060010133TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
10134
10135 TEST_DESCRIPTION("End a command buffer with an active render pass");
10136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10138 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -060010139
10140 ASSERT_NO_FATAL_FAILURE(InitState());
10141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10142
10143 // The framework's BeginCommandBuffer calls CreateRenderPass
10144 BeginCommandBuffer();
10145
10146 // Call directly into vkEndCommandBuffer instead of the
10147 // the framework's EndCommandBuffer, which inserts a
10148 // vkEndRenderPass
10149 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
10150
10151 m_errorMonitor->VerifyFound();
10152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
10154 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -060010155}
10156
Karl Schultz6addd812016-02-02 17:17:23 -070010157TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010158 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10160 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010161
10162 ASSERT_NO_FATAL_FAILURE(InitState());
10163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010164
10165 // Renderpass is started here
10166 BeginCommandBuffer();
10167
10168 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010169 vk_testing::Buffer dstBuffer;
10170 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010171
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010172 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010173
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010174 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010175}
10176
Karl Schultz6addd812016-02-02 17:17:23 -070010177TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010178 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10180 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010181
10182 ASSERT_NO_FATAL_FAILURE(InitState());
10183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010184
10185 // Renderpass is started here
10186 BeginCommandBuffer();
10187
10188 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010189 vk_testing::Buffer dstBuffer;
10190 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010191
Karl Schultz6addd812016-02-02 17:17:23 -070010192 VkDeviceSize dstOffset = 0;
10193 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -060010194 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010196 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010197
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010198 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010199}
10200
Karl Schultz6addd812016-02-02 17:17:23 -070010201TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010202 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10204 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010205
10206 ASSERT_NO_FATAL_FAILURE(InitState());
10207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010208
10209 // Renderpass is started here
10210 BeginCommandBuffer();
10211
Michael Lentine0a369f62016-02-03 16:51:46 -060010212 VkClearColorValue clear_color;
10213 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -070010214 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10215 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10216 const int32_t tex_width = 32;
10217 const int32_t tex_height = 32;
10218 VkImageCreateInfo image_create_info = {};
10219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10220 image_create_info.pNext = NULL;
10221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10222 image_create_info.format = tex_format;
10223 image_create_info.extent.width = tex_width;
10224 image_create_info.extent.height = tex_height;
10225 image_create_info.extent.depth = 1;
10226 image_create_info.mipLevels = 1;
10227 image_create_info.arrayLayers = 1;
10228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10229 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10230 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010231
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010232 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010239 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010240}
10241
Karl Schultz6addd812016-02-02 17:17:23 -070010242TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010243 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10245 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010246
10247 ASSERT_NO_FATAL_FAILURE(InitState());
10248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010249
10250 // Renderpass is started here
10251 BeginCommandBuffer();
10252
10253 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010254 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010255 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10257 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10258 image_create_info.extent.width = 64;
10259 image_create_info.extent.height = 64;
10260 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10261 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010262
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010263 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010264 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010268 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10269 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010270
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010271 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010272}
10273
Karl Schultz6addd812016-02-02 17:17:23 -070010274TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010275 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010276 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10279 "must be issued inside an active "
10280 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010281
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010282 ASSERT_NO_FATAL_FAILURE(InitState());
10283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010284
10285 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010286 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010287 ASSERT_VK_SUCCESS(err);
10288
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010289 VkClearAttachment color_attachment;
10290 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10291 color_attachment.clearValue.color.float32[0] = 0;
10292 color_attachment.clearValue.color.float32[1] = 0;
10293 color_attachment.clearValue.color.float32[2] = 0;
10294 color_attachment.clearValue.color.float32[3] = 0;
10295 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010296 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010298
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010299 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010300}
10301
Chris Forbes3b97e932016-09-07 11:29:24 +120010302TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10303 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10304 "called too many times in a renderpass instance");
10305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10307 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010308
10309 ASSERT_NO_FATAL_FAILURE(InitState());
10310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10311
10312 BeginCommandBuffer();
10313
10314 // error here.
10315 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10316 m_errorMonitor->VerifyFound();
10317
10318 EndCommandBuffer();
10319}
10320
Chris Forbes6d624702016-09-07 13:57:05 +120010321TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10322 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10323 "called before the final subpass has been reached");
10324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10326 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010327
10328 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10330 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010332 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010333
10334 VkRenderPass rp;
10335 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10336 ASSERT_VK_SUCCESS(err);
10337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010338 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010339
10340 VkFramebuffer fb;
10341 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10342 ASSERT_VK_SUCCESS(err);
10343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010344 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 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 +120010347
10348 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10349
10350 // Error here.
10351 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10352 m_errorMonitor->VerifyFound();
10353
10354 // Clean up.
10355 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10356 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10357}
10358
Karl Schultz9e66a292016-04-21 15:57:51 -060010359TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10360 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10362 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010363
10364 ASSERT_NO_FATAL_FAILURE(InitState());
10365 BeginCommandBuffer();
10366
10367 VkBufferMemoryBarrier buf_barrier = {};
10368 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10369 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10370 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10371 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10372 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10373 buf_barrier.buffer = VK_NULL_HANDLE;
10374 buf_barrier.offset = 0;
10375 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10377 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010378
10379 m_errorMonitor->VerifyFound();
10380}
10381
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010382TEST_F(VkLayerTest, InvalidBarriers) {
10383 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010386
10387 ASSERT_NO_FATAL_FAILURE(InitState());
10388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10389
10390 VkMemoryBarrier mem_barrier = {};
10391 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10392 mem_barrier.pNext = NULL;
10393 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10394 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10395 BeginCommandBuffer();
10396 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010398 &mem_barrier, 0, nullptr, 0, nullptr);
10399 m_errorMonitor->VerifyFound();
10400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010402 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 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 -060010404 ASSERT_TRUE(image.initialized());
10405 VkImageMemoryBarrier img_barrier = {};
10406 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10407 img_barrier.pNext = NULL;
10408 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10409 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10410 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10411 // New layout can't be UNDEFINED
10412 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10413 img_barrier.image = image.handle();
10414 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10415 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10416 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10417 img_barrier.subresourceRange.baseArrayLayer = 0;
10418 img_barrier.subresourceRange.baseMipLevel = 0;
10419 img_barrier.subresourceRange.layerCount = 1;
10420 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010421 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10422 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010423 m_errorMonitor->VerifyFound();
10424 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10427 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010428 // baseArrayLayer + layerCount must be <= image's arrayLayers
10429 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10431 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010432 m_errorMonitor->VerifyFound();
10433 img_barrier.subresourceRange.baseArrayLayer = 0;
10434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010436 // baseMipLevel + levelCount must be <= image's mipLevels
10437 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10439 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010440 m_errorMonitor->VerifyFound();
10441 img_barrier.subresourceRange.baseMipLevel = 0;
10442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 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 -060010444 vk_testing::Buffer buffer;
10445 buffer.init(*m_device, 256);
10446 VkBufferMemoryBarrier buf_barrier = {};
10447 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10448 buf_barrier.pNext = NULL;
10449 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10450 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10451 buf_barrier.buffer = buffer.handle();
10452 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10453 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10454 buf_barrier.offset = 0;
10455 buf_barrier.size = VK_WHOLE_SIZE;
10456 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10458 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010459 m_errorMonitor->VerifyFound();
10460 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010463 buf_barrier.offset = 257;
10464 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10466 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010467 m_errorMonitor->VerifyFound();
10468 buf_barrier.offset = 0;
10469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010471 buf_barrier.size = 257;
10472 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010473 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10474 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010475 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010476
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010477 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10479 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10480 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010481 VkDepthStencilObj ds_image(m_device);
10482 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10483 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010484 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10485 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010486 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010487 // Use of COLOR aspect on DS image is error
10488 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10490 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010491 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010492 // Now test depth-only
10493 VkFormatProperties format_props;
10494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010495 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10496 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10498 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010499 VkDepthStencilObj d_image(m_device);
10500 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10501 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010503 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010504 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010505 // Use of COLOR aspect on depth image is error
10506 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10508 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010509 m_errorMonitor->VerifyFound();
10510 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10512 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010513 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10515 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010516 VkDepthStencilObj s_image(m_device);
10517 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10518 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010519 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010520 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010521 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010522 // Use of COLOR aspect on depth image is error
10523 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10525 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010526 m_errorMonitor->VerifyFound();
10527 }
10528 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10530 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010531 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 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 -060010533 ASSERT_TRUE(c_image.initialized());
10534 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10535 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10536 img_barrier.image = c_image.handle();
10537 // Set aspect to depth (non-color)
10538 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010539 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10540 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010541 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010542}
10543
Karl Schultz6addd812016-02-02 17:17:23 -070010544TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010545 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010546 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010549
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010550 ASSERT_NO_FATAL_FAILURE(InitState());
10551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010552 uint32_t qfi = 0;
10553 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010554 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10555 buffCI.size = 1024;
10556 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10557 buffCI.queueFamilyIndexCount = 1;
10558 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010559
10560 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010561 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010562 ASSERT_VK_SUCCESS(err);
10563
10564 BeginCommandBuffer();
10565 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010566 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10567 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010568 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010571 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010572
Chia-I Wuf7458c52015-10-26 21:10:41 +080010573 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010574}
10575
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010576TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10577 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10579 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10580 "of the indices specified when the device was created, via the "
10581 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010582
10583 ASSERT_NO_FATAL_FAILURE(InitState());
10584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10585 VkBufferCreateInfo buffCI = {};
10586 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10587 buffCI.size = 1024;
10588 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10589 buffCI.queueFamilyIndexCount = 1;
10590 // Introduce failure by specifying invalid queue_family_index
10591 uint32_t qfi = 777;
10592 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010593 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010594
10595 VkBuffer ib;
10596 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10597
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010598 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010599 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010600}
10601
Karl Schultz6addd812016-02-02 17:17:23 -070010602TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010603 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10604 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010607
10608 ASSERT_NO_FATAL_FAILURE(InitState());
10609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010610
10611 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010612
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010613 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10614 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010615
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010616 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010617}
10618
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010619TEST_F(VkLayerTest, DSUsageBitsErrors) {
10620 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10621 "that do not have correct usage bits sets.");
10622 VkResult err;
10623
10624 ASSERT_NO_FATAL_FAILURE(InitState());
10625 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10626 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10627 ds_type_count[i].type = VkDescriptorType(i);
10628 ds_type_count[i].descriptorCount = 1;
10629 }
10630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10632 ds_pool_ci.pNext = NULL;
10633 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10634 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10635 ds_pool_ci.pPoolSizes = ds_type_count;
10636
10637 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010639 ASSERT_VK_SUCCESS(err);
10640
10641 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010643 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10644 dsl_binding[i].binding = 0;
10645 dsl_binding[i].descriptorType = VkDescriptorType(i);
10646 dsl_binding[i].descriptorCount = 1;
10647 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10648 dsl_binding[i].pImmutableSamplers = NULL;
10649 }
10650
10651 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10652 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10653 ds_layout_ci.pNext = NULL;
10654 ds_layout_ci.bindingCount = 1;
10655 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10656 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10657 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010659 ASSERT_VK_SUCCESS(err);
10660 }
10661 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10662 VkDescriptorSetAllocateInfo alloc_info = {};
10663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10664 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10665 alloc_info.descriptorPool = ds_pool;
10666 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010668 ASSERT_VK_SUCCESS(err);
10669
10670 // Create a buffer & bufferView to be used for invalid updates
10671 VkBufferCreateInfo buff_ci = {};
10672 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10673 // This usage is not valid for any descriptor type
10674 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10675 buff_ci.size = 256;
10676 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10677 VkBuffer buffer;
10678 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10679 ASSERT_VK_SUCCESS(err);
10680
10681 VkBufferViewCreateInfo buff_view_ci = {};
10682 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10683 buff_view_ci.buffer = buffer;
10684 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10685 buff_view_ci.range = VK_WHOLE_SIZE;
10686 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010688 ASSERT_VK_SUCCESS(err);
10689
10690 // Create an image to be used for invalid updates
10691 VkImageCreateInfo image_ci = {};
10692 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10693 image_ci.imageType = VK_IMAGE_TYPE_2D;
10694 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10695 image_ci.extent.width = 64;
10696 image_ci.extent.height = 64;
10697 image_ci.extent.depth = 1;
10698 image_ci.mipLevels = 1;
10699 image_ci.arrayLayers = 1;
10700 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10701 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10702 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10703 // This usage is not valid for any descriptor type
10704 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10705 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10706 VkImage image;
10707 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10708 ASSERT_VK_SUCCESS(err);
10709 // Bind memory to image
10710 VkMemoryRequirements mem_reqs;
10711 VkDeviceMemory image_mem;
10712 bool pass;
10713 VkMemoryAllocateInfo mem_alloc = {};
10714 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10715 mem_alloc.pNext = NULL;
10716 mem_alloc.allocationSize = 0;
10717 mem_alloc.memoryTypeIndex = 0;
10718 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10719 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010721 ASSERT_TRUE(pass);
10722 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10723 ASSERT_VK_SUCCESS(err);
10724 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10725 ASSERT_VK_SUCCESS(err);
10726 // Now create view for image
10727 VkImageViewCreateInfo image_view_ci = {};
10728 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10729 image_view_ci.image = image;
10730 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10731 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10732 image_view_ci.subresourceRange.layerCount = 1;
10733 image_view_ci.subresourceRange.baseArrayLayer = 0;
10734 image_view_ci.subresourceRange.levelCount = 1;
10735 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10736 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010737 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010738 ASSERT_VK_SUCCESS(err);
10739
10740 VkDescriptorBufferInfo buff_info = {};
10741 buff_info.buffer = buffer;
10742 VkDescriptorImageInfo img_info = {};
10743 img_info.imageView = image_view;
10744 VkWriteDescriptorSet descriptor_write = {};
10745 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10746 descriptor_write.dstBinding = 0;
10747 descriptor_write.descriptorCount = 1;
10748 descriptor_write.pTexelBufferView = &buff_view;
10749 descriptor_write.pBufferInfo = &buff_info;
10750 descriptor_write.pImageInfo = &img_info;
10751
10752 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010753 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10754 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10755 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10756 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10757 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10758 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10759 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10760 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10761 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10762 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10763 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010764 // Start loop at 1 as SAMPLER desc type has no usage bit error
10765 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10766 descriptor_write.descriptorType = VkDescriptorType(i);
10767 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010770 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010771
10772 m_errorMonitor->VerifyFound();
10773 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10774 }
10775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10776 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010777 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010778 vkDestroyImageView(m_device->device(), image_view, NULL);
10779 vkDestroyBuffer(m_device->device(), buffer, NULL);
10780 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010782 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10783}
10784
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010785TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010786 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10787 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10788 "1. offset value greater than buffer size\n"
10789 "2. range value of 0\n"
10790 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010791 VkResult err;
10792
10793 ASSERT_NO_FATAL_FAILURE(InitState());
10794 VkDescriptorPoolSize ds_type_count = {};
10795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10796 ds_type_count.descriptorCount = 1;
10797
10798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10800 ds_pool_ci.pNext = NULL;
10801 ds_pool_ci.maxSets = 1;
10802 ds_pool_ci.poolSizeCount = 1;
10803 ds_pool_ci.pPoolSizes = &ds_type_count;
10804
10805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010807 ASSERT_VK_SUCCESS(err);
10808
10809 // Create layout with single uniform buffer descriptor
10810 VkDescriptorSetLayoutBinding dsl_binding = {};
10811 dsl_binding.binding = 0;
10812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10813 dsl_binding.descriptorCount = 1;
10814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10815 dsl_binding.pImmutableSamplers = NULL;
10816
10817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10819 ds_layout_ci.pNext = NULL;
10820 ds_layout_ci.bindingCount = 1;
10821 ds_layout_ci.pBindings = &dsl_binding;
10822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010824 ASSERT_VK_SUCCESS(err);
10825
10826 VkDescriptorSet descriptor_set = {};
10827 VkDescriptorSetAllocateInfo alloc_info = {};
10828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10829 alloc_info.descriptorSetCount = 1;
10830 alloc_info.descriptorPool = ds_pool;
10831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010833 ASSERT_VK_SUCCESS(err);
10834
10835 // Create a buffer to be used for invalid updates
10836 VkBufferCreateInfo buff_ci = {};
10837 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10838 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10839 buff_ci.size = 256;
10840 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10841 VkBuffer buffer;
10842 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10843 ASSERT_VK_SUCCESS(err);
10844 // Have to bind memory to buffer before descriptor update
10845 VkMemoryAllocateInfo mem_alloc = {};
10846 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10847 mem_alloc.pNext = NULL;
10848 mem_alloc.allocationSize = 256;
10849 mem_alloc.memoryTypeIndex = 0;
10850
10851 VkMemoryRequirements mem_reqs;
10852 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010853 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010854 if (!pass) {
10855 vkDestroyBuffer(m_device->device(), buffer, NULL);
10856 return;
10857 }
10858
10859 VkDeviceMemory mem;
10860 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10861 ASSERT_VK_SUCCESS(err);
10862 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10863 ASSERT_VK_SUCCESS(err);
10864
10865 VkDescriptorBufferInfo buff_info = {};
10866 buff_info.buffer = buffer;
10867 // First make offset 1 larger than buffer size
10868 buff_info.offset = 257;
10869 buff_info.range = VK_WHOLE_SIZE;
10870 VkWriteDescriptorSet descriptor_write = {};
10871 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10872 descriptor_write.dstBinding = 0;
10873 descriptor_write.descriptorCount = 1;
10874 descriptor_write.pTexelBufferView = nullptr;
10875 descriptor_write.pBufferInfo = &buff_info;
10876 descriptor_write.pImageInfo = nullptr;
10877
10878 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10879 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010881
10882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10883
10884 m_errorMonitor->VerifyFound();
10885 // Now cause error due to range of 0
10886 buff_info.offset = 0;
10887 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10889 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010890
10891 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10892
10893 m_errorMonitor->VerifyFound();
10894 // Now cause error due to range exceeding buffer size - offset
10895 buff_info.offset = 128;
10896 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010897 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 -060010898
10899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10900
10901 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010902 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010903 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10904 vkDestroyBuffer(m_device->device(), buffer, NULL);
10905 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10906 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10907}
10908
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010909TEST_F(VkLayerTest, DSAspectBitsErrors) {
10910 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10911 // are set, but could expand this test to hit more cases.
10912 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10913 "that do not have correct aspect bits sets.");
10914 VkResult err;
10915
10916 ASSERT_NO_FATAL_FAILURE(InitState());
10917 VkDescriptorPoolSize ds_type_count = {};
10918 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10919 ds_type_count.descriptorCount = 1;
10920
10921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10923 ds_pool_ci.pNext = NULL;
10924 ds_pool_ci.maxSets = 5;
10925 ds_pool_ci.poolSizeCount = 1;
10926 ds_pool_ci.pPoolSizes = &ds_type_count;
10927
10928 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010929 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010930 ASSERT_VK_SUCCESS(err);
10931
10932 VkDescriptorSetLayoutBinding dsl_binding = {};
10933 dsl_binding.binding = 0;
10934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10935 dsl_binding.descriptorCount = 1;
10936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10937 dsl_binding.pImmutableSamplers = NULL;
10938
10939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10941 ds_layout_ci.pNext = NULL;
10942 ds_layout_ci.bindingCount = 1;
10943 ds_layout_ci.pBindings = &dsl_binding;
10944 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010946 ASSERT_VK_SUCCESS(err);
10947
10948 VkDescriptorSet descriptor_set = {};
10949 VkDescriptorSetAllocateInfo alloc_info = {};
10950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10951 alloc_info.descriptorSetCount = 1;
10952 alloc_info.descriptorPool = ds_pool;
10953 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010955 ASSERT_VK_SUCCESS(err);
10956
10957 // Create an image to be used for invalid updates
10958 VkImageCreateInfo image_ci = {};
10959 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10960 image_ci.imageType = VK_IMAGE_TYPE_2D;
10961 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10962 image_ci.extent.width = 64;
10963 image_ci.extent.height = 64;
10964 image_ci.extent.depth = 1;
10965 image_ci.mipLevels = 1;
10966 image_ci.arrayLayers = 1;
10967 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10968 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10969 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10970 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10971 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10972 VkImage image;
10973 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10974 ASSERT_VK_SUCCESS(err);
10975 // Bind memory to image
10976 VkMemoryRequirements mem_reqs;
10977 VkDeviceMemory image_mem;
10978 bool pass;
10979 VkMemoryAllocateInfo mem_alloc = {};
10980 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10981 mem_alloc.pNext = NULL;
10982 mem_alloc.allocationSize = 0;
10983 mem_alloc.memoryTypeIndex = 0;
10984 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10985 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010986 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010987 ASSERT_TRUE(pass);
10988 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10989 ASSERT_VK_SUCCESS(err);
10990 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10991 ASSERT_VK_SUCCESS(err);
10992 // Now create view for image
10993 VkImageViewCreateInfo image_view_ci = {};
10994 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10995 image_view_ci.image = image;
10996 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10997 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10998 image_view_ci.subresourceRange.layerCount = 1;
10999 image_view_ci.subresourceRange.baseArrayLayer = 0;
11000 image_view_ci.subresourceRange.levelCount = 1;
11001 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011002 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011003
11004 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011005 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011006 ASSERT_VK_SUCCESS(err);
11007
11008 VkDescriptorImageInfo img_info = {};
11009 img_info.imageView = image_view;
11010 VkWriteDescriptorSet descriptor_write = {};
11011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11012 descriptor_write.dstBinding = 0;
11013 descriptor_write.descriptorCount = 1;
11014 descriptor_write.pTexelBufferView = NULL;
11015 descriptor_write.pBufferInfo = NULL;
11016 descriptor_write.pImageInfo = &img_info;
11017 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
11018 descriptor_write.dstSet = descriptor_set;
11019 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
11020 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011022
11023 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11024
11025 m_errorMonitor->VerifyFound();
11026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11027 vkDestroyImage(m_device->device(), image, NULL);
11028 vkFreeMemory(m_device->device(), image_mem, NULL);
11029 vkDestroyImageView(m_device->device(), image_view, NULL);
11030 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11031 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11032}
11033
Karl Schultz6addd812016-02-02 17:17:23 -070011034TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011035 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070011036 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11039 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
11040 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011041
Tobin Ehlis3b780662015-05-28 12:11:26 -060011042 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011043 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011044 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011045 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11046 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011047
11048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11050 ds_pool_ci.pNext = NULL;
11051 ds_pool_ci.maxSets = 1;
11052 ds_pool_ci.poolSizeCount = 1;
11053 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011054
Tobin Ehlis3b780662015-05-28 12:11:26 -060011055 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011056 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011057 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011058 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011059 dsl_binding.binding = 0;
11060 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11061 dsl_binding.descriptorCount = 1;
11062 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11063 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011064
Tony Barboureb254902015-07-15 12:50:33 -060011065 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011066 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11067 ds_layout_ci.pNext = NULL;
11068 ds_layout_ci.bindingCount = 1;
11069 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011070
Tobin Ehlis3b780662015-05-28 12:11:26 -060011071 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011073 ASSERT_VK_SUCCESS(err);
11074
11075 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011076 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011077 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011078 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011079 alloc_info.descriptorPool = ds_pool;
11080 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011081 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011082 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011083
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011084 VkSamplerCreateInfo sampler_ci = {};
11085 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11086 sampler_ci.pNext = NULL;
11087 sampler_ci.magFilter = VK_FILTER_NEAREST;
11088 sampler_ci.minFilter = VK_FILTER_NEAREST;
11089 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11090 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11091 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11092 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11093 sampler_ci.mipLodBias = 1.0;
11094 sampler_ci.anisotropyEnable = VK_FALSE;
11095 sampler_ci.maxAnisotropy = 1;
11096 sampler_ci.compareEnable = VK_FALSE;
11097 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11098 sampler_ci.minLod = 1.0;
11099 sampler_ci.maxLod = 1.0;
11100 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11101 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11102 VkSampler sampler;
11103 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11104 ASSERT_VK_SUCCESS(err);
11105
11106 VkDescriptorImageInfo info = {};
11107 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011108
11109 VkWriteDescriptorSet descriptor_write;
11110 memset(&descriptor_write, 0, sizeof(descriptor_write));
11111 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011112 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011113 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011114 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011115 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011116 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011117
11118 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11119
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011120 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011121
Chia-I Wuf7458c52015-10-26 21:10:41 +080011122 vkDestroySampler(m_device->device(), sampler, NULL);
11123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011125}
11126
Karl Schultz6addd812016-02-02 17:17:23 -070011127TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011128 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070011129 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11132 " binding #0 with 1 total descriptors but update of 1 descriptors "
11133 "starting at binding offset of 0 combined with update array element "
11134 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011135
Tobin Ehlis3b780662015-05-28 12:11:26 -060011136 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011137 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011138 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11140 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011141
11142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11144 ds_pool_ci.pNext = NULL;
11145 ds_pool_ci.maxSets = 1;
11146 ds_pool_ci.poolSizeCount = 1;
11147 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011148
Tobin Ehlis3b780662015-05-28 12:11:26 -060011149 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011151 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011152
Tony Barboureb254902015-07-15 12:50:33 -060011153 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011154 dsl_binding.binding = 0;
11155 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11156 dsl_binding.descriptorCount = 1;
11157 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11158 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011159
11160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11162 ds_layout_ci.pNext = NULL;
11163 ds_layout_ci.bindingCount = 1;
11164 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011165
Tobin Ehlis3b780662015-05-28 12:11:26 -060011166 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011168 ASSERT_VK_SUCCESS(err);
11169
11170 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011171 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011173 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011174 alloc_info.descriptorPool = ds_pool;
11175 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011177 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011178
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011179 // Correctly update descriptor to avoid "NOT_UPDATED" error
11180 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011182 buff_info.offset = 0;
11183 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011184
11185 VkWriteDescriptorSet descriptor_write;
11186 memset(&descriptor_write, 0, sizeof(descriptor_write));
11187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011188 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011190 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11192 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011193
11194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11195
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011196 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011197
Chia-I Wuf7458c52015-10-26 21:10:41 +080011198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011200}
11201
Karl Schultz6addd812016-02-02 17:17:23 -070011202TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
11203 // Create layout w/ count of 1 and attempt update to that layout w/ binding
11204 // index 2
11205 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011208
Tobin Ehlis3b780662015-05-28 12:11:26 -060011209 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011210 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011211 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011212 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11213 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011214
11215 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011216 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11217 ds_pool_ci.pNext = NULL;
11218 ds_pool_ci.maxSets = 1;
11219 ds_pool_ci.poolSizeCount = 1;
11220 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011221
Tobin Ehlis3b780662015-05-28 12:11:26 -060011222 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011223 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011224 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011225
Tony Barboureb254902015-07-15 12:50:33 -060011226 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011227 dsl_binding.binding = 0;
11228 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11229 dsl_binding.descriptorCount = 1;
11230 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11231 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011232
11233 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011234 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11235 ds_layout_ci.pNext = NULL;
11236 ds_layout_ci.bindingCount = 1;
11237 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011238 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011240 ASSERT_VK_SUCCESS(err);
11241
11242 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011243 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011245 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011246 alloc_info.descriptorPool = ds_pool;
11247 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011250
Tony Barboureb254902015-07-15 12:50:33 -060011251 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011252 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11253 sampler_ci.pNext = NULL;
11254 sampler_ci.magFilter = VK_FILTER_NEAREST;
11255 sampler_ci.minFilter = VK_FILTER_NEAREST;
11256 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11257 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11258 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11259 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11260 sampler_ci.mipLodBias = 1.0;
11261 sampler_ci.anisotropyEnable = VK_FALSE;
11262 sampler_ci.maxAnisotropy = 1;
11263 sampler_ci.compareEnable = VK_FALSE;
11264 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11265 sampler_ci.minLod = 1.0;
11266 sampler_ci.maxLod = 1.0;
11267 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11268 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011269
Tobin Ehlis3b780662015-05-28 12:11:26 -060011270 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011271 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011272 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011273
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011274 VkDescriptorImageInfo info = {};
11275 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011276
11277 VkWriteDescriptorSet descriptor_write;
11278 memset(&descriptor_write, 0, sizeof(descriptor_write));
11279 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011280 descriptor_write.dstSet = descriptorSet;
11281 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011282 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011283 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011285 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011286
11287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011289 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011290
Chia-I Wuf7458c52015-10-26 21:10:41 +080011291 vkDestroySampler(m_device->device(), sampler, NULL);
11292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011294}
11295
Karl Schultz6addd812016-02-02 17:17:23 -070011296TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11297 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11298 // types
11299 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 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 -060011302
Tobin Ehlis3b780662015-05-28 12:11:26 -060011303 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011304
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011305 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11307 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011308
11309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11311 ds_pool_ci.pNext = NULL;
11312 ds_pool_ci.maxSets = 1;
11313 ds_pool_ci.poolSizeCount = 1;
11314 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011315
Tobin Ehlis3b780662015-05-28 12:11:26 -060011316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011318 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011319 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011320 dsl_binding.binding = 0;
11321 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11322 dsl_binding.descriptorCount = 1;
11323 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11324 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011325
Tony Barboureb254902015-07-15 12:50:33 -060011326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11328 ds_layout_ci.pNext = NULL;
11329 ds_layout_ci.bindingCount = 1;
11330 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011331
Tobin Ehlis3b780662015-05-28 12:11:26 -060011332 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011334 ASSERT_VK_SUCCESS(err);
11335
11336 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011337 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011339 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011340 alloc_info.descriptorPool = ds_pool;
11341 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011342 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011343 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011344
Tony Barboureb254902015-07-15 12:50:33 -060011345 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011346 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11347 sampler_ci.pNext = NULL;
11348 sampler_ci.magFilter = VK_FILTER_NEAREST;
11349 sampler_ci.minFilter = VK_FILTER_NEAREST;
11350 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11351 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11352 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11353 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11354 sampler_ci.mipLodBias = 1.0;
11355 sampler_ci.anisotropyEnable = VK_FALSE;
11356 sampler_ci.maxAnisotropy = 1;
11357 sampler_ci.compareEnable = VK_FALSE;
11358 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11359 sampler_ci.minLod = 1.0;
11360 sampler_ci.maxLod = 1.0;
11361 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11362 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011363 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011364 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011365 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011366
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011367 VkDescriptorImageInfo info = {};
11368 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011369
11370 VkWriteDescriptorSet descriptor_write;
11371 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011372 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011373 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011374 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011375 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011376 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011377 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011378
11379 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011381 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011382
Chia-I Wuf7458c52015-10-26 21:10:41 +080011383 vkDestroySampler(m_device->device(), sampler, NULL);
11384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011386}
11387
Karl Schultz6addd812016-02-02 17:17:23 -070011388TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011389 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011390 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11393 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011394
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011395 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011396 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11397 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011398 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011399 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11400 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011401
11402 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011403 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11404 ds_pool_ci.pNext = NULL;
11405 ds_pool_ci.maxSets = 1;
11406 ds_pool_ci.poolSizeCount = 1;
11407 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011408
11409 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011410 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011411 ASSERT_VK_SUCCESS(err);
11412
11413 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011414 dsl_binding.binding = 0;
11415 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11416 dsl_binding.descriptorCount = 1;
11417 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11418 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011419
11420 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011421 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11422 ds_layout_ci.pNext = NULL;
11423 ds_layout_ci.bindingCount = 1;
11424 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011425 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011427 ASSERT_VK_SUCCESS(err);
11428
11429 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011430 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011432 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011433 alloc_info.descriptorPool = ds_pool;
11434 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011436 ASSERT_VK_SUCCESS(err);
11437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011439
11440 VkDescriptorImageInfo descriptor_info;
11441 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11442 descriptor_info.sampler = sampler;
11443
11444 VkWriteDescriptorSet descriptor_write;
11445 memset(&descriptor_write, 0, sizeof(descriptor_write));
11446 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011447 descriptor_write.dstSet = descriptorSet;
11448 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011449 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011450 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11451 descriptor_write.pImageInfo = &descriptor_info;
11452
11453 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11454
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011455 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011456
Chia-I Wuf7458c52015-10-26 21:10:41 +080011457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011459}
11460
Karl Schultz6addd812016-02-02 17:17:23 -070011461TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11462 // Create a single combined Image/Sampler descriptor and send it an invalid
11463 // imageView
11464 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11467 "image sampler descriptor failed due "
11468 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011469
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011470 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011472 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11473 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011474
11475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11477 ds_pool_ci.pNext = NULL;
11478 ds_pool_ci.maxSets = 1;
11479 ds_pool_ci.poolSizeCount = 1;
11480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011481
11482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011484 ASSERT_VK_SUCCESS(err);
11485
11486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011487 dsl_binding.binding = 0;
11488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11489 dsl_binding.descriptorCount = 1;
11490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11491 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011492
11493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11495 ds_layout_ci.pNext = NULL;
11496 ds_layout_ci.bindingCount = 1;
11497 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011498 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011500 ASSERT_VK_SUCCESS(err);
11501
11502 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011503 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011505 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011506 alloc_info.descriptorPool = ds_pool;
11507 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011509 ASSERT_VK_SUCCESS(err);
11510
11511 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011512 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11513 sampler_ci.pNext = NULL;
11514 sampler_ci.magFilter = VK_FILTER_NEAREST;
11515 sampler_ci.minFilter = VK_FILTER_NEAREST;
11516 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11517 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11518 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11519 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11520 sampler_ci.mipLodBias = 1.0;
11521 sampler_ci.anisotropyEnable = VK_FALSE;
11522 sampler_ci.maxAnisotropy = 1;
11523 sampler_ci.compareEnable = VK_FALSE;
11524 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11525 sampler_ci.minLod = 1.0;
11526 sampler_ci.maxLod = 1.0;
11527 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11528 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011529
11530 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011531 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011532 ASSERT_VK_SUCCESS(err);
11533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011534 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011535
11536 VkDescriptorImageInfo descriptor_info;
11537 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11538 descriptor_info.sampler = sampler;
11539 descriptor_info.imageView = view;
11540
11541 VkWriteDescriptorSet descriptor_write;
11542 memset(&descriptor_write, 0, sizeof(descriptor_write));
11543 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011544 descriptor_write.dstSet = descriptorSet;
11545 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011546 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011547 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11548 descriptor_write.pImageInfo = &descriptor_info;
11549
11550 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11551
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011552 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011553
Chia-I Wuf7458c52015-10-26 21:10:41 +080011554 vkDestroySampler(m_device->device(), sampler, NULL);
11555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011557}
11558
Karl Schultz6addd812016-02-02 17:17:23 -070011559TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11560 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11561 // into the other
11562 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11565 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11566 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011567
Tobin Ehlis04356f92015-10-27 16:35:27 -060011568 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011569 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011570 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011571 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11572 ds_type_count[0].descriptorCount = 1;
11573 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11574 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011575
11576 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011577 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11578 ds_pool_ci.pNext = NULL;
11579 ds_pool_ci.maxSets = 1;
11580 ds_pool_ci.poolSizeCount = 2;
11581 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011582
11583 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011584 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011585 ASSERT_VK_SUCCESS(err);
11586 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011587 dsl_binding[0].binding = 0;
11588 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11589 dsl_binding[0].descriptorCount = 1;
11590 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11591 dsl_binding[0].pImmutableSamplers = NULL;
11592 dsl_binding[1].binding = 1;
11593 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11594 dsl_binding[1].descriptorCount = 1;
11595 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11596 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011597
11598 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011599 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11600 ds_layout_ci.pNext = NULL;
11601 ds_layout_ci.bindingCount = 2;
11602 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011603
11604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011606 ASSERT_VK_SUCCESS(err);
11607
11608 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011609 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011611 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011612 alloc_info.descriptorPool = ds_pool;
11613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011615 ASSERT_VK_SUCCESS(err);
11616
11617 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011618 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11619 sampler_ci.pNext = NULL;
11620 sampler_ci.magFilter = VK_FILTER_NEAREST;
11621 sampler_ci.minFilter = VK_FILTER_NEAREST;
11622 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11623 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11624 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11625 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11626 sampler_ci.mipLodBias = 1.0;
11627 sampler_ci.anisotropyEnable = VK_FALSE;
11628 sampler_ci.maxAnisotropy = 1;
11629 sampler_ci.compareEnable = VK_FALSE;
11630 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11631 sampler_ci.minLod = 1.0;
11632 sampler_ci.maxLod = 1.0;
11633 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11634 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011635
11636 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011637 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011638 ASSERT_VK_SUCCESS(err);
11639
11640 VkDescriptorImageInfo info = {};
11641 info.sampler = sampler;
11642
11643 VkWriteDescriptorSet descriptor_write;
11644 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11645 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011646 descriptor_write.dstSet = descriptorSet;
11647 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011648 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011649 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11650 descriptor_write.pImageInfo = &info;
11651 // This write update should succeed
11652 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11653 // Now perform a copy update that fails due to type mismatch
11654 VkCopyDescriptorSet copy_ds_update;
11655 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11656 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11657 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011658 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011659 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011660 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011661 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011662 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11663
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011664 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011665 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011666 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 -060011667 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11668 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11669 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011670 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011671 copy_ds_update.dstSet = descriptorSet;
11672 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011673 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011674 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11675
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011676 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011677
Tobin Ehlis04356f92015-10-27 16:35:27 -060011678 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11680 "update array offset of 0 and update of "
11681 "5 descriptors oversteps total number "
11682 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011683
Tobin Ehlis04356f92015-10-27 16:35:27 -060011684 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11685 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11686 copy_ds_update.srcSet = descriptorSet;
11687 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011688 copy_ds_update.dstSet = descriptorSet;
11689 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011690 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011691 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011693 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011694
Chia-I Wuf7458c52015-10-26 21:10:41 +080011695 vkDestroySampler(m_device->device(), sampler, NULL);
11696 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11697 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011698}
11699
Karl Schultz6addd812016-02-02 17:17:23 -070011700TEST_F(VkLayerTest, NumSamplesMismatch) {
11701 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11702 // sampleCount
11703 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011706
Tobin Ehlis3b780662015-05-28 12:11:26 -060011707 ASSERT_NO_FATAL_FAILURE(InitState());
11708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011709 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011711 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011712
11713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11715 ds_pool_ci.pNext = NULL;
11716 ds_pool_ci.maxSets = 1;
11717 ds_pool_ci.poolSizeCount = 1;
11718 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011719
Tobin Ehlis3b780662015-05-28 12:11:26 -060011720 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011721 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011722 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011723
Tony Barboureb254902015-07-15 12:50:33 -060011724 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011725 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011726 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011727 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011728 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11729 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011730
Tony Barboureb254902015-07-15 12:50:33 -060011731 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11732 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11733 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011734 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011735 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011736
Tobin Ehlis3b780662015-05-28 12:11:26 -060011737 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011739 ASSERT_VK_SUCCESS(err);
11740
11741 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011742 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011744 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011745 alloc_info.descriptorPool = ds_pool;
11746 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011748 ASSERT_VK_SUCCESS(err);
11749
Tony Barboureb254902015-07-15 12:50:33 -060011750 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011751 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011752 pipe_ms_state_ci.pNext = NULL;
11753 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11754 pipe_ms_state_ci.sampleShadingEnable = 0;
11755 pipe_ms_state_ci.minSampleShading = 1.0;
11756 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011757
Tony Barboureb254902015-07-15 12:50:33 -060011758 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011759 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11760 pipeline_layout_ci.pNext = NULL;
11761 pipeline_layout_ci.setLayoutCount = 1;
11762 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011763
11764 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011765 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011766 ASSERT_VK_SUCCESS(err);
11767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011768 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11769 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11770 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011771 VkPipelineObj pipe(m_device);
11772 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011773 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011774 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011775 pipe.SetMSAA(&pipe_ms_state_ci);
11776 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011777
Tony Barbourfe3351b2015-07-28 10:17:20 -060011778 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011779 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011780
Mark Young29927482016-05-04 14:38:51 -060011781 // Render triangle (the error should trigger on the attempt to draw).
11782 Draw(3, 1, 0, 0);
11783
11784 // Finalize recording of the command buffer
11785 EndCommandBuffer();
11786
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011787 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011788
Chia-I Wuf7458c52015-10-26 21:10:41 +080011789 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011792}
Mark Young29927482016-05-04 14:38:51 -060011793
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011794TEST_F(VkLayerTest, RenderPassIncompatible) {
11795 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11796 "Initial case is drawing with an active renderpass that's "
11797 "not compatible with the bound PSO's creation renderpass");
11798 VkResult err;
11799
11800 ASSERT_NO_FATAL_FAILURE(InitState());
11801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11802
11803 VkDescriptorSetLayoutBinding dsl_binding = {};
11804 dsl_binding.binding = 0;
11805 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11806 dsl_binding.descriptorCount = 1;
11807 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11808 dsl_binding.pImmutableSamplers = NULL;
11809
11810 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11811 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11812 ds_layout_ci.pNext = NULL;
11813 ds_layout_ci.bindingCount = 1;
11814 ds_layout_ci.pBindings = &dsl_binding;
11815
11816 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011817 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011818 ASSERT_VK_SUCCESS(err);
11819
11820 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11821 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11822 pipeline_layout_ci.pNext = NULL;
11823 pipeline_layout_ci.setLayoutCount = 1;
11824 pipeline_layout_ci.pSetLayouts = &ds_layout;
11825
11826 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011827 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011828 ASSERT_VK_SUCCESS(err);
11829
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011830 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11831 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11832 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011833 // Create a renderpass that will be incompatible with default renderpass
11834 VkAttachmentReference attach = {};
11835 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11836 VkAttachmentReference color_att = {};
11837 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11838 VkSubpassDescription subpass = {};
11839 subpass.inputAttachmentCount = 1;
11840 subpass.pInputAttachments = &attach;
11841 subpass.colorAttachmentCount = 1;
11842 subpass.pColorAttachments = &color_att;
11843 VkRenderPassCreateInfo rpci = {};
11844 rpci.subpassCount = 1;
11845 rpci.pSubpasses = &subpass;
11846 rpci.attachmentCount = 1;
11847 VkAttachmentDescription attach_desc = {};
11848 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011849 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11850 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011851 rpci.pAttachments = &attach_desc;
11852 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11853 VkRenderPass rp;
11854 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11855 VkPipelineObj pipe(m_device);
11856 pipe.AddShader(&vs);
11857 pipe.AddShader(&fs);
11858 pipe.AddColorAttachment();
11859 VkViewport view_port = {};
11860 m_viewports.push_back(view_port);
11861 pipe.SetViewport(m_viewports);
11862 VkRect2D rect = {};
11863 m_scissors.push_back(rect);
11864 pipe.SetScissor(m_scissors);
11865 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11866
11867 VkCommandBufferInheritanceInfo cbii = {};
11868 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11869 cbii.renderPass = rp;
11870 cbii.subpass = 0;
11871 VkCommandBufferBeginInfo cbbi = {};
11872 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11873 cbbi.pInheritanceInfo = &cbii;
11874 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11875 VkRenderPassBeginInfo rpbi = {};
11876 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11877 rpbi.framebuffer = m_framebuffer;
11878 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11880 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011883 // Render triangle (the error should trigger on the attempt to draw).
11884 Draw(3, 1, 0, 0);
11885
11886 // Finalize recording of the command buffer
11887 EndCommandBuffer();
11888
11889 m_errorMonitor->VerifyFound();
11890
11891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11893 vkDestroyRenderPass(m_device->device(), rp, NULL);
11894}
11895
Mark Youngc89c6312016-03-31 16:03:20 -060011896TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11897 // Create Pipeline where the number of blend attachments doesn't match the
11898 // number of color attachments. In this case, we don't add any color
11899 // blend attachments even though we have a color attachment.
11900 VkResult err;
11901
11902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011904
11905 ASSERT_NO_FATAL_FAILURE(InitState());
11906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11907 VkDescriptorPoolSize ds_type_count = {};
11908 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11909 ds_type_count.descriptorCount = 1;
11910
11911 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11912 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11913 ds_pool_ci.pNext = NULL;
11914 ds_pool_ci.maxSets = 1;
11915 ds_pool_ci.poolSizeCount = 1;
11916 ds_pool_ci.pPoolSizes = &ds_type_count;
11917
11918 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011919 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011920 ASSERT_VK_SUCCESS(err);
11921
11922 VkDescriptorSetLayoutBinding dsl_binding = {};
11923 dsl_binding.binding = 0;
11924 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11925 dsl_binding.descriptorCount = 1;
11926 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11927 dsl_binding.pImmutableSamplers = NULL;
11928
11929 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11930 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11931 ds_layout_ci.pNext = NULL;
11932 ds_layout_ci.bindingCount = 1;
11933 ds_layout_ci.pBindings = &dsl_binding;
11934
11935 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011937 ASSERT_VK_SUCCESS(err);
11938
11939 VkDescriptorSet descriptorSet;
11940 VkDescriptorSetAllocateInfo alloc_info = {};
11941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11942 alloc_info.descriptorSetCount = 1;
11943 alloc_info.descriptorPool = ds_pool;
11944 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011946 ASSERT_VK_SUCCESS(err);
11947
11948 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011949 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011950 pipe_ms_state_ci.pNext = NULL;
11951 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11952 pipe_ms_state_ci.sampleShadingEnable = 0;
11953 pipe_ms_state_ci.minSampleShading = 1.0;
11954 pipe_ms_state_ci.pSampleMask = NULL;
11955
11956 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11957 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11958 pipeline_layout_ci.pNext = NULL;
11959 pipeline_layout_ci.setLayoutCount = 1;
11960 pipeline_layout_ci.pSetLayouts = &ds_layout;
11961
11962 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011964 ASSERT_VK_SUCCESS(err);
11965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11967 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11968 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011969 VkPipelineObj pipe(m_device);
11970 pipe.AddShader(&vs);
11971 pipe.AddShader(&fs);
11972 pipe.SetMSAA(&pipe_ms_state_ci);
11973 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11974
11975 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011976 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011977
Mark Young29927482016-05-04 14:38:51 -060011978 // Render triangle (the error should trigger on the attempt to draw).
11979 Draw(3, 1, 0, 0);
11980
11981 // Finalize recording of the command buffer
11982 EndCommandBuffer();
11983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011984 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011985
11986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11989}
Mark Young29927482016-05-04 14:38:51 -060011990
Mark Muellerd4914412016-06-13 17:52:06 -060011991TEST_F(VkLayerTest, MissingClearAttachment) {
11992 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11993 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011994 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011996 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011997
11998 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11999 m_errorMonitor->VerifyFound();
12000}
12001
Karl Schultz6addd812016-02-02 17:17:23 -070012002TEST_F(VkLayerTest, ClearCmdNoDraw) {
12003 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
12004 // to issuing a Draw
12005 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12008 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012009
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012010 ASSERT_NO_FATAL_FAILURE(InitState());
12011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012012
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012013 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12015 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012016
12017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12019 ds_pool_ci.pNext = NULL;
12020 ds_pool_ci.maxSets = 1;
12021 ds_pool_ci.poolSizeCount = 1;
12022 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012023
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012024 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012026 ASSERT_VK_SUCCESS(err);
12027
Tony Barboureb254902015-07-15 12:50:33 -060012028 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012029 dsl_binding.binding = 0;
12030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12031 dsl_binding.descriptorCount = 1;
12032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12033 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012034
Tony Barboureb254902015-07-15 12:50:33 -060012035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12037 ds_layout_ci.pNext = NULL;
12038 ds_layout_ci.bindingCount = 1;
12039 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012040
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012041 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012043 ASSERT_VK_SUCCESS(err);
12044
12045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012046 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012048 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012049 alloc_info.descriptorPool = ds_pool;
12050 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012052 ASSERT_VK_SUCCESS(err);
12053
Tony Barboureb254902015-07-15 12:50:33 -060012054 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012055 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012056 pipe_ms_state_ci.pNext = NULL;
12057 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
12058 pipe_ms_state_ci.sampleShadingEnable = 0;
12059 pipe_ms_state_ci.minSampleShading = 1.0;
12060 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012061
Tony Barboureb254902015-07-15 12:50:33 -060012062 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012063 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12064 pipeline_layout_ci.pNext = NULL;
12065 pipeline_layout_ci.setLayoutCount = 1;
12066 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012067
12068 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012070 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012072 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060012073 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070012074 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012075 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012076
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012077 VkPipelineObj pipe(m_device);
12078 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012079 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012080 pipe.SetMSAA(&pipe_ms_state_ci);
12081 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012082
12083 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012084
Karl Schultz6addd812016-02-02 17:17:23 -070012085 // Main thing we care about for this test is that the VkImage obj we're
12086 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012087 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060012088 VkClearAttachment color_attachment;
12089 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12090 color_attachment.clearValue.color.float32[0] = 1.0;
12091 color_attachment.clearValue.color.float32[1] = 1.0;
12092 color_attachment.clearValue.color.float32[2] = 1.0;
12093 color_attachment.clearValue.color.float32[3] = 1.0;
12094 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012095 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012097 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012098
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012099 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012100
Chia-I Wuf7458c52015-10-26 21:10:41 +080012101 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12102 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12103 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012104}
12105
Karl Schultz6addd812016-02-02 17:17:23 -070012106TEST_F(VkLayerTest, VtxBufferBadIndex) {
12107 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12110 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012111
Tobin Ehlis502480b2015-06-24 15:53:07 -060012112 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012113 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012115
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012116 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012117 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12118 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012119
12120 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012121 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12122 ds_pool_ci.pNext = NULL;
12123 ds_pool_ci.maxSets = 1;
12124 ds_pool_ci.poolSizeCount = 1;
12125 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012126
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012127 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012128 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012129 ASSERT_VK_SUCCESS(err);
12130
Tony Barboureb254902015-07-15 12:50:33 -060012131 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012132 dsl_binding.binding = 0;
12133 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12134 dsl_binding.descriptorCount = 1;
12135 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12136 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012137
Tony Barboureb254902015-07-15 12:50:33 -060012138 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012139 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12140 ds_layout_ci.pNext = NULL;
12141 ds_layout_ci.bindingCount = 1;
12142 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012143
Tobin Ehlis502480b2015-06-24 15:53:07 -060012144 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012146 ASSERT_VK_SUCCESS(err);
12147
12148 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012149 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012150 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012151 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012152 alloc_info.descriptorPool = ds_pool;
12153 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012154 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012155 ASSERT_VK_SUCCESS(err);
12156
Tony Barboureb254902015-07-15 12:50:33 -060012157 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012158 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012159 pipe_ms_state_ci.pNext = NULL;
12160 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12161 pipe_ms_state_ci.sampleShadingEnable = 0;
12162 pipe_ms_state_ci.minSampleShading = 1.0;
12163 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012164
Tony Barboureb254902015-07-15 12:50:33 -060012165 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012166 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12167 pipeline_layout_ci.pNext = NULL;
12168 pipeline_layout_ci.setLayoutCount = 1;
12169 pipeline_layout_ci.pSetLayouts = &ds_layout;
12170 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012173 ASSERT_VK_SUCCESS(err);
12174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012175 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12176 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
12177 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012178 VkPipelineObj pipe(m_device);
12179 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012180 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012181 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012182 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012183 pipe.SetViewport(m_viewports);
12184 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012185 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012186
12187 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012188 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012189 // Don't care about actual data, just need to get to draw to flag error
12190 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012192 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012193 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012194
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012195 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012196
Chia-I Wuf7458c52015-10-26 21:10:41 +080012197 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012200}
Mark Muellerdfe37552016-07-07 14:47:42 -060012201
Mark Mueller2ee294f2016-08-04 12:59:48 -060012202TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
12203 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
12204 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060012205 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
12208 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012210 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
12211 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060012216 // The following test fails with recent NVidia drivers.
12217 // By the time core_validation is reached, the NVidia
12218 // driver has sanitized the invalid condition and core_validation
12219 // is not introduced to the failure condition. This is not the case
12220 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 // uint32_t count = static_cast<uint32_t>(~0);
12222 // VkPhysicalDevice physical_device;
12223 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12224 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012227 float queue_priority = 0.0;
12228
12229 VkDeviceQueueCreateInfo queue_create_info = {};
12230 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12231 queue_create_info.queueCount = 1;
12232 queue_create_info.pQueuePriorities = &queue_priority;
12233 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12234
12235 VkPhysicalDeviceFeatures features = m_device->phy().features();
12236 VkDevice testDevice;
12237 VkDeviceCreateInfo device_create_info = {};
12238 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12239 device_create_info.queueCreateInfoCount = 1;
12240 device_create_info.pQueueCreateInfos = &queue_create_info;
12241 device_create_info.pEnabledFeatures = &features;
12242 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12243 m_errorMonitor->VerifyFound();
12244
12245 queue_create_info.queueFamilyIndex = 1;
12246
12247 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12248 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12249 for (unsigned i = 0; i < feature_count; i++) {
12250 if (VK_FALSE == feature_array[i]) {
12251 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012253 device_create_info.pEnabledFeatures = &features;
12254 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12255 m_errorMonitor->VerifyFound();
12256 break;
12257 }
12258 }
12259}
12260
12261TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12262 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12263 "End a command buffer with a query still in progress.");
12264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12266 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12267 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012269 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012272
12273 ASSERT_NO_FATAL_FAILURE(InitState());
12274
12275 VkEvent event;
12276 VkEventCreateInfo event_create_info{};
12277 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12278 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12279
Mark Mueller2ee294f2016-08-04 12:59:48 -060012280 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012282
12283 BeginCommandBuffer();
12284
12285 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 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 -060012287 ASSERT_TRUE(image.initialized());
12288 VkImageMemoryBarrier img_barrier = {};
12289 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12290 img_barrier.pNext = NULL;
12291 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12292 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12293 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12294 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12295 img_barrier.image = image.handle();
12296 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012297
12298 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12299 // that layer validation catches the case when it is not.
12300 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012301 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12302 img_barrier.subresourceRange.baseArrayLayer = 0;
12303 img_barrier.subresourceRange.baseMipLevel = 0;
12304 img_barrier.subresourceRange.layerCount = 1;
12305 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012306 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12307 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012308 m_errorMonitor->VerifyFound();
12309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012311
12312 VkQueryPool query_pool;
12313 VkQueryPoolCreateInfo query_pool_create_info = {};
12314 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12315 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12316 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012319 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012320 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12321
12322 vkEndCommandBuffer(m_commandBuffer->handle());
12323 m_errorMonitor->VerifyFound();
12324
12325 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12326 vkDestroyEvent(m_device->device(), event, nullptr);
12327}
12328
Mark Muellerdfe37552016-07-07 14:47:42 -060012329TEST_F(VkLayerTest, VertexBufferInvalid) {
12330 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12331 "delete a buffer twice, use an invalid offset for each "
12332 "buffer type, and attempt to bind a null buffer");
12333
12334 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12335 "using deleted buffer ";
12336 const char *double_destroy_message = "Cannot free buffer 0x";
12337 const char *invalid_offset_message = "vkBindBufferMemory(): "
12338 "memoryOffset is 0x";
12339 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12340 "storage memoryOffset "
12341 "is 0x";
12342 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12343 "texel memoryOffset "
12344 "is 0x";
12345 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12346 "uniform memoryOffset "
12347 "is 0x";
12348 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12349 " to Bind Obj(0x";
12350 const char *free_invalid_buffer_message = "Request to delete memory "
12351 "object 0x";
12352
12353 ASSERT_NO_FATAL_FAILURE(InitState());
12354 ASSERT_NO_FATAL_FAILURE(InitViewport());
12355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12356
12357 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012359 pipe_ms_state_ci.pNext = NULL;
12360 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12361 pipe_ms_state_ci.sampleShadingEnable = 0;
12362 pipe_ms_state_ci.minSampleShading = 1.0;
12363 pipe_ms_state_ci.pSampleMask = nullptr;
12364
12365 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12366 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12367 VkPipelineLayout pipeline_layout;
12368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012370 ASSERT_VK_SUCCESS(err);
12371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012372 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12373 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012374 VkPipelineObj pipe(m_device);
12375 pipe.AddShader(&vs);
12376 pipe.AddShader(&fs);
12377 pipe.AddColorAttachment();
12378 pipe.SetMSAA(&pipe_ms_state_ci);
12379 pipe.SetViewport(m_viewports);
12380 pipe.SetScissor(m_scissors);
12381 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12382
12383 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012384 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012385
12386 {
12387 // Create and bind a vertex buffer in a reduced scope, which will cause
12388 // it to be deleted upon leaving this scope
12389 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012390 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012391 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12392 draw_verticies.AddVertexInputToPipe(pipe);
12393 }
12394
12395 Draw(1, 0, 0, 0);
12396
12397 EndCommandBuffer();
12398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012400 QueueCommandBuffer(false);
12401 m_errorMonitor->VerifyFound();
12402
12403 {
12404 // Create and bind a vertex buffer in a reduced scope, and delete it
12405 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012406 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012408 buffer_test.TestDoubleDestroy();
12409 }
12410 m_errorMonitor->VerifyFound();
12411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012413 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12415 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12416 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012417 m_errorMonitor->VerifyFound();
12418 }
12419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012420 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12421 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012422 // Create and bind a memory buffer with an invalid offset again,
12423 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12425 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12426 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012427 m_errorMonitor->VerifyFound();
12428 }
12429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012430 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012431 // Create and bind a memory buffer with an invalid offset again, but
12432 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12434 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12435 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012436 m_errorMonitor->VerifyFound();
12437 }
12438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012439 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012440 // Create and bind a memory buffer with an invalid offset again, but
12441 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12443 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12444 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012445 m_errorMonitor->VerifyFound();
12446 }
12447
12448 {
12449 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12451 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12452 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012453 m_errorMonitor->VerifyFound();
12454 }
12455
12456 {
12457 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12459 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12460 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012461 }
12462 m_errorMonitor->VerifyFound();
12463
12464 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12465}
12466
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012467// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12468TEST_F(VkLayerTest, InvalidImageLayout) {
12469 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012470 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12471 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012472 // 3 in ValidateCmdBufImageLayouts
12473 // * -1 Attempt to submit cmd buf w/ deleted image
12474 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12475 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12477 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012478
12479 ASSERT_NO_FATAL_FAILURE(InitState());
12480 // Create src & dst images to use for copy operations
12481 VkImage src_image;
12482 VkImage dst_image;
12483
12484 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12485 const int32_t tex_width = 32;
12486 const int32_t tex_height = 32;
12487
12488 VkImageCreateInfo image_create_info = {};
12489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12490 image_create_info.pNext = NULL;
12491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12492 image_create_info.format = tex_format;
12493 image_create_info.extent.width = tex_width;
12494 image_create_info.extent.height = tex_height;
12495 image_create_info.extent.depth = 1;
12496 image_create_info.mipLevels = 1;
12497 image_create_info.arrayLayers = 4;
12498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12499 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12500 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12501 image_create_info.flags = 0;
12502
12503 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12504 ASSERT_VK_SUCCESS(err);
12505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12506 ASSERT_VK_SUCCESS(err);
12507
12508 BeginCommandBuffer();
12509 VkImageCopy copyRegion;
12510 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12511 copyRegion.srcSubresource.mipLevel = 0;
12512 copyRegion.srcSubresource.baseArrayLayer = 0;
12513 copyRegion.srcSubresource.layerCount = 1;
12514 copyRegion.srcOffset.x = 0;
12515 copyRegion.srcOffset.y = 0;
12516 copyRegion.srcOffset.z = 0;
12517 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12518 copyRegion.dstSubresource.mipLevel = 0;
12519 copyRegion.dstSubresource.baseArrayLayer = 0;
12520 copyRegion.dstSubresource.layerCount = 1;
12521 copyRegion.dstOffset.x = 0;
12522 copyRegion.dstOffset.y = 0;
12523 copyRegion.dstOffset.z = 0;
12524 copyRegion.extent.width = 1;
12525 copyRegion.extent.height = 1;
12526 copyRegion.extent.depth = 1;
12527 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12528 m_errorMonitor->VerifyFound();
12529 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12531 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12532 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012533 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12534 m_errorMonitor->VerifyFound();
12535 // Final src error is due to bad layout type
12536 m_errorMonitor->SetDesiredFailureMsg(
12537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12538 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12539 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12540 m_errorMonitor->VerifyFound();
12541 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12543 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012544 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12545 m_errorMonitor->VerifyFound();
12546 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12548 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12549 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012550 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12551 m_errorMonitor->VerifyFound();
12552 m_errorMonitor->SetDesiredFailureMsg(
12553 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12554 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12555 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12556 m_errorMonitor->VerifyFound();
12557 // Now cause error due to bad image layout transition in PipelineBarrier
12558 VkImageMemoryBarrier image_barrier[1] = {};
12559 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12560 image_barrier[0].image = src_image;
12561 image_barrier[0].subresourceRange.layerCount = 2;
12562 image_barrier[0].subresourceRange.levelCount = 2;
12563 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12565 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12566 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12567 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12568 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012569 m_errorMonitor->VerifyFound();
12570
12571 // Finally some layout errors at RenderPass create time
12572 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12573 VkAttachmentReference attach = {};
12574 // perf warning for GENERAL layout w/ non-DS input attachment
12575 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12576 VkSubpassDescription subpass = {};
12577 subpass.inputAttachmentCount = 1;
12578 subpass.pInputAttachments = &attach;
12579 VkRenderPassCreateInfo rpci = {};
12580 rpci.subpassCount = 1;
12581 rpci.pSubpasses = &subpass;
12582 rpci.attachmentCount = 1;
12583 VkAttachmentDescription attach_desc = {};
12584 attach_desc.format = VK_FORMAT_UNDEFINED;
12585 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012586 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012587 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12589 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012590 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12591 m_errorMonitor->VerifyFound();
12592 // error w/ non-general layout
12593 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12594
12595 m_errorMonitor->SetDesiredFailureMsg(
12596 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12597 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12598 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12599 m_errorMonitor->VerifyFound();
12600 subpass.inputAttachmentCount = 0;
12601 subpass.colorAttachmentCount = 1;
12602 subpass.pColorAttachments = &attach;
12603 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12604 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12606 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012607 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12608 m_errorMonitor->VerifyFound();
12609 // error w/ non-color opt or GENERAL layout for color attachment
12610 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12611 m_errorMonitor->SetDesiredFailureMsg(
12612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12613 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12614 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12615 m_errorMonitor->VerifyFound();
12616 subpass.colorAttachmentCount = 0;
12617 subpass.pDepthStencilAttachment = &attach;
12618 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12619 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12621 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012622 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12623 m_errorMonitor->VerifyFound();
12624 // error w/ non-ds opt or GENERAL layout for color attachment
12625 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12627 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12628 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012629 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12630 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012631 // For this error we need a valid renderpass so create default one
12632 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12633 attach.attachment = 0;
12634 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12635 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12636 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12637 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12638 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12639 // Can't do a CLEAR load on READ_ONLY initialLayout
12640 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12641 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12642 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12644 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12645 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012646 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12647 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012648
12649 vkDestroyImage(m_device->device(), src_image, NULL);
12650 vkDestroyImage(m_device->device(), dst_image, NULL);
12651}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012652
12653TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12654 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12655 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12656 "has a valid layout, and a second subpass then uses a "
12657 "valid *READ_ONLY* layout.");
12658 m_errorMonitor->ExpectSuccess();
12659 ASSERT_NO_FATAL_FAILURE(InitState());
12660
12661 VkAttachmentReference attach[2] = {};
12662 attach[0].attachment = 0;
12663 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12664 attach[1].attachment = 0;
12665 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12666 VkSubpassDescription subpasses[2] = {};
12667 // First subpass clears DS attach on load
12668 subpasses[0].pDepthStencilAttachment = &attach[0];
12669 // 2nd subpass reads in DS as input attachment
12670 subpasses[1].inputAttachmentCount = 1;
12671 subpasses[1].pInputAttachments = &attach[1];
12672 VkAttachmentDescription attach_desc = {};
12673 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12674 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12675 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12676 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12677 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12678 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012679 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012680 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12681 VkRenderPassCreateInfo rpci = {};
12682 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12683 rpci.attachmentCount = 1;
12684 rpci.pAttachments = &attach_desc;
12685 rpci.subpassCount = 2;
12686 rpci.pSubpasses = subpasses;
12687
12688 // Now create RenderPass and verify no errors
12689 VkRenderPass rp;
12690 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12691 m_errorMonitor->VerifyNotFound();
12692
12693 vkDestroyRenderPass(m_device->device(), rp, NULL);
12694}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012695
Mark Mueller93b938f2016-08-18 10:27:40 -060012696TEST_F(VkLayerTest, SimultaneousUse) {
12697 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12698 "in primary and secondary command buffers.");
12699
12700 ASSERT_NO_FATAL_FAILURE(InitState());
12701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012703 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12704 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12705 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012706
12707 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012708 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012709 command_buffer_allocate_info.commandPool = m_commandPool;
12710 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12711 command_buffer_allocate_info.commandBufferCount = 1;
12712
12713 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012714 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012715 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12716 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012717 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012718 command_buffer_inheritance_info.renderPass = m_renderPass;
12719 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12720 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012721 command_buffer_begin_info.flags =
12722 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012723 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12724
12725 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012726 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12727 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012728 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012729 vkEndCommandBuffer(secondary_command_buffer);
12730
Mark Mueller93b938f2016-08-18 10:27:40 -060012731 VkSubmitInfo submit_info = {};
12732 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12733 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012734 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012735 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012736
Mark Mueller4042b652016-09-05 22:52:21 -060012737 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012738 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12740 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012741 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012742 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12743 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012744
12745 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12747
Mark Mueller4042b652016-09-05 22:52:21 -060012748 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012749 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012750 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12753 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012754 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012755 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12756 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012757}
12758
Mark Mueller917f6bc2016-08-30 10:57:19 -060012759TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12760 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12761 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012762 "Delete objects that are inuse. Call VkQueueSubmit "
12763 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012764
12765 ASSERT_NO_FATAL_FAILURE(InitState());
12766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012768 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12769 const char *cannot_delete_event_message = "Cannot delete event 0x";
12770 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12771 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012772
12773 BeginCommandBuffer();
12774
12775 VkEvent event;
12776 VkEventCreateInfo event_create_info = {};
12777 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12778 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012779 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012780
Mark Muellerc8d441e2016-08-23 17:36:00 -060012781 EndCommandBuffer();
12782 vkDestroyEvent(m_device->device(), event, nullptr);
12783
12784 VkSubmitInfo submit_info = {};
12785 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12786 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012787 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012789 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12790 m_errorMonitor->VerifyFound();
12791
12792 m_errorMonitor->SetDesiredFailureMsg(0, "");
12793 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12794
12795 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12796
Mark Mueller917f6bc2016-08-30 10:57:19 -060012797 VkSemaphoreCreateInfo semaphore_create_info = {};
12798 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12799 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012800 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012801 VkFenceCreateInfo fence_create_info = {};
12802 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12803 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012804 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012805
12806 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012807 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012808 descriptor_pool_type_count.descriptorCount = 1;
12809
12810 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12811 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12812 descriptor_pool_create_info.maxSets = 1;
12813 descriptor_pool_create_info.poolSizeCount = 1;
12814 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012815 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012816
12817 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012818 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012819
12820 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012821 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012822 descriptorset_layout_binding.descriptorCount = 1;
12823 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12824
12825 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012826 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012827 descriptorset_layout_create_info.bindingCount = 1;
12828 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12829
12830 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012831 ASSERT_VK_SUCCESS(
12832 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012833
12834 VkDescriptorSet descriptorset;
12835 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012836 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012837 descriptorset_allocate_info.descriptorSetCount = 1;
12838 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12839 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012840 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012841
Mark Mueller4042b652016-09-05 22:52:21 -060012842 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12843
12844 VkDescriptorBufferInfo buffer_info = {};
12845 buffer_info.buffer = buffer_test.GetBuffer();
12846 buffer_info.offset = 0;
12847 buffer_info.range = 1024;
12848
12849 VkWriteDescriptorSet write_descriptor_set = {};
12850 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12851 write_descriptor_set.dstSet = descriptorset;
12852 write_descriptor_set.descriptorCount = 1;
12853 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12854 write_descriptor_set.pBufferInfo = &buffer_info;
12855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012856 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012858 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12859 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012860
12861 VkPipelineObj pipe(m_device);
12862 pipe.AddColorAttachment();
12863 pipe.AddShader(&vs);
12864 pipe.AddShader(&fs);
12865
12866 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012867 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012868 pipeline_layout_create_info.setLayoutCount = 1;
12869 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12870
12871 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012872 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012873
12874 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12875
Mark Muellerc8d441e2016-08-23 17:36:00 -060012876 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012877 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12880 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12881 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012882
Mark Muellerc8d441e2016-08-23 17:36:00 -060012883 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012884
Mark Mueller917f6bc2016-08-30 10:57:19 -060012885 submit_info.signalSemaphoreCount = 1;
12886 submit_info.pSignalSemaphores = &semaphore;
12887 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012890 vkDestroyEvent(m_device->device(), event, nullptr);
12891 m_errorMonitor->VerifyFound();
12892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012894 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12895 m_errorMonitor->VerifyFound();
12896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012898 vkDestroyFence(m_device->device(), fence, nullptr);
12899 m_errorMonitor->VerifyFound();
12900
Tobin Ehlis122207b2016-09-01 08:50:06 -070012901 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012902 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12903 vkDestroyFence(m_device->device(), fence, nullptr);
12904 vkDestroyEvent(m_device->device(), event, nullptr);
12905 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012906 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012907 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12908}
12909
Tobin Ehlis2adda372016-09-01 08:51:06 -070012910TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12911 TEST_DESCRIPTION("Delete in-use query pool.");
12912
12913 ASSERT_NO_FATAL_FAILURE(InitState());
12914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12915
12916 VkQueryPool query_pool;
12917 VkQueryPoolCreateInfo query_pool_ci{};
12918 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12919 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12920 query_pool_ci.queryCount = 1;
12921 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12922 BeginCommandBuffer();
12923 // Reset query pool to create binding with cmd buffer
12924 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12925
12926 EndCommandBuffer();
12927
12928 VkSubmitInfo submit_info = {};
12929 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12930 submit_info.commandBufferCount = 1;
12931 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12932 // Submit cmd buffer and then destroy query pool while in-flight
12933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012936 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12937 m_errorMonitor->VerifyFound();
12938
12939 vkQueueWaitIdle(m_device->m_queue);
12940 // Now that cmd buffer done we can safely destroy query_pool
12941 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12942}
12943
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012944TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12945 TEST_DESCRIPTION("Delete in-use pipeline.");
12946
12947 ASSERT_NO_FATAL_FAILURE(InitState());
12948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12949
12950 // Empty pipeline layout used for binding PSO
12951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12953 pipeline_layout_ci.setLayoutCount = 0;
12954 pipeline_layout_ci.pSetLayouts = NULL;
12955
12956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012958 ASSERT_VK_SUCCESS(err);
12959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012961 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012962 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12963 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012964 // Store pipeline handle so we can actually delete it before test finishes
12965 VkPipeline delete_this_pipeline;
12966 { // Scope pipeline so it will be auto-deleted
12967 VkPipelineObj pipe(m_device);
12968 pipe.AddShader(&vs);
12969 pipe.AddShader(&fs);
12970 pipe.AddColorAttachment();
12971 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12972 delete_this_pipeline = pipe.handle();
12973
12974 BeginCommandBuffer();
12975 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012976 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012977
12978 EndCommandBuffer();
12979
12980 VkSubmitInfo submit_info = {};
12981 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12982 submit_info.commandBufferCount = 1;
12983 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12984 // Submit cmd buffer and then pipeline destroyed while in-flight
12985 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12986 } // Pipeline deletion triggered here
12987 m_errorMonitor->VerifyFound();
12988 // Make sure queue finished and then actually delete pipeline
12989 vkQueueWaitIdle(m_device->m_queue);
12990 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12991 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12992}
12993
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012994TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12995 TEST_DESCRIPTION("Delete in-use imageView.");
12996
12997 ASSERT_NO_FATAL_FAILURE(InitState());
12998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12999
13000 VkDescriptorPoolSize ds_type_count;
13001 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13002 ds_type_count.descriptorCount = 1;
13003
13004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13006 ds_pool_ci.maxSets = 1;
13007 ds_pool_ci.poolSizeCount = 1;
13008 ds_pool_ci.pPoolSizes = &ds_type_count;
13009
13010 VkDescriptorPool ds_pool;
13011 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13012 ASSERT_VK_SUCCESS(err);
13013
13014 VkSamplerCreateInfo sampler_ci = {};
13015 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13016 sampler_ci.pNext = NULL;
13017 sampler_ci.magFilter = VK_FILTER_NEAREST;
13018 sampler_ci.minFilter = VK_FILTER_NEAREST;
13019 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13020 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13021 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13022 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13023 sampler_ci.mipLodBias = 1.0;
13024 sampler_ci.anisotropyEnable = VK_FALSE;
13025 sampler_ci.maxAnisotropy = 1;
13026 sampler_ci.compareEnable = VK_FALSE;
13027 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13028 sampler_ci.minLod = 1.0;
13029 sampler_ci.maxLod = 1.0;
13030 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13031 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13032 VkSampler sampler;
13033
13034 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13035 ASSERT_VK_SUCCESS(err);
13036
13037 VkDescriptorSetLayoutBinding layout_binding;
13038 layout_binding.binding = 0;
13039 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13040 layout_binding.descriptorCount = 1;
13041 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13042 layout_binding.pImmutableSamplers = NULL;
13043
13044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13046 ds_layout_ci.bindingCount = 1;
13047 ds_layout_ci.pBindings = &layout_binding;
13048 VkDescriptorSetLayout ds_layout;
13049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13050 ASSERT_VK_SUCCESS(err);
13051
13052 VkDescriptorSetAllocateInfo alloc_info = {};
13053 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13054 alloc_info.descriptorSetCount = 1;
13055 alloc_info.descriptorPool = ds_pool;
13056 alloc_info.pSetLayouts = &ds_layout;
13057 VkDescriptorSet descriptor_set;
13058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13059 ASSERT_VK_SUCCESS(err);
13060
13061 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13062 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13063 pipeline_layout_ci.pNext = NULL;
13064 pipeline_layout_ci.setLayoutCount = 1;
13065 pipeline_layout_ci.pSetLayouts = &ds_layout;
13066
13067 VkPipelineLayout pipeline_layout;
13068 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13069 ASSERT_VK_SUCCESS(err);
13070
13071 VkImageObj image(m_device);
13072 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
13073 ASSERT_TRUE(image.initialized());
13074
13075 VkImageView view;
13076 VkImageViewCreateInfo ivci = {};
13077 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13078 ivci.image = image.handle();
13079 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13080 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13081 ivci.subresourceRange.layerCount = 1;
13082 ivci.subresourceRange.baseMipLevel = 0;
13083 ivci.subresourceRange.levelCount = 1;
13084 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13085
13086 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13087 ASSERT_VK_SUCCESS(err);
13088
13089 VkDescriptorImageInfo image_info{};
13090 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13091 image_info.imageView = view;
13092 image_info.sampler = sampler;
13093
13094 VkWriteDescriptorSet descriptor_write = {};
13095 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13096 descriptor_write.dstSet = descriptor_set;
13097 descriptor_write.dstBinding = 0;
13098 descriptor_write.descriptorCount = 1;
13099 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13100 descriptor_write.pImageInfo = &image_info;
13101
13102 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13103
13104 // Create PSO to use the sampler
13105 char const *vsSource = "#version 450\n"
13106 "\n"
13107 "out gl_PerVertex { \n"
13108 " vec4 gl_Position;\n"
13109 "};\n"
13110 "void main(){\n"
13111 " gl_Position = vec4(1);\n"
13112 "}\n";
13113 char const *fsSource = "#version 450\n"
13114 "\n"
13115 "layout(set=0, binding=0) uniform sampler2D s;\n"
13116 "layout(location=0) out vec4 x;\n"
13117 "void main(){\n"
13118 " x = texture(s, vec2(1));\n"
13119 "}\n";
13120 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13121 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13122 VkPipelineObj pipe(m_device);
13123 pipe.AddShader(&vs);
13124 pipe.AddShader(&fs);
13125 pipe.AddColorAttachment();
13126 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13127
13128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
13129
13130 BeginCommandBuffer();
13131 // Bind pipeline to cmd buffer
13132 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13133 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13134 &descriptor_set, 0, nullptr);
13135 Draw(1, 0, 0, 0);
13136 EndCommandBuffer();
13137 // Submit cmd buffer then destroy sampler
13138 VkSubmitInfo submit_info = {};
13139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13140 submit_info.commandBufferCount = 1;
13141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13142 // Submit cmd buffer and then destroy imageView while in-flight
13143 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13144
13145 vkDestroyImageView(m_device->device(), view, nullptr);
13146 m_errorMonitor->VerifyFound();
13147 vkQueueWaitIdle(m_device->m_queue);
13148 // Now we can actually destroy imageView
13149 vkDestroyImageView(m_device->device(), view, NULL);
13150 vkDestroySampler(m_device->device(), sampler, nullptr);
13151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13154}
13155
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013156TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13157 TEST_DESCRIPTION("Delete in-use bufferView.");
13158
13159 ASSERT_NO_FATAL_FAILURE(InitState());
13160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13161
13162 VkDescriptorPoolSize ds_type_count;
13163 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13164 ds_type_count.descriptorCount = 1;
13165
13166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13168 ds_pool_ci.maxSets = 1;
13169 ds_pool_ci.poolSizeCount = 1;
13170 ds_pool_ci.pPoolSizes = &ds_type_count;
13171
13172 VkDescriptorPool ds_pool;
13173 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13174 ASSERT_VK_SUCCESS(err);
13175
13176 VkDescriptorSetLayoutBinding layout_binding;
13177 layout_binding.binding = 0;
13178 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13179 layout_binding.descriptorCount = 1;
13180 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13181 layout_binding.pImmutableSamplers = NULL;
13182
13183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13185 ds_layout_ci.bindingCount = 1;
13186 ds_layout_ci.pBindings = &layout_binding;
13187 VkDescriptorSetLayout ds_layout;
13188 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13189 ASSERT_VK_SUCCESS(err);
13190
13191 VkDescriptorSetAllocateInfo alloc_info = {};
13192 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13193 alloc_info.descriptorSetCount = 1;
13194 alloc_info.descriptorPool = ds_pool;
13195 alloc_info.pSetLayouts = &ds_layout;
13196 VkDescriptorSet descriptor_set;
13197 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13198 ASSERT_VK_SUCCESS(err);
13199
13200 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13201 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13202 pipeline_layout_ci.pNext = NULL;
13203 pipeline_layout_ci.setLayoutCount = 1;
13204 pipeline_layout_ci.pSetLayouts = &ds_layout;
13205
13206 VkPipelineLayout pipeline_layout;
13207 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13208 ASSERT_VK_SUCCESS(err);
13209
13210 VkBuffer buffer;
13211 uint32_t queue_family_index = 0;
13212 VkBufferCreateInfo buffer_create_info = {};
13213 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13214 buffer_create_info.size = 1024;
13215 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13216 buffer_create_info.queueFamilyIndexCount = 1;
13217 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13218
13219 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13220 ASSERT_VK_SUCCESS(err);
13221
13222 VkMemoryRequirements memory_reqs;
13223 VkDeviceMemory buffer_memory;
13224
13225 VkMemoryAllocateInfo memory_info = {};
13226 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13227 memory_info.allocationSize = 0;
13228 memory_info.memoryTypeIndex = 0;
13229
13230 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13231 memory_info.allocationSize = memory_reqs.size;
13232 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13233 ASSERT_TRUE(pass);
13234
13235 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13236 ASSERT_VK_SUCCESS(err);
13237 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13238 ASSERT_VK_SUCCESS(err);
13239
13240 VkBufferView view;
13241 VkBufferViewCreateInfo bvci = {};
13242 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13243 bvci.buffer = buffer;
13244 bvci.format = VK_FORMAT_R8_UNORM;
13245 bvci.range = VK_WHOLE_SIZE;
13246
13247 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13248 ASSERT_VK_SUCCESS(err);
13249
13250 VkWriteDescriptorSet descriptor_write = {};
13251 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13252 descriptor_write.dstSet = descriptor_set;
13253 descriptor_write.dstBinding = 0;
13254 descriptor_write.descriptorCount = 1;
13255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13256 descriptor_write.pTexelBufferView = &view;
13257
13258 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13259
13260 char const *vsSource = "#version 450\n"
13261 "\n"
13262 "out gl_PerVertex { \n"
13263 " vec4 gl_Position;\n"
13264 "};\n"
13265 "void main(){\n"
13266 " gl_Position = vec4(1);\n"
13267 "}\n";
13268 char const *fsSource = "#version 450\n"
13269 "\n"
13270 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13271 "layout(location=0) out vec4 x;\n"
13272 "void main(){\n"
13273 " x = imageLoad(s, 0);\n"
13274 "}\n";
13275 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13276 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13277 VkPipelineObj pipe(m_device);
13278 pipe.AddShader(&vs);
13279 pipe.AddShader(&fs);
13280 pipe.AddColorAttachment();
13281 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13282
13283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
13284
13285 BeginCommandBuffer();
13286 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13287 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13288 VkRect2D scissor = {{0, 0}, {16, 16}};
13289 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13290 // Bind pipeline to cmd buffer
13291 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13292 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13293 &descriptor_set, 0, nullptr);
13294 Draw(1, 0, 0, 0);
13295 EndCommandBuffer();
13296
13297 VkSubmitInfo submit_info = {};
13298 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13299 submit_info.commandBufferCount = 1;
13300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13301 // Submit cmd buffer and then destroy bufferView while in-flight
13302 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13303
13304 vkDestroyBufferView(m_device->device(), view, nullptr);
13305 m_errorMonitor->VerifyFound();
13306 vkQueueWaitIdle(m_device->m_queue);
13307 // Now we can actually destroy bufferView
13308 vkDestroyBufferView(m_device->device(), view, NULL);
13309 vkDestroyBuffer(m_device->device(), buffer, NULL);
13310 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13311 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13312 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13313 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13314}
13315
Tobin Ehlis209532e2016-09-07 13:52:18 -060013316TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13317 TEST_DESCRIPTION("Delete in-use sampler.");
13318
13319 ASSERT_NO_FATAL_FAILURE(InitState());
13320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13321
13322 VkDescriptorPoolSize ds_type_count;
13323 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13324 ds_type_count.descriptorCount = 1;
13325
13326 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13327 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13328 ds_pool_ci.maxSets = 1;
13329 ds_pool_ci.poolSizeCount = 1;
13330 ds_pool_ci.pPoolSizes = &ds_type_count;
13331
13332 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013333 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013334 ASSERT_VK_SUCCESS(err);
13335
13336 VkSamplerCreateInfo sampler_ci = {};
13337 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13338 sampler_ci.pNext = NULL;
13339 sampler_ci.magFilter = VK_FILTER_NEAREST;
13340 sampler_ci.minFilter = VK_FILTER_NEAREST;
13341 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13342 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13343 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13344 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13345 sampler_ci.mipLodBias = 1.0;
13346 sampler_ci.anisotropyEnable = VK_FALSE;
13347 sampler_ci.maxAnisotropy = 1;
13348 sampler_ci.compareEnable = VK_FALSE;
13349 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13350 sampler_ci.minLod = 1.0;
13351 sampler_ci.maxLod = 1.0;
13352 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13353 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13354 VkSampler sampler;
13355
13356 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13357 ASSERT_VK_SUCCESS(err);
13358
13359 VkDescriptorSetLayoutBinding layout_binding;
13360 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013361 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013362 layout_binding.descriptorCount = 1;
13363 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13364 layout_binding.pImmutableSamplers = NULL;
13365
13366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13368 ds_layout_ci.bindingCount = 1;
13369 ds_layout_ci.pBindings = &layout_binding;
13370 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013371 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013372 ASSERT_VK_SUCCESS(err);
13373
13374 VkDescriptorSetAllocateInfo alloc_info = {};
13375 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13376 alloc_info.descriptorSetCount = 1;
13377 alloc_info.descriptorPool = ds_pool;
13378 alloc_info.pSetLayouts = &ds_layout;
13379 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013380 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013381 ASSERT_VK_SUCCESS(err);
13382
13383 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13384 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13385 pipeline_layout_ci.pNext = NULL;
13386 pipeline_layout_ci.setLayoutCount = 1;
13387 pipeline_layout_ci.pSetLayouts = &ds_layout;
13388
13389 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013391 ASSERT_VK_SUCCESS(err);
13392
13393 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013394 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 -060013395 ASSERT_TRUE(image.initialized());
13396
13397 VkImageView view;
13398 VkImageViewCreateInfo ivci = {};
13399 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13400 ivci.image = image.handle();
13401 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13402 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13403 ivci.subresourceRange.layerCount = 1;
13404 ivci.subresourceRange.baseMipLevel = 0;
13405 ivci.subresourceRange.levelCount = 1;
13406 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13407
13408 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13409 ASSERT_VK_SUCCESS(err);
13410
13411 VkDescriptorImageInfo image_info{};
13412 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13413 image_info.imageView = view;
13414 image_info.sampler = sampler;
13415
13416 VkWriteDescriptorSet descriptor_write = {};
13417 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13418 descriptor_write.dstSet = descriptor_set;
13419 descriptor_write.dstBinding = 0;
13420 descriptor_write.descriptorCount = 1;
13421 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13422 descriptor_write.pImageInfo = &image_info;
13423
13424 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13425
13426 // Create PSO to use the sampler
13427 char const *vsSource = "#version 450\n"
13428 "\n"
13429 "out gl_PerVertex { \n"
13430 " vec4 gl_Position;\n"
13431 "};\n"
13432 "void main(){\n"
13433 " gl_Position = vec4(1);\n"
13434 "}\n";
13435 char const *fsSource = "#version 450\n"
13436 "\n"
13437 "layout(set=0, binding=0) uniform sampler2D s;\n"
13438 "layout(location=0) out vec4 x;\n"
13439 "void main(){\n"
13440 " x = texture(s, vec2(1));\n"
13441 "}\n";
13442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13444 VkPipelineObj pipe(m_device);
13445 pipe.AddShader(&vs);
13446 pipe.AddShader(&fs);
13447 pipe.AddColorAttachment();
13448 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060013451
13452 BeginCommandBuffer();
13453 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013454 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13455 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13456 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013457 Draw(1, 0, 0, 0);
13458 EndCommandBuffer();
13459 // Submit cmd buffer then destroy sampler
13460 VkSubmitInfo submit_info = {};
13461 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13462 submit_info.commandBufferCount = 1;
13463 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13464 // Submit cmd buffer and then destroy sampler while in-flight
13465 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13466
13467 vkDestroySampler(m_device->device(), sampler, nullptr);
13468 m_errorMonitor->VerifyFound();
13469 vkQueueWaitIdle(m_device->m_queue);
13470 // Now we can actually destroy sampler
13471 vkDestroySampler(m_device->device(), sampler, nullptr);
13472 vkDestroyImageView(m_device->device(), view, NULL);
13473 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13474 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13475 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13476}
13477
Mark Mueller1cd9f412016-08-25 13:23:52 -060013478TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060013479 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060013480 "signaled but not waited on by the queue. Wait on a "
13481 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013482
13483 ASSERT_NO_FATAL_FAILURE(InitState());
13484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013486 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
13487 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
13488 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013489
13490 BeginCommandBuffer();
13491 EndCommandBuffer();
13492
13493 VkSemaphoreCreateInfo semaphore_create_info = {};
13494 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13495 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013496 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013497 VkSubmitInfo submit_info = {};
13498 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13499 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013500 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013501 submit_info.signalSemaphoreCount = 1;
13502 submit_info.pSignalSemaphores = &semaphore;
13503 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13504 m_errorMonitor->SetDesiredFailureMsg(0, "");
13505 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
13506 BeginCommandBuffer();
13507 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013509 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13510 m_errorMonitor->VerifyFound();
13511
Mark Mueller1cd9f412016-08-25 13:23:52 -060013512 VkFenceCreateInfo fence_create_info = {};
13513 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13514 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013515 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013518 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13519 m_errorMonitor->VerifyFound();
13520
Mark Mueller4042b652016-09-05 22:52:21 -060013521 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013522 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013523 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13524}
13525
Tobin Ehlis4af23302016-07-19 10:50:30 -060013526TEST_F(VkLayerTest, FramebufferIncompatible) {
13527 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
13528 "that does not match the framebuffer for the active "
13529 "renderpass.");
13530 ASSERT_NO_FATAL_FAILURE(InitState());
13531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13532
13533 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013534 VkAttachmentDescription attachment = {0,
13535 VK_FORMAT_B8G8R8A8_UNORM,
13536 VK_SAMPLE_COUNT_1_BIT,
13537 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13538 VK_ATTACHMENT_STORE_OP_STORE,
13539 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13540 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13541 VK_IMAGE_LAYOUT_UNDEFINED,
13542 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013546 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013548 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013549
13550 VkRenderPass rp;
13551 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13552 ASSERT_VK_SUCCESS(err);
13553
13554 // A compatible framebuffer.
13555 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013556 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 -060013557 ASSERT_TRUE(image.initialized());
13558
13559 VkImageViewCreateInfo ivci = {
13560 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13561 nullptr,
13562 0,
13563 image.handle(),
13564 VK_IMAGE_VIEW_TYPE_2D,
13565 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013566 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13567 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013568 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13569 };
13570 VkImageView view;
13571 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13572 ASSERT_VK_SUCCESS(err);
13573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013574 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013575 VkFramebuffer fb;
13576 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13577 ASSERT_VK_SUCCESS(err);
13578
13579 VkCommandBufferAllocateInfo cbai = {};
13580 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13581 cbai.commandPool = m_commandPool;
13582 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13583 cbai.commandBufferCount = 1;
13584
13585 VkCommandBuffer sec_cb;
13586 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13587 ASSERT_VK_SUCCESS(err);
13588 VkCommandBufferBeginInfo cbbi = {};
13589 VkCommandBufferInheritanceInfo cbii = {};
13590 cbii.renderPass = renderPass();
13591 cbii.framebuffer = fb;
13592 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13593 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013594 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 -060013595 cbbi.pInheritanceInfo = &cbii;
13596 vkBeginCommandBuffer(sec_cb, &cbbi);
13597 vkEndCommandBuffer(sec_cb);
13598
Chris Forbes3400bc52016-09-13 18:10:34 +120013599 VkCommandBufferBeginInfo cbbi2 = {
13600 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13601 0, nullptr
13602 };
13603 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13604 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13607 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013608 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13609 m_errorMonitor->VerifyFound();
13610 // Cleanup
13611 vkDestroyImageView(m_device->device(), view, NULL);
13612 vkDestroyRenderPass(m_device->device(), rp, NULL);
13613 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13614}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013615
13616TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13617 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13618 "invalid value. If logicOp is not available, attempt to "
13619 "use it and verify that we see the correct error.");
13620 ASSERT_NO_FATAL_FAILURE(InitState());
13621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13622
13623 auto features = m_device->phy().features();
13624 // Set the expected error depending on whether or not logicOp available
13625 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13627 "enabled, logicOpEnable must be "
13628 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013629 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013631 }
13632 // Create a pipeline using logicOp
13633 VkResult err;
13634
13635 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13636 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13637
13638 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013639 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013640 ASSERT_VK_SUCCESS(err);
13641
13642 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13643 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13644 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013645 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013646 vp_state_ci.pViewports = &vp;
13647 vp_state_ci.scissorCount = 1;
13648 VkRect2D scissors = {}; // Dummy scissors to point to
13649 vp_state_ci.pScissors = &scissors;
13650 // No dynamic state
13651 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13652 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13653
13654 VkPipelineShaderStageCreateInfo shaderStages[2];
13655 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013657 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13658 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013659 shaderStages[0] = vs.GetStageCreateInfo();
13660 shaderStages[1] = fs.GetStageCreateInfo();
13661
13662 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13663 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13664
13665 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13666 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13667 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13668
13669 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13670 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13671
13672 VkPipelineColorBlendAttachmentState att = {};
13673 att.blendEnable = VK_FALSE;
13674 att.colorWriteMask = 0xf;
13675
13676 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13677 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13678 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13679 cb_ci.logicOpEnable = VK_TRUE;
13680 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13681 cb_ci.attachmentCount = 1;
13682 cb_ci.pAttachments = &att;
13683
13684 VkGraphicsPipelineCreateInfo gp_ci = {};
13685 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13686 gp_ci.stageCount = 2;
13687 gp_ci.pStages = shaderStages;
13688 gp_ci.pVertexInputState = &vi_ci;
13689 gp_ci.pInputAssemblyState = &ia_ci;
13690 gp_ci.pViewportState = &vp_state_ci;
13691 gp_ci.pRasterizationState = &rs_ci;
13692 gp_ci.pColorBlendState = &cb_ci;
13693 gp_ci.pDynamicState = &dyn_state_ci;
13694 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13695 gp_ci.layout = pipeline_layout;
13696 gp_ci.renderPass = renderPass();
13697
13698 VkPipelineCacheCreateInfo pc_ci = {};
13699 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13700
13701 VkPipeline pipeline;
13702 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013703 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013704 ASSERT_VK_SUCCESS(err);
13705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013706 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013707 m_errorMonitor->VerifyFound();
13708 if (VK_SUCCESS == err) {
13709 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13710 }
13711 m_errorMonitor->VerifyFound();
13712 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13713 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13714}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013715#endif // DRAW_STATE_TESTS
13716
Tobin Ehlis0788f522015-05-26 16:11:58 -060013717#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013718#if GTEST_IS_THREADSAFE
13719struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013720 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013721 VkEvent event;
13722 bool bailout;
13723};
13724
Karl Schultz6addd812016-02-02 17:17:23 -070013725extern "C" void *AddToCommandBuffer(void *arg) {
13726 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013727
Mike Stroyana6d14942016-07-13 15:10:05 -060013728 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013729 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013730 if (data->bailout) {
13731 break;
13732 }
13733 }
13734 return NULL;
13735}
13736
Karl Schultz6addd812016-02-02 17:17:23 -070013737TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013738 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013739
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013741
Mike Stroyanaccf7692015-05-12 16:00:45 -060013742 ASSERT_NO_FATAL_FAILURE(InitState());
13743 ASSERT_NO_FATAL_FAILURE(InitViewport());
13744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13745
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013746 // Calls AllocateCommandBuffers
13747 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013748
13749 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013750 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013751
13752 VkEventCreateInfo event_info;
13753 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013754 VkResult err;
13755
13756 memset(&event_info, 0, sizeof(event_info));
13757 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13758
Chia-I Wuf7458c52015-10-26 21:10:41 +080013759 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013760 ASSERT_VK_SUCCESS(err);
13761
Mike Stroyanaccf7692015-05-12 16:00:45 -060013762 err = vkResetEvent(device(), event);
13763 ASSERT_VK_SUCCESS(err);
13764
13765 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013766 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013767 data.event = event;
13768 data.bailout = false;
13769 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013770
13771 // First do some correct operations using multiple threads.
13772 // Add many entries to command buffer from another thread.
13773 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13774 // Make non-conflicting calls from this thread at the same time.
13775 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013776 uint32_t count;
13777 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013778 }
13779 test_platform_thread_join(thread, NULL);
13780
13781 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013782 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013783 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013784 // Add many entries to command buffer from this thread at the same time.
13785 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013786
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013787 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013788 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013789
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013790 m_errorMonitor->SetBailout(NULL);
13791
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013792 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013793
Chia-I Wuf7458c52015-10-26 21:10:41 +080013794 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013795}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013796#endif // GTEST_IS_THREADSAFE
13797#endif // THREADING_TESTS
13798
Chris Forbes9f7ff632015-05-25 11:13:08 +120013799#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013800TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013801 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13802 "with an impossible code size");
13803
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013805
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013806 ASSERT_NO_FATAL_FAILURE(InitState());
13807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13808
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013809 VkShaderModule module;
13810 VkShaderModuleCreateInfo moduleCreateInfo;
13811 struct icd_spv_header spv;
13812
13813 spv.magic = ICD_SPV_MAGIC;
13814 spv.version = ICD_SPV_VERSION;
13815 spv.gen_magic = 0;
13816
13817 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13818 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013819 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013820 moduleCreateInfo.codeSize = 4;
13821 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013822 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013823
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013824 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013825}
13826
Karl Schultz6addd812016-02-02 17:17:23 -070013827TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013828 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13829 "with a bad magic number");
13830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013832
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013833 ASSERT_NO_FATAL_FAILURE(InitState());
13834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13835
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013836 VkShaderModule module;
13837 VkShaderModuleCreateInfo moduleCreateInfo;
13838 struct icd_spv_header spv;
13839
13840 spv.magic = ~ICD_SPV_MAGIC;
13841 spv.version = ICD_SPV_VERSION;
13842 spv.gen_magic = 0;
13843
13844 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13845 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013846 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013847 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13848 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013849 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013850
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013851 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013852}
13853
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013854#if 0
13855// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013856TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013858 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013859
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013860 ASSERT_NO_FATAL_FAILURE(InitState());
13861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13862
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013863 VkShaderModule module;
13864 VkShaderModuleCreateInfo moduleCreateInfo;
13865 struct icd_spv_header spv;
13866
13867 spv.magic = ICD_SPV_MAGIC;
13868 spv.version = ~ICD_SPV_VERSION;
13869 spv.gen_magic = 0;
13870
13871 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13872 moduleCreateInfo.pNext = NULL;
13873
Karl Schultz6addd812016-02-02 17:17:23 -070013874 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013875 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13876 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013877 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013878
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013879 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013880}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013881#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013882
Karl Schultz6addd812016-02-02 17:17:23 -070013883TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013884 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13885 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013887
Chris Forbes9f7ff632015-05-25 11:13:08 +120013888 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 char const *vsSource = "#version 450\n"
13892 "\n"
13893 "layout(location=0) out float x;\n"
13894 "out gl_PerVertex {\n"
13895 " vec4 gl_Position;\n"
13896 "};\n"
13897 "void main(){\n"
13898 " gl_Position = vec4(1);\n"
13899 " x = 0;\n"
13900 "}\n";
13901 char const *fsSource = "#version 450\n"
13902 "\n"
13903 "layout(location=0) out vec4 color;\n"
13904 "void main(){\n"
13905 " color = vec4(1);\n"
13906 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013907
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13909 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013910
13911 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013912 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013913 pipe.AddShader(&vs);
13914 pipe.AddShader(&fs);
13915
Chris Forbes9f7ff632015-05-25 11:13:08 +120013916 VkDescriptorSetObj descriptorSet(m_device);
13917 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013918 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013919
Tony Barbour5781e8f2015-08-04 16:23:11 -060013920 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013921
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013922 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013923}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013924
Karl Schultz6addd812016-02-02 17:17:23 -070013925TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013926 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13927 "which is not present in the outputs of the previous stage");
13928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013930
Chris Forbes59cb88d2015-05-25 11:13:13 +120013931 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013934 char const *vsSource = "#version 450\n"
13935 "\n"
13936 "out gl_PerVertex {\n"
13937 " vec4 gl_Position;\n"
13938 "};\n"
13939 "void main(){\n"
13940 " gl_Position = vec4(1);\n"
13941 "}\n";
13942 char const *fsSource = "#version 450\n"
13943 "\n"
13944 "layout(location=0) in float x;\n"
13945 "layout(location=0) out vec4 color;\n"
13946 "void main(){\n"
13947 " color = vec4(x);\n"
13948 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013949
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013950 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13951 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013952
13953 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013954 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013955 pipe.AddShader(&vs);
13956 pipe.AddShader(&fs);
13957
Chris Forbes59cb88d2015-05-25 11:13:13 +120013958 VkDescriptorSetObj descriptorSet(m_device);
13959 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013960 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013961
Tony Barbour5781e8f2015-08-04 16:23:11 -060013962 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013963
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013964 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013965}
13966
Karl Schultz6addd812016-02-02 17:17:23 -070013967TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013968 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13969 "within an interace block, which is not present in the outputs "
13970 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013972
13973 ASSERT_NO_FATAL_FAILURE(InitState());
13974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 char const *vsSource = "#version 450\n"
13977 "\n"
13978 "out gl_PerVertex {\n"
13979 " vec4 gl_Position;\n"
13980 "};\n"
13981 "void main(){\n"
13982 " gl_Position = vec4(1);\n"
13983 "}\n";
13984 char const *fsSource = "#version 450\n"
13985 "\n"
13986 "in block { layout(location=0) float x; } ins;\n"
13987 "layout(location=0) out vec4 color;\n"
13988 "void main(){\n"
13989 " color = vec4(ins.x);\n"
13990 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013991
13992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13994
13995 VkPipelineObj pipe(m_device);
13996 pipe.AddColorAttachment();
13997 pipe.AddShader(&vs);
13998 pipe.AddShader(&fs);
13999
14000 VkDescriptorSetObj descriptorSet(m_device);
14001 descriptorSet.AppendDummy();
14002 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14003
14004 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014006 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014007}
14008
Karl Schultz6addd812016-02-02 17:17:23 -070014009TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014010 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
14011 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
14013 "output arr[2] of float32' vs 'ptr to "
14014 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014015
14016 ASSERT_NO_FATAL_FAILURE(InitState());
14017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014019 char const *vsSource = "#version 450\n"
14020 "\n"
14021 "layout(location=0) out float x[2];\n"
14022 "out gl_PerVertex {\n"
14023 " vec4 gl_Position;\n"
14024 "};\n"
14025 "void main(){\n"
14026 " x[0] = 0; x[1] = 0;\n"
14027 " gl_Position = vec4(1);\n"
14028 "}\n";
14029 char const *fsSource = "#version 450\n"
14030 "\n"
14031 "layout(location=0) in float x[3];\n"
14032 "layout(location=0) out vec4 color;\n"
14033 "void main(){\n"
14034 " color = vec4(x[0] + x[1] + x[2]);\n"
14035 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014036
14037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14039
14040 VkPipelineObj pipe(m_device);
14041 pipe.AddColorAttachment();
14042 pipe.AddShader(&vs);
14043 pipe.AddShader(&fs);
14044
14045 VkDescriptorSetObj descriptorSet(m_device);
14046 descriptorSet.AppendDummy();
14047 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14048
14049 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14050
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014051 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014052}
14053
Karl Schultz6addd812016-02-02 17:17:23 -070014054TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014055 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
14056 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014058
Chris Forbesb56af562015-05-25 11:13:17 +120014059 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014062 char const *vsSource = "#version 450\n"
14063 "\n"
14064 "layout(location=0) out int x;\n"
14065 "out gl_PerVertex {\n"
14066 " vec4 gl_Position;\n"
14067 "};\n"
14068 "void main(){\n"
14069 " x = 0;\n"
14070 " gl_Position = vec4(1);\n"
14071 "}\n";
14072 char const *fsSource = "#version 450\n"
14073 "\n"
14074 "layout(location=0) in float x;\n" /* VS writes int */
14075 "layout(location=0) out vec4 color;\n"
14076 "void main(){\n"
14077 " color = vec4(x);\n"
14078 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014079
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014082
14083 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014084 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014085 pipe.AddShader(&vs);
14086 pipe.AddShader(&fs);
14087
Chris Forbesb56af562015-05-25 11:13:17 +120014088 VkDescriptorSetObj descriptorSet(m_device);
14089 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014090 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014091
Tony Barbour5781e8f2015-08-04 16:23:11 -060014092 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014093
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014094 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014095}
14096
Karl Schultz6addd812016-02-02 17:17:23 -070014097TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014098 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
14099 "the VS->FS interface, when the variable is contained within "
14100 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014102
14103 ASSERT_NO_FATAL_FAILURE(InitState());
14104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 char const *vsSource = "#version 450\n"
14107 "\n"
14108 "out block { layout(location=0) int x; } outs;\n"
14109 "out gl_PerVertex {\n"
14110 " vec4 gl_Position;\n"
14111 "};\n"
14112 "void main(){\n"
14113 " outs.x = 0;\n"
14114 " gl_Position = vec4(1);\n"
14115 "}\n";
14116 char const *fsSource = "#version 450\n"
14117 "\n"
14118 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14119 "layout(location=0) out vec4 color;\n"
14120 "void main(){\n"
14121 " color = vec4(ins.x);\n"
14122 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014123
14124 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14125 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14126
14127 VkPipelineObj pipe(m_device);
14128 pipe.AddColorAttachment();
14129 pipe.AddShader(&vs);
14130 pipe.AddShader(&fs);
14131
14132 VkDescriptorSetObj descriptorSet(m_device);
14133 descriptorSet.AppendDummy();
14134 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14135
14136 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14137
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014138 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014139}
14140
14141TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014142 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
14143 "the VS->FS interface; This should manifest as a not-written/not-consumed "
14144 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014145 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 +130014146
14147 ASSERT_NO_FATAL_FAILURE(InitState());
14148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014150 char const *vsSource = "#version 450\n"
14151 "\n"
14152 "out block { layout(location=1) float x; } outs;\n"
14153 "out gl_PerVertex {\n"
14154 " vec4 gl_Position;\n"
14155 "};\n"
14156 "void main(){\n"
14157 " outs.x = 0;\n"
14158 " gl_Position = vec4(1);\n"
14159 "}\n";
14160 char const *fsSource = "#version 450\n"
14161 "\n"
14162 "in block { layout(location=0) float x; } ins;\n"
14163 "layout(location=0) out vec4 color;\n"
14164 "void main(){\n"
14165 " color = vec4(ins.x);\n"
14166 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014167
14168 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14169 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14170
14171 VkPipelineObj pipe(m_device);
14172 pipe.AddColorAttachment();
14173 pipe.AddShader(&vs);
14174 pipe.AddShader(&fs);
14175
14176 VkDescriptorSetObj descriptorSet(m_device);
14177 descriptorSet.AppendDummy();
14178 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14179
14180 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014182 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014183}
14184
14185TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014186 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
14187 "VS->FS interface. It's not enough to have the same set of locations in "
14188 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014189 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 +130014190
14191 ASSERT_NO_FATAL_FAILURE(InitState());
14192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014194 char const *vsSource = "#version 450\n"
14195 "\n"
14196 "out block { layout(location=0, component=0) float x; } outs;\n"
14197 "out gl_PerVertex {\n"
14198 " vec4 gl_Position;\n"
14199 "};\n"
14200 "void main(){\n"
14201 " outs.x = 0;\n"
14202 " gl_Position = vec4(1);\n"
14203 "}\n";
14204 char const *fsSource = "#version 450\n"
14205 "\n"
14206 "in block { layout(location=0, component=1) float x; } ins;\n"
14207 "layout(location=0) out vec4 color;\n"
14208 "void main(){\n"
14209 " color = vec4(ins.x);\n"
14210 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014211
14212 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14213 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14214
14215 VkPipelineObj pipe(m_device);
14216 pipe.AddColorAttachment();
14217 pipe.AddShader(&vs);
14218 pipe.AddShader(&fs);
14219
14220 VkDescriptorSetObj descriptorSet(m_device);
14221 descriptorSet.AppendDummy();
14222 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14223
14224 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014226 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014227}
14228
Karl Schultz6addd812016-02-02 17:17:23 -070014229TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014230 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
14231 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014233
Chris Forbesde136e02015-05-25 11:13:28 +120014234 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014236
14237 VkVertexInputBindingDescription input_binding;
14238 memset(&input_binding, 0, sizeof(input_binding));
14239
14240 VkVertexInputAttributeDescription input_attrib;
14241 memset(&input_attrib, 0, sizeof(input_attrib));
14242 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014244 char const *vsSource = "#version 450\n"
14245 "\n"
14246 "out gl_PerVertex {\n"
14247 " vec4 gl_Position;\n"
14248 "};\n"
14249 "void main(){\n"
14250 " gl_Position = vec4(1);\n"
14251 "}\n";
14252 char const *fsSource = "#version 450\n"
14253 "\n"
14254 "layout(location=0) out vec4 color;\n"
14255 "void main(){\n"
14256 " color = vec4(1);\n"
14257 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014258
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014259 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14260 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014261
14262 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014263 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014264 pipe.AddShader(&vs);
14265 pipe.AddShader(&fs);
14266
14267 pipe.AddVertexInputBindings(&input_binding, 1);
14268 pipe.AddVertexInputAttribs(&input_attrib, 1);
14269
Chris Forbesde136e02015-05-25 11:13:28 +120014270 VkDescriptorSetObj descriptorSet(m_device);
14271 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014272 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014273
Tony Barbour5781e8f2015-08-04 16:23:11 -060014274 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014275
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014276 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014277}
14278
Karl Schultz6addd812016-02-02 17:17:23 -070014279TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014280 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
14281 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014283
14284 ASSERT_NO_FATAL_FAILURE(InitState());
14285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14286
14287 VkVertexInputBindingDescription input_binding;
14288 memset(&input_binding, 0, sizeof(input_binding));
14289
14290 VkVertexInputAttributeDescription input_attrib;
14291 memset(&input_attrib, 0, sizeof(input_attrib));
14292 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014294 char const *vsSource = "#version 450\n"
14295 "\n"
14296 "layout(location=1) in float x;\n"
14297 "out gl_PerVertex {\n"
14298 " vec4 gl_Position;\n"
14299 "};\n"
14300 "void main(){\n"
14301 " gl_Position = vec4(x);\n"
14302 "}\n";
14303 char const *fsSource = "#version 450\n"
14304 "\n"
14305 "layout(location=0) out vec4 color;\n"
14306 "void main(){\n"
14307 " color = vec4(1);\n"
14308 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014309
14310 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14311 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14312
14313 VkPipelineObj pipe(m_device);
14314 pipe.AddColorAttachment();
14315 pipe.AddShader(&vs);
14316 pipe.AddShader(&fs);
14317
14318 pipe.AddVertexInputBindings(&input_binding, 1);
14319 pipe.AddVertexInputAttribs(&input_attrib, 1);
14320
14321 VkDescriptorSetObj descriptorSet(m_device);
14322 descriptorSet.AppendDummy();
14323 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14324
14325 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14326
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014327 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014328}
14329
Karl Schultz6addd812016-02-02 17:17:23 -070014330TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014331 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
14332 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VS consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014334
Chris Forbes62e8e502015-05-25 11:13:29 +120014335 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014338 char const *vsSource = "#version 450\n"
14339 "\n"
14340 "layout(location=0) in vec4 x;\n" /* not provided */
14341 "out gl_PerVertex {\n"
14342 " vec4 gl_Position;\n"
14343 "};\n"
14344 "void main(){\n"
14345 " gl_Position = x;\n"
14346 "}\n";
14347 char const *fsSource = "#version 450\n"
14348 "\n"
14349 "layout(location=0) out vec4 color;\n"
14350 "void main(){\n"
14351 " color = vec4(1);\n"
14352 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014353
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014356
14357 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014358 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014359 pipe.AddShader(&vs);
14360 pipe.AddShader(&fs);
14361
Chris Forbes62e8e502015-05-25 11:13:29 +120014362 VkDescriptorSetObj descriptorSet(m_device);
14363 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014365
Tony Barbour5781e8f2015-08-04 16:23:11 -060014366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014368 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014369}
14370
Karl Schultz6addd812016-02-02 17:17:23 -070014371TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014372 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
14373 "fundamental type (float/int/uint) of an attribute and the "
14374 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014376
Chris Forbesc97d98e2015-05-25 11:13:31 +120014377 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014379
14380 VkVertexInputBindingDescription input_binding;
14381 memset(&input_binding, 0, sizeof(input_binding));
14382
14383 VkVertexInputAttributeDescription input_attrib;
14384 memset(&input_attrib, 0, sizeof(input_attrib));
14385 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014387 char const *vsSource = "#version 450\n"
14388 "\n"
14389 "layout(location=0) in int x;\n" /* attrib provided float */
14390 "out gl_PerVertex {\n"
14391 " vec4 gl_Position;\n"
14392 "};\n"
14393 "void main(){\n"
14394 " gl_Position = vec4(x);\n"
14395 "}\n";
14396 char const *fsSource = "#version 450\n"
14397 "\n"
14398 "layout(location=0) out vec4 color;\n"
14399 "void main(){\n"
14400 " color = vec4(1);\n"
14401 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014402
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014403 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14404 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014405
14406 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014407 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014408 pipe.AddShader(&vs);
14409 pipe.AddShader(&fs);
14410
14411 pipe.AddVertexInputBindings(&input_binding, 1);
14412 pipe.AddVertexInputAttribs(&input_attrib, 1);
14413
Chris Forbesc97d98e2015-05-25 11:13:31 +120014414 VkDescriptorSetObj descriptorSet(m_device);
14415 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014416 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014417
Tony Barbour5781e8f2015-08-04 16:23:11 -060014418 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014419
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014420 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014421}
14422
Chris Forbesc68b43c2016-04-06 11:18:47 +120014423TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014424 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
14425 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14427 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014428
14429 ASSERT_NO_FATAL_FAILURE(InitState());
14430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014432 char const *vsSource = "#version 450\n"
14433 "\n"
14434 "out gl_PerVertex {\n"
14435 " vec4 gl_Position;\n"
14436 "};\n"
14437 "void main(){\n"
14438 " gl_Position = vec4(1);\n"
14439 "}\n";
14440 char const *fsSource = "#version 450\n"
14441 "\n"
14442 "layout(location=0) out vec4 color;\n"
14443 "void main(){\n"
14444 " color = vec4(1);\n"
14445 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014446
14447 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14448 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14449
14450 VkPipelineObj pipe(m_device);
14451 pipe.AddColorAttachment();
14452 pipe.AddShader(&vs);
14453 pipe.AddShader(&vs);
14454 pipe.AddShader(&fs);
14455
14456 VkDescriptorSetObj descriptorSet(m_device);
14457 descriptorSet.AppendDummy();
14458 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14459
14460 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14461
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014462 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014463}
14464
Karl Schultz6addd812016-02-02 17:17:23 -070014465TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014466 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
14467 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014468 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014469
14470 ASSERT_NO_FATAL_FAILURE(InitState());
14471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14472
14473 VkVertexInputBindingDescription input_binding;
14474 memset(&input_binding, 0, sizeof(input_binding));
14475
14476 VkVertexInputAttributeDescription input_attribs[2];
14477 memset(input_attribs, 0, sizeof(input_attribs));
14478
14479 for (int i = 0; i < 2; i++) {
14480 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14481 input_attribs[i].location = i;
14482 }
14483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014484 char const *vsSource = "#version 450\n"
14485 "\n"
14486 "layout(location=0) in mat2x4 x;\n"
14487 "out gl_PerVertex {\n"
14488 " vec4 gl_Position;\n"
14489 "};\n"
14490 "void main(){\n"
14491 " gl_Position = x[0] + x[1];\n"
14492 "}\n";
14493 char const *fsSource = "#version 450\n"
14494 "\n"
14495 "layout(location=0) out vec4 color;\n"
14496 "void main(){\n"
14497 " color = vec4(1);\n"
14498 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014499
14500 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14501 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14502
14503 VkPipelineObj pipe(m_device);
14504 pipe.AddColorAttachment();
14505 pipe.AddShader(&vs);
14506 pipe.AddShader(&fs);
14507
14508 pipe.AddVertexInputBindings(&input_binding, 1);
14509 pipe.AddVertexInputAttribs(input_attribs, 2);
14510
14511 VkDescriptorSetObj descriptorSet(m_device);
14512 descriptorSet.AppendDummy();
14513 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14514
14515 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14516
14517 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014518 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014519}
14520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014521TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014522 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014523
14524 ASSERT_NO_FATAL_FAILURE(InitState());
14525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14526
14527 VkVertexInputBindingDescription input_binding;
14528 memset(&input_binding, 0, sizeof(input_binding));
14529
14530 VkVertexInputAttributeDescription input_attribs[2];
14531 memset(input_attribs, 0, sizeof(input_attribs));
14532
14533 for (int i = 0; i < 2; i++) {
14534 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14535 input_attribs[i].location = i;
14536 }
14537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014538 char const *vsSource = "#version 450\n"
14539 "\n"
14540 "layout(location=0) in vec4 x[2];\n"
14541 "out gl_PerVertex {\n"
14542 " vec4 gl_Position;\n"
14543 "};\n"
14544 "void main(){\n"
14545 " gl_Position = x[0] + x[1];\n"
14546 "}\n";
14547 char const *fsSource = "#version 450\n"
14548 "\n"
14549 "layout(location=0) out vec4 color;\n"
14550 "void main(){\n"
14551 " color = vec4(1);\n"
14552 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014553
14554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14556
14557 VkPipelineObj pipe(m_device);
14558 pipe.AddColorAttachment();
14559 pipe.AddShader(&vs);
14560 pipe.AddShader(&fs);
14561
14562 pipe.AddVertexInputBindings(&input_binding, 1);
14563 pipe.AddVertexInputAttribs(input_attribs, 2);
14564
14565 VkDescriptorSetObj descriptorSet(m_device);
14566 descriptorSet.AppendDummy();
14567 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14568
14569 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014571 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014572}
Chris Forbes2682b242015-11-24 11:13:14 +130014573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014574TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014575 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14576 "through multiple VS inputs, each consuming a different subset of the "
14577 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014578 m_errorMonitor->ExpectSuccess();
14579
14580 ASSERT_NO_FATAL_FAILURE(InitState());
14581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14582
14583 VkVertexInputBindingDescription input_binding;
14584 memset(&input_binding, 0, sizeof(input_binding));
14585
14586 VkVertexInputAttributeDescription input_attribs[3];
14587 memset(input_attribs, 0, sizeof(input_attribs));
14588
14589 for (int i = 0; i < 3; i++) {
14590 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14591 input_attribs[i].location = i;
14592 }
14593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014594 char const *vsSource = "#version 450\n"
14595 "\n"
14596 "layout(location=0) in vec4 x;\n"
14597 "layout(location=1) in vec3 y1;\n"
14598 "layout(location=1, component=3) in float y2;\n"
14599 "layout(location=2) in vec4 z;\n"
14600 "out gl_PerVertex {\n"
14601 " vec4 gl_Position;\n"
14602 "};\n"
14603 "void main(){\n"
14604 " gl_Position = x + vec4(y1, y2) + z;\n"
14605 "}\n";
14606 char const *fsSource = "#version 450\n"
14607 "\n"
14608 "layout(location=0) out vec4 color;\n"
14609 "void main(){\n"
14610 " color = vec4(1);\n"
14611 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014612
14613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14615
14616 VkPipelineObj pipe(m_device);
14617 pipe.AddColorAttachment();
14618 pipe.AddShader(&vs);
14619 pipe.AddShader(&fs);
14620
14621 pipe.AddVertexInputBindings(&input_binding, 1);
14622 pipe.AddVertexInputAttribs(input_attribs, 3);
14623
14624 VkDescriptorSetObj descriptorSet(m_device);
14625 descriptorSet.AppendDummy();
14626 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14627
14628 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14629
14630 m_errorMonitor->VerifyNotFound();
14631}
14632
Chris Forbes82ff92a2016-09-09 10:50:24 +120014633TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14635 "No entrypoint found named `foo`");
14636
14637 ASSERT_NO_FATAL_FAILURE(InitState());
14638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14639
14640 char const *vsSource = "#version 450\n"
14641 "out gl_PerVertex {\n"
14642 " vec4 gl_Position;\n"
14643 "};\n"
14644 "void main(){\n"
14645 " gl_Position = vec4(0);\n"
14646 "}\n";
14647 char const *fsSource = "#version 450\n"
14648 "\n"
14649 "layout(location=0) out vec4 color;\n"
14650 "void main(){\n"
14651 " color = vec4(1);\n"
14652 "}\n";
14653
14654 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14655 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14656
14657 VkPipelineObj pipe(m_device);
14658 pipe.AddColorAttachment();
14659 pipe.AddShader(&vs);
14660 pipe.AddShader(&fs);
14661
14662 VkDescriptorSetObj descriptorSet(m_device);
14663 descriptorSet.AppendDummy();
14664 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14665
14666 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14667
14668 m_errorMonitor->VerifyFound();
14669}
14670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014672 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014673
14674 ASSERT_NO_FATAL_FAILURE(InitState());
14675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014677 char const *vsSource = "#version 450\n"
14678 "out gl_PerVertex {\n"
14679 " vec4 gl_Position;\n"
14680 "};\n"
14681 "void main(){\n"
14682 " gl_Position = vec4(0);\n"
14683 "}\n";
14684 char const *fsSource = "#version 450\n"
14685 "\n"
14686 "layout(location=0) out vec4 color;\n"
14687 "void main(){\n"
14688 " color = vec4(1);\n"
14689 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014690
14691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14692 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14693
14694 VkPipelineObj pipe(m_device);
14695 pipe.AddColorAttachment();
14696 pipe.AddShader(&vs);
14697 pipe.AddShader(&fs);
14698
14699 VkDescriptorSetObj descriptorSet(m_device);
14700 descriptorSet.AppendDummy();
14701 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14702
14703 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14704
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014705 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014706}
14707
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014708TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14709 m_errorMonitor->SetDesiredFailureMsg(
14710 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14711 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14712 "uses a depth/stencil attachment");
14713
14714 ASSERT_NO_FATAL_FAILURE(InitState());
14715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14716
14717 char const *vsSource = "#version 450\n"
14718 "void main(){ gl_Position = vec4(0); }\n";
14719 char const *fsSource = "#version 450\n"
14720 "\n"
14721 "layout(location=0) out vec4 color;\n"
14722 "void main(){\n"
14723 " color = vec4(1);\n"
14724 "}\n";
14725
14726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14728
14729 VkPipelineObj pipe(m_device);
14730 pipe.AddColorAttachment();
14731 pipe.AddShader(&vs);
14732 pipe.AddShader(&fs);
14733
14734 VkDescriptorSetObj descriptorSet(m_device);
14735 descriptorSet.AppendDummy();
14736 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14737
14738 VkAttachmentDescription attachments[] = {
14739 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14740 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14741 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14742 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14743 },
14744 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14745 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14746 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14747 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14748 },
14749 };
14750 VkAttachmentReference refs[] = {
14751 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14752 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14753 };
14754 VkSubpassDescription subpass = {
14755 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14756 1, &refs[0], nullptr, &refs[1],
14757 0, nullptr
14758 };
14759 VkRenderPassCreateInfo rpci = {
14760 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14761 0, 2, attachments, 1, &subpass, 0, nullptr
14762 };
14763 VkRenderPass rp;
14764 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14765 ASSERT_VK_SUCCESS(err);
14766
14767 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14768
14769 m_errorMonitor->VerifyFound();
14770
14771 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14772}
14773
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014774TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014775 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14776 "set out in 14.1.3: fundamental type must match, and producer side must "
14777 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014778 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014779
14780 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14781
14782 ASSERT_NO_FATAL_FAILURE(InitState());
14783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014785 char const *vsSource = "#version 450\n"
14786 "out gl_PerVertex {\n"
14787 " vec4 gl_Position;\n"
14788 "};\n"
14789 "layout(location=0) out vec3 x;\n"
14790 "layout(location=1) out ivec3 y;\n"
14791 "layout(location=2) out vec3 z;\n"
14792 "void main(){\n"
14793 " gl_Position = vec4(0);\n"
14794 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14795 "}\n";
14796 char const *fsSource = "#version 450\n"
14797 "\n"
14798 "layout(location=0) out vec4 color;\n"
14799 "layout(location=0) in float x;\n"
14800 "layout(location=1) flat in int y;\n"
14801 "layout(location=2) in vec2 z;\n"
14802 "void main(){\n"
14803 " color = vec4(1 + x + y + z.x);\n"
14804 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014805
14806 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14807 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14808
14809 VkPipelineObj pipe(m_device);
14810 pipe.AddColorAttachment();
14811 pipe.AddShader(&vs);
14812 pipe.AddShader(&fs);
14813
14814 VkDescriptorSetObj descriptorSet(m_device);
14815 descriptorSet.AppendDummy();
14816 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14817
Mike Stroyan255e9582016-06-24 09:49:32 -060014818 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014819 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014820 ASSERT_VK_SUCCESS(err);
14821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014822 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014823}
14824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014825TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014826 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14827 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014828 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014829
14830 ASSERT_NO_FATAL_FAILURE(InitState());
14831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14832
Chris Forbesc1e852d2016-04-04 19:26:42 +120014833 if (!m_device->phy().features().tessellationShader) {
14834 printf("Device does not support tessellation shaders; skipped.\n");
14835 return;
14836 }
14837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014838 char const *vsSource = "#version 450\n"
14839 "void main(){}\n";
14840 char const *tcsSource = "#version 450\n"
14841 "layout(location=0) out int x[];\n"
14842 "layout(vertices=3) out;\n"
14843 "void main(){\n"
14844 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14845 " gl_TessLevelInner[0] = 1;\n"
14846 " x[gl_InvocationID] = gl_InvocationID;\n"
14847 "}\n";
14848 char const *tesSource = "#version 450\n"
14849 "layout(triangles, equal_spacing, cw) in;\n"
14850 "layout(location=0) in int x[];\n"
14851 "out gl_PerVertex { vec4 gl_Position; };\n"
14852 "void main(){\n"
14853 " gl_Position.xyz = gl_TessCoord;\n"
14854 " gl_Position.w = x[0] + x[1] + x[2];\n"
14855 "}\n";
14856 char const *fsSource = "#version 450\n"
14857 "layout(location=0) out vec4 color;\n"
14858 "void main(){\n"
14859 " color = vec4(1);\n"
14860 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014861
14862 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14863 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14864 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14865 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14866
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014867 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14868 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014871
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014872 VkPipelineObj pipe(m_device);
14873 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014874 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014875 pipe.AddColorAttachment();
14876 pipe.AddShader(&vs);
14877 pipe.AddShader(&tcs);
14878 pipe.AddShader(&tes);
14879 pipe.AddShader(&fs);
14880
14881 VkDescriptorSetObj descriptorSet(m_device);
14882 descriptorSet.AppendDummy();
14883 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14884
14885 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14886
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014887 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014888}
14889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014890TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014891 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14892 "interface block passed into the geometry shader. This "
14893 "is interesting because the 'extra' array level is not "
14894 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014895 m_errorMonitor->ExpectSuccess();
14896
14897 ASSERT_NO_FATAL_FAILURE(InitState());
14898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14899
14900 if (!m_device->phy().features().geometryShader) {
14901 printf("Device does not support geometry shaders; skipped.\n");
14902 return;
14903 }
14904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 char const *vsSource = "#version 450\n"
14906 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14907 "void main(){\n"
14908 " vs_out.x = vec4(1);\n"
14909 "}\n";
14910 char const *gsSource = "#version 450\n"
14911 "layout(triangles) in;\n"
14912 "layout(triangle_strip, max_vertices=3) out;\n"
14913 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14914 "out gl_PerVertex { vec4 gl_Position; };\n"
14915 "void main() {\n"
14916 " gl_Position = gs_in[0].x;\n"
14917 " EmitVertex();\n"
14918 "}\n";
14919 char const *fsSource = "#version 450\n"
14920 "layout(location=0) out vec4 color;\n"
14921 "void main(){\n"
14922 " color = vec4(1);\n"
14923 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014924
14925 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14926 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14927 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14928
14929 VkPipelineObj pipe(m_device);
14930 pipe.AddColorAttachment();
14931 pipe.AddShader(&vs);
14932 pipe.AddShader(&gs);
14933 pipe.AddShader(&fs);
14934
14935 VkDescriptorSetObj descriptorSet(m_device);
14936 descriptorSet.AppendDummy();
14937 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14938
14939 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14940
14941 m_errorMonitor->VerifyNotFound();
14942}
14943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014944TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014945 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14946 "the TCS without the patch decoration, but consumed in the TES "
14947 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14949 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014950
14951 ASSERT_NO_FATAL_FAILURE(InitState());
14952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14953
Chris Forbesc1e852d2016-04-04 19:26:42 +120014954 if (!m_device->phy().features().tessellationShader) {
14955 printf("Device does not support tessellation shaders; skipped.\n");
14956 return;
14957 }
14958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014959 char const *vsSource = "#version 450\n"
14960 "void main(){}\n";
14961 char const *tcsSource = "#version 450\n"
14962 "layout(location=0) out int x[];\n"
14963 "layout(vertices=3) out;\n"
14964 "void main(){\n"
14965 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14966 " gl_TessLevelInner[0] = 1;\n"
14967 " x[gl_InvocationID] = gl_InvocationID;\n"
14968 "}\n";
14969 char const *tesSource = "#version 450\n"
14970 "layout(triangles, equal_spacing, cw) in;\n"
14971 "layout(location=0) patch in int x;\n"
14972 "out gl_PerVertex { vec4 gl_Position; };\n"
14973 "void main(){\n"
14974 " gl_Position.xyz = gl_TessCoord;\n"
14975 " gl_Position.w = x;\n"
14976 "}\n";
14977 char const *fsSource = "#version 450\n"
14978 "layout(location=0) out vec4 color;\n"
14979 "void main(){\n"
14980 " color = vec4(1);\n"
14981 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014982
14983 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14984 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14985 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14986 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014988 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14989 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014992
14993 VkPipelineObj pipe(m_device);
14994 pipe.SetInputAssembly(&iasci);
14995 pipe.SetTessellation(&tsci);
14996 pipe.AddColorAttachment();
14997 pipe.AddShader(&vs);
14998 pipe.AddShader(&tcs);
14999 pipe.AddShader(&tes);
15000 pipe.AddShader(&fs);
15001
15002 VkDescriptorSetObj descriptorSet(m_device);
15003 descriptorSet.AppendDummy();
15004 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15005
15006 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15007
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015008 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015009}
15010
Karl Schultz6addd812016-02-02 17:17:23 -070015011TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015012 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
15013 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15015 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015016
Chris Forbes280ba2c2015-06-12 11:16:41 +120015017 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015019
15020 /* Two binding descriptions for binding 0 */
15021 VkVertexInputBindingDescription input_bindings[2];
15022 memset(input_bindings, 0, sizeof(input_bindings));
15023
15024 VkVertexInputAttributeDescription input_attrib;
15025 memset(&input_attrib, 0, sizeof(input_attrib));
15026 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015028 char const *vsSource = "#version 450\n"
15029 "\n"
15030 "layout(location=0) in float x;\n" /* attrib provided float */
15031 "out gl_PerVertex {\n"
15032 " vec4 gl_Position;\n"
15033 "};\n"
15034 "void main(){\n"
15035 " gl_Position = vec4(x);\n"
15036 "}\n";
15037 char const *fsSource = "#version 450\n"
15038 "\n"
15039 "layout(location=0) out vec4 color;\n"
15040 "void main(){\n"
15041 " color = vec4(1);\n"
15042 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015043
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015044 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15045 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015046
15047 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015048 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015049 pipe.AddShader(&vs);
15050 pipe.AddShader(&fs);
15051
15052 pipe.AddVertexInputBindings(input_bindings, 2);
15053 pipe.AddVertexInputAttribs(&input_attrib, 1);
15054
Chris Forbes280ba2c2015-06-12 11:16:41 +120015055 VkDescriptorSetObj descriptorSet(m_device);
15056 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015057 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015058
Tony Barbour5781e8f2015-08-04 16:23:11 -060015059 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015060
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015061 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015062}
Chris Forbes8f68b562015-05-25 11:13:32 +120015063
Chris Forbes35efec72016-04-21 14:32:08 +120015064TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015065 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
15066 "attributes. This is interesting because they consume multiple "
15067 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120015068 m_errorMonitor->ExpectSuccess();
15069
15070 ASSERT_NO_FATAL_FAILURE(InitState());
15071 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15072
Chris Forbes91cf3a82016-06-28 17:51:35 +120015073 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120015074 printf("Device does not support 64bit vertex attributes; skipped.\n");
15075 return;
15076 }
15077
15078 VkVertexInputBindingDescription input_bindings[1];
15079 memset(input_bindings, 0, sizeof(input_bindings));
15080
15081 VkVertexInputAttributeDescription input_attribs[4];
15082 memset(input_attribs, 0, sizeof(input_attribs));
15083 input_attribs[0].location = 0;
15084 input_attribs[0].offset = 0;
15085 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
15086 input_attribs[1].location = 2;
15087 input_attribs[1].offset = 32;
15088 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
15089 input_attribs[2].location = 4;
15090 input_attribs[2].offset = 64;
15091 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
15092 input_attribs[3].location = 6;
15093 input_attribs[3].offset = 96;
15094 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
15095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 char const *vsSource = "#version 450\n"
15097 "\n"
15098 "layout(location=0) in dmat4 x;\n"
15099 "out gl_PerVertex {\n"
15100 " vec4 gl_Position;\n"
15101 "};\n"
15102 "void main(){\n"
15103 " gl_Position = vec4(x[0][0]);\n"
15104 "}\n";
15105 char const *fsSource = "#version 450\n"
15106 "\n"
15107 "layout(location=0) out vec4 color;\n"
15108 "void main(){\n"
15109 " color = vec4(1);\n"
15110 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120015111
15112 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15113 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15114
15115 VkPipelineObj pipe(m_device);
15116 pipe.AddColorAttachment();
15117 pipe.AddShader(&vs);
15118 pipe.AddShader(&fs);
15119
15120 pipe.AddVertexInputBindings(input_bindings, 1);
15121 pipe.AddVertexInputAttribs(input_attribs, 4);
15122
15123 VkDescriptorSetObj descriptorSet(m_device);
15124 descriptorSet.AppendDummy();
15125 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15126
15127 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15128
15129 m_errorMonitor->VerifyNotFound();
15130}
15131
Karl Schultz6addd812016-02-02 17:17:23 -070015132TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015133 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
15134 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015136
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015137 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015139 char const *vsSource = "#version 450\n"
15140 "\n"
15141 "out gl_PerVertex {\n"
15142 " vec4 gl_Position;\n"
15143 "};\n"
15144 "void main(){\n"
15145 " gl_Position = vec4(1);\n"
15146 "}\n";
15147 char const *fsSource = "#version 450\n"
15148 "\n"
15149 "void main(){\n"
15150 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015151
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015154
15155 VkPipelineObj pipe(m_device);
15156 pipe.AddShader(&vs);
15157 pipe.AddShader(&fs);
15158
Chia-I Wu08accc62015-07-07 11:50:03 +080015159 /* set up CB 0, not written */
15160 pipe.AddColorAttachment();
15161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015162
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015163 VkDescriptorSetObj descriptorSet(m_device);
15164 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015165 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015166
Tony Barbour5781e8f2015-08-04 16:23:11 -060015167 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015168
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015169 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015170}
15171
Karl Schultz6addd812016-02-02 17:17:23 -070015172TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015173 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
15174 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
15176 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015177
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015178 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015180 char const *vsSource = "#version 450\n"
15181 "\n"
15182 "out gl_PerVertex {\n"
15183 " vec4 gl_Position;\n"
15184 "};\n"
15185 "void main(){\n"
15186 " gl_Position = vec4(1);\n"
15187 "}\n";
15188 char const *fsSource = "#version 450\n"
15189 "\n"
15190 "layout(location=0) out vec4 x;\n"
15191 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15192 "void main(){\n"
15193 " x = vec4(1);\n"
15194 " y = vec4(1);\n"
15195 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015196
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015199
15200 VkPipelineObj pipe(m_device);
15201 pipe.AddShader(&vs);
15202 pipe.AddShader(&fs);
15203
Chia-I Wu08accc62015-07-07 11:50:03 +080015204 /* set up CB 0, not written */
15205 pipe.AddColorAttachment();
15206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015207 /* FS writes CB 1, but we don't configure it */
15208
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015209 VkDescriptorSetObj descriptorSet(m_device);
15210 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015212
Tony Barbour5781e8f2015-08-04 16:23:11 -060015213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015215 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015216}
15217
Karl Schultz6addd812016-02-02 17:17:23 -070015218TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015219 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
15220 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015222
Chris Forbesa36d69e2015-05-25 11:13:44 +120015223 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 char const *vsSource = "#version 450\n"
15226 "\n"
15227 "out gl_PerVertex {\n"
15228 " vec4 gl_Position;\n"
15229 "};\n"
15230 "void main(){\n"
15231 " gl_Position = vec4(1);\n"
15232 "}\n";
15233 char const *fsSource = "#version 450\n"
15234 "\n"
15235 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15236 "void main(){\n"
15237 " x = ivec4(1);\n"
15238 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015239
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015240 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15241 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015242
15243 VkPipelineObj pipe(m_device);
15244 pipe.AddShader(&vs);
15245 pipe.AddShader(&fs);
15246
Chia-I Wu08accc62015-07-07 11:50:03 +080015247 /* set up CB 0; type is UNORM by default */
15248 pipe.AddColorAttachment();
15249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015250
Chris Forbesa36d69e2015-05-25 11:13:44 +120015251 VkDescriptorSetObj descriptorSet(m_device);
15252 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015253 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015254
Tony Barbour5781e8f2015-08-04 16:23:11 -060015255 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015256
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015257 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015258}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015259
Karl Schultz6addd812016-02-02 17:17:23 -070015260TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015261 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
15262 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015264
Chris Forbes556c76c2015-08-14 12:04:59 +120015265 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015267 char const *vsSource = "#version 450\n"
15268 "\n"
15269 "out gl_PerVertex {\n"
15270 " vec4 gl_Position;\n"
15271 "};\n"
15272 "void main(){\n"
15273 " gl_Position = vec4(1);\n"
15274 "}\n";
15275 char const *fsSource = "#version 450\n"
15276 "\n"
15277 "layout(location=0) out vec4 x;\n"
15278 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15279 "void main(){\n"
15280 " x = vec4(bar.y);\n"
15281 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015282
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015285
Chris Forbes556c76c2015-08-14 12:04:59 +120015286 VkPipelineObj pipe(m_device);
15287 pipe.AddShader(&vs);
15288 pipe.AddShader(&fs);
15289
15290 /* set up CB 0; type is UNORM by default */
15291 pipe.AddColorAttachment();
15292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15293
15294 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015295 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015296
15297 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15298
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015299 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015300}
15301
Chris Forbes5c59e902016-02-26 16:56:09 +130015302TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015303 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
15304 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015306
15307 ASSERT_NO_FATAL_FAILURE(InitState());
15308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 char const *vsSource = "#version 450\n"
15310 "\n"
15311 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15312 "out gl_PerVertex {\n"
15313 " vec4 gl_Position;\n"
15314 "};\n"
15315 "void main(){\n"
15316 " gl_Position = vec4(consts.x);\n"
15317 "}\n";
15318 char const *fsSource = "#version 450\n"
15319 "\n"
15320 "layout(location=0) out vec4 x;\n"
15321 "void main(){\n"
15322 " x = vec4(1);\n"
15323 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015324
15325 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15326 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15327
15328 VkPipelineObj pipe(m_device);
15329 pipe.AddShader(&vs);
15330 pipe.AddShader(&fs);
15331
15332 /* set up CB 0; type is UNORM by default */
15333 pipe.AddColorAttachment();
15334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15335
15336 VkDescriptorSetObj descriptorSet(m_device);
15337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15338
15339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15340
15341 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015342 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015343}
15344
Chris Forbes3fb17902016-08-22 14:57:55 +120015345TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
15346 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15347 "which is not included in the subpass description");
15348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15349 "consumes input attachment index 0 but not provided in subpass");
15350
15351 ASSERT_NO_FATAL_FAILURE(InitState());
15352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 char const *vsSource = "#version 450\n"
15354 "\n"
15355 "out gl_PerVertex {\n"
15356 " vec4 gl_Position;\n"
15357 "};\n"
15358 "void main(){\n"
15359 " gl_Position = vec4(1);\n"
15360 "}\n";
15361 char const *fsSource = "#version 450\n"
15362 "\n"
15363 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15364 "layout(location=0) out vec4 color;\n"
15365 "void main() {\n"
15366 " color = subpassLoad(x);\n"
15367 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015368
15369 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15370 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15371
15372 VkPipelineObj pipe(m_device);
15373 pipe.AddShader(&vs);
15374 pipe.AddShader(&fs);
15375 pipe.AddColorAttachment();
15376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015378 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15379 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015380 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015381 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015382 ASSERT_VK_SUCCESS(err);
15383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015384 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015385 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015386 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015387 ASSERT_VK_SUCCESS(err);
15388
15389 // error here.
15390 pipe.CreateVKPipeline(pl, renderPass());
15391
15392 m_errorMonitor->VerifyFound();
15393
15394 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15395 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15396}
15397
Chris Forbes663b5a82016-08-22 16:14:06 +120015398TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
15399 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
15400 m_errorMonitor->ExpectSuccess();
15401
15402 ASSERT_NO_FATAL_FAILURE(InitState());
15403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015404 char const *vsSource = "#version 450\n"
15405 "\n"
15406 "out gl_PerVertex {\n"
15407 " vec4 gl_Position;\n"
15408 "};\n"
15409 "void main(){\n"
15410 " gl_Position = vec4(1);\n"
15411 "}\n";
15412 char const *fsSource = "#version 450\n"
15413 "\n"
15414 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15415 "layout(location=0) out vec4 color;\n"
15416 "void main() {\n"
15417 " color = subpassLoad(x);\n"
15418 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120015419
15420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15422
15423 VkPipelineObj pipe(m_device);
15424 pipe.AddShader(&vs);
15425 pipe.AddShader(&fs);
15426 pipe.AddColorAttachment();
15427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015429 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15430 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120015431 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015432 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015433 ASSERT_VK_SUCCESS(err);
15434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015435 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015436 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015437 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015438 ASSERT_VK_SUCCESS(err);
15439
15440 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015441 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15442 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15443 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15444 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15445 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes663b5a82016-08-22 16:14:06 +120015446 };
15447 VkAttachmentReference color = {
15448 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15449 };
15450 VkAttachmentReference input = {
15451 1, VK_IMAGE_LAYOUT_GENERAL,
15452 };
15453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015454 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015456 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015457 VkRenderPass rp;
15458 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15459 ASSERT_VK_SUCCESS(err);
15460
15461 // should be OK. would go wrong here if it's going to...
15462 pipe.CreateVKPipeline(pl, rp);
15463
15464 m_errorMonitor->VerifyNotFound();
15465
15466 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15467 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15468 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15469}
15470
Chris Forbes5a9a0472016-08-22 16:02:09 +120015471TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
15472 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15473 "with a format having a different fundamental type");
15474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15475 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15476
15477 ASSERT_NO_FATAL_FAILURE(InitState());
15478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015479 char const *vsSource = "#version 450\n"
15480 "\n"
15481 "out gl_PerVertex {\n"
15482 " vec4 gl_Position;\n"
15483 "};\n"
15484 "void main(){\n"
15485 " gl_Position = vec4(1);\n"
15486 "}\n";
15487 char const *fsSource = "#version 450\n"
15488 "\n"
15489 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15490 "layout(location=0) out vec4 color;\n"
15491 "void main() {\n"
15492 " color = subpassLoad(x);\n"
15493 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015494
15495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15497
15498 VkPipelineObj pipe(m_device);
15499 pipe.AddShader(&vs);
15500 pipe.AddShader(&fs);
15501 pipe.AddColorAttachment();
15502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015504 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15505 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015506 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015507 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015508 ASSERT_VK_SUCCESS(err);
15509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015510 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015511 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015512 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015513 ASSERT_VK_SUCCESS(err);
15514
15515 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015516 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15517 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15518 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15519 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15520 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 +120015521 };
15522 VkAttachmentReference color = {
15523 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15524 };
15525 VkAttachmentReference input = {
15526 1, VK_IMAGE_LAYOUT_GENERAL,
15527 };
15528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015529 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015531 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015532 VkRenderPass rp;
15533 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15534 ASSERT_VK_SUCCESS(err);
15535
15536 // error here.
15537 pipe.CreateVKPipeline(pl, rp);
15538
15539 m_errorMonitor->VerifyFound();
15540
15541 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15542 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15543 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15544}
15545
Chris Forbes541f7b02016-08-22 15:30:27 +120015546TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
15547 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15548 "which is not included in the subpass description -- array case");
15549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15550 "consumes input attachment index 1 but not provided in subpass");
15551
15552 ASSERT_NO_FATAL_FAILURE(InitState());
15553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015554 char const *vsSource = "#version 450\n"
15555 "\n"
15556 "out gl_PerVertex {\n"
15557 " vec4 gl_Position;\n"
15558 "};\n"
15559 "void main(){\n"
15560 " gl_Position = vec4(1);\n"
15561 "}\n";
15562 char const *fsSource = "#version 450\n"
15563 "\n"
15564 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15565 "layout(location=0) out vec4 color;\n"
15566 "void main() {\n"
15567 " color = subpassLoad(xs[1]);\n"
15568 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015569
15570 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15571 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15572
15573 VkPipelineObj pipe(m_device);
15574 pipe.AddShader(&vs);
15575 pipe.AddShader(&fs);
15576 pipe.AddColorAttachment();
15577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15580 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015581 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015583 ASSERT_VK_SUCCESS(err);
15584
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015585 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015586 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015587 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015588 ASSERT_VK_SUCCESS(err);
15589
15590 // error here.
15591 pipe.CreateVKPipeline(pl, renderPass());
15592
15593 m_errorMonitor->VerifyFound();
15594
15595 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15596 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15597}
15598
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015599TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015600 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15601 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015603
15604 ASSERT_NO_FATAL_FAILURE(InitState());
15605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015606 char const *csSource = "#version 450\n"
15607 "\n"
15608 "layout(local_size_x=1) in;\n"
15609 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15610 "void main(){\n"
15611 " x = vec4(1);\n"
15612 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015613
15614 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15615
15616 VkDescriptorSetObj descriptorSet(m_device);
15617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015619 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15620 nullptr,
15621 0,
15622 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15623 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15624 descriptorSet.GetPipelineLayout(),
15625 VK_NULL_HANDLE,
15626 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015627
15628 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015629 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015630
15631 m_errorMonitor->VerifyFound();
15632
15633 if (err == VK_SUCCESS) {
15634 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15635 }
15636}
15637
15638TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015639 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15640 "descriptor-backed resource which is not provided, but the shader does not "
15641 "statically use it. This is interesting because it requires compute pipelines "
15642 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015643 m_errorMonitor->ExpectSuccess();
15644
15645 ASSERT_NO_FATAL_FAILURE(InitState());
15646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015647 char const *csSource = "#version 450\n"
15648 "\n"
15649 "layout(local_size_x=1) in;\n"
15650 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15651 "void main(){\n"
15652 " // x is not used.\n"
15653 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015654
15655 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15656
15657 VkDescriptorSetObj descriptorSet(m_device);
15658 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015660 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15661 nullptr,
15662 0,
15663 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15664 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15665 descriptorSet.GetPipelineLayout(),
15666 VK_NULL_HANDLE,
15667 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015668
15669 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015670 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015671
15672 m_errorMonitor->VerifyNotFound();
15673
15674 if (err == VK_SUCCESS) {
15675 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15676 }
15677}
15678
Chris Forbes22a9b092016-07-19 14:34:05 +120015679TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015680 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15681 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15683 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015684
15685 ASSERT_NO_FATAL_FAILURE(InitState());
15686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015687 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15688 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015689 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015690 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015691 ASSERT_VK_SUCCESS(err);
15692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015694 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015695 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015696 ASSERT_VK_SUCCESS(err);
15697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015698 char const *csSource = "#version 450\n"
15699 "\n"
15700 "layout(local_size_x=1) in;\n"
15701 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15702 "void main() {\n"
15703 " x.x = 1.0f;\n"
15704 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015705 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015707 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15708 nullptr,
15709 0,
15710 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15711 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15712 pl,
15713 VK_NULL_HANDLE,
15714 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015715
15716 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015717 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015718
15719 m_errorMonitor->VerifyFound();
15720
15721 if (err == VK_SUCCESS) {
15722 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15723 }
15724
15725 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15726 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15727}
15728
Chris Forbese10a51f2016-07-19 14:42:51 +120015729TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015730 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15731 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015732 m_errorMonitor->ExpectSuccess();
15733
15734 ASSERT_NO_FATAL_FAILURE(InitState());
15735
15736 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015737 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15738 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15739 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015740 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015741 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015742 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015743 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015744 ASSERT_VK_SUCCESS(err);
15745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015746 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015747 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015748 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015749 ASSERT_VK_SUCCESS(err);
15750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015751 char const *csSource = "#version 450\n"
15752 "\n"
15753 "layout(local_size_x=1) in;\n"
15754 "layout(set=0, binding=0) uniform sampler s;\n"
15755 "layout(set=0, binding=1) uniform texture2D t;\n"
15756 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15757 "void main() {\n"
15758 " x = texture(sampler2D(t, s), vec2(0));\n"
15759 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015760 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015762 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15763 nullptr,
15764 0,
15765 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15766 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15767 pl,
15768 VK_NULL_HANDLE,
15769 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015770
15771 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015772 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015773
15774 m_errorMonitor->VerifyNotFound();
15775
15776 if (err == VK_SUCCESS) {
15777 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15778 }
15779
15780 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15781 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15782}
15783
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015784TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015785 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15786 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015787 m_errorMonitor->ExpectSuccess();
15788
15789 ASSERT_NO_FATAL_FAILURE(InitState());
15790
15791 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015792 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15793 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15794 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015795 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015796 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015797 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015798 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015799 ASSERT_VK_SUCCESS(err);
15800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015801 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015802 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015803 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015804 ASSERT_VK_SUCCESS(err);
15805
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015806 char const *csSource = "#version 450\n"
15807 "\n"
15808 "layout(local_size_x=1) in;\n"
15809 "layout(set=0, binding=0) uniform texture2D t;\n"
15810 "layout(set=0, binding=1) uniform sampler s;\n"
15811 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15812 "void main() {\n"
15813 " x = texture(sampler2D(t, s), vec2(0));\n"
15814 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015815 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015817 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15818 nullptr,
15819 0,
15820 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15821 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15822 pl,
15823 VK_NULL_HANDLE,
15824 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015825
15826 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015827 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015828
15829 m_errorMonitor->VerifyNotFound();
15830
15831 if (err == VK_SUCCESS) {
15832 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15833 }
15834
15835 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15836 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15837}
15838
Chris Forbes6a4991a2016-07-19 15:07:32 +120015839TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015840 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15841 "both the sampler and the image of a combined image+sampler "
15842 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015843 m_errorMonitor->ExpectSuccess();
15844
15845 ASSERT_NO_FATAL_FAILURE(InitState());
15846
15847 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015848 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15849 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015850 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015851 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015852 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015853 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015854 ASSERT_VK_SUCCESS(err);
15855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015856 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015857 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015858 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015859 ASSERT_VK_SUCCESS(err);
15860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015861 char const *csSource = "#version 450\n"
15862 "\n"
15863 "layout(local_size_x=1) in;\n"
15864 "layout(set=0, binding=0) uniform texture2D t;\n"
15865 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15866 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15867 "void main() {\n"
15868 " x = texture(sampler2D(t, s), vec2(0));\n"
15869 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015870 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015872 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15873 nullptr,
15874 0,
15875 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15876 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15877 pl,
15878 VK_NULL_HANDLE,
15879 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015880
15881 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015882 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015883
15884 m_errorMonitor->VerifyNotFound();
15885
15886 if (err == VK_SUCCESS) {
15887 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15888 }
15889
15890 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15891 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15892}
15893
Chris Forbes50020592016-07-27 13:52:41 +120015894TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15895 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15896 "does not match the dimensionality declared in the shader");
15897
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015898 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 +120015899
15900 ASSERT_NO_FATAL_FAILURE(InitState());
15901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015903 char const *vsSource = "#version 450\n"
15904 "\n"
15905 "out gl_PerVertex { vec4 gl_Position; };\n"
15906 "void main() { gl_Position = vec4(0); }\n";
15907 char const *fsSource = "#version 450\n"
15908 "\n"
15909 "layout(set=0, binding=0) uniform sampler3D s;\n"
15910 "layout(location=0) out vec4 color;\n"
15911 "void main() {\n"
15912 " color = texture(s, vec3(0));\n"
15913 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15916
15917 VkPipelineObj pipe(m_device);
15918 pipe.AddShader(&vs);
15919 pipe.AddShader(&fs);
15920 pipe.AddColorAttachment();
15921
15922 VkTextureObj texture(m_device, nullptr);
15923 VkSamplerObj sampler(m_device);
15924
15925 VkDescriptorSetObj descriptorSet(m_device);
15926 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15928
15929 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15930 ASSERT_VK_SUCCESS(err);
15931
15932 BeginCommandBuffer();
15933
15934 m_commandBuffer->BindPipeline(pipe);
15935 m_commandBuffer->BindDescriptorSet(descriptorSet);
15936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015937 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015938 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015939 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015940 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15941
15942 // error produced here.
15943 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15944
15945 m_errorMonitor->VerifyFound();
15946
15947 EndCommandBuffer();
15948}
15949
Chris Forbes5533bfc2016-07-27 14:12:34 +120015950TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15951 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15952 "are consumed via singlesample images types in the shader, or vice versa.");
15953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015955
15956 ASSERT_NO_FATAL_FAILURE(InitState());
15957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015959 char const *vsSource = "#version 450\n"
15960 "\n"
15961 "out gl_PerVertex { vec4 gl_Position; };\n"
15962 "void main() { gl_Position = vec4(0); }\n";
15963 char const *fsSource = "#version 450\n"
15964 "\n"
15965 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15966 "layout(location=0) out vec4 color;\n"
15967 "void main() {\n"
15968 " color = texelFetch(s, ivec2(0), 0);\n"
15969 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15972
15973 VkPipelineObj pipe(m_device);
15974 pipe.AddShader(&vs);
15975 pipe.AddShader(&fs);
15976 pipe.AddColorAttachment();
15977
15978 VkTextureObj texture(m_device, nullptr);
15979 VkSamplerObj sampler(m_device);
15980
15981 VkDescriptorSetObj descriptorSet(m_device);
15982 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15983 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15984
15985 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15986 ASSERT_VK_SUCCESS(err);
15987
15988 BeginCommandBuffer();
15989
15990 m_commandBuffer->BindPipeline(pipe);
15991 m_commandBuffer->BindDescriptorSet(descriptorSet);
15992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015993 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015994 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015995 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015996 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15997
15998 // error produced here.
15999 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16000
16001 m_errorMonitor->VerifyFound();
16002
16003 EndCommandBuffer();
16004}
16005
Mark Lobodzinski209b5292015-09-17 09:44:05 -060016006#endif // SHADER_CHECKER_TESTS
16007
16008#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060016009TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016011
16012 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016013
16014 // Create an image
16015 VkImage image;
16016
Karl Schultz6addd812016-02-02 17:17:23 -070016017 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16018 const int32_t tex_width = 32;
16019 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016020
16021 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016022 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16023 image_create_info.pNext = NULL;
16024 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16025 image_create_info.format = tex_format;
16026 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016027 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070016028 image_create_info.extent.depth = 1;
16029 image_create_info.mipLevels = 1;
16030 image_create_info.arrayLayers = 1;
16031 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16032 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16033 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16034 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016035
16036 // Introduce error by sending down a bogus width extent
16037 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080016038 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016039
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016040 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016041}
16042
Mark Youngc48c4c12016-04-11 14:26:49 -060016043TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16045 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060016046
16047 ASSERT_NO_FATAL_FAILURE(InitState());
16048
16049 // Create an image
16050 VkImage image;
16051
16052 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16053 const int32_t tex_width = 32;
16054 const int32_t tex_height = 32;
16055
16056 VkImageCreateInfo image_create_info = {};
16057 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16058 image_create_info.pNext = NULL;
16059 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16060 image_create_info.format = tex_format;
16061 image_create_info.extent.width = tex_width;
16062 image_create_info.extent.height = tex_height;
16063 image_create_info.extent.depth = 1;
16064 image_create_info.mipLevels = 1;
16065 image_create_info.arrayLayers = 1;
16066 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16067 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16068 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16069 image_create_info.flags = 0;
16070
16071 // Introduce error by sending down a bogus width extent
16072 image_create_info.extent.width = 0;
16073 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16074
16075 m_errorMonitor->VerifyFound();
16076}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060016077#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120016078
Tobin Ehliscde08892015-09-22 10:11:37 -060016079#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016080TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
16081 TEST_DESCRIPTION("Create a render pass with an attachment description "
16082 "format set to VK_FORMAT_UNDEFINED");
16083
16084 ASSERT_NO_FATAL_FAILURE(InitState());
16085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016088
16089 VkAttachmentReference color_attach = {};
16090 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16091 color_attach.attachment = 0;
16092 VkSubpassDescription subpass = {};
16093 subpass.colorAttachmentCount = 1;
16094 subpass.pColorAttachments = &color_attach;
16095
16096 VkRenderPassCreateInfo rpci = {};
16097 rpci.subpassCount = 1;
16098 rpci.pSubpasses = &subpass;
16099 rpci.attachmentCount = 1;
16100 VkAttachmentDescription attach_desc = {};
16101 attach_desc.format = VK_FORMAT_UNDEFINED;
16102 rpci.pAttachments = &attach_desc;
16103 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16104 VkRenderPass rp;
16105 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16106
16107 m_errorMonitor->VerifyFound();
16108
16109 if (result == VK_SUCCESS) {
16110 vkDestroyRenderPass(m_device->device(), rp, NULL);
16111 }
16112}
16113
Karl Schultz6addd812016-02-02 17:17:23 -070016114TEST_F(VkLayerTest, InvalidImageView) {
16115 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060016116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016118
Tobin Ehliscde08892015-09-22 10:11:37 -060016119 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060016120
Mike Stroyana3082432015-09-25 13:39:21 -060016121 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070016122 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060016123
Karl Schultz6addd812016-02-02 17:17:23 -070016124 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16125 const int32_t tex_width = 32;
16126 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060016127
16128 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016129 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16130 image_create_info.pNext = NULL;
16131 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16132 image_create_info.format = tex_format;
16133 image_create_info.extent.width = tex_width;
16134 image_create_info.extent.height = tex_height;
16135 image_create_info.extent.depth = 1;
16136 image_create_info.mipLevels = 1;
16137 image_create_info.arrayLayers = 1;
16138 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16139 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16140 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16141 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060016142
Chia-I Wuf7458c52015-10-26 21:10:41 +080016143 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060016144 ASSERT_VK_SUCCESS(err);
16145
16146 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016147 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16148 image_view_create_info.image = image;
16149 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16150 image_view_create_info.format = tex_format;
16151 image_view_create_info.subresourceRange.layerCount = 1;
16152 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
16153 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016154 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060016155
16156 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016157 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060016158
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016159 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060016160 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016161}
Mike Stroyana3082432015-09-25 13:39:21 -060016162
Mark Youngd339ba32016-05-30 13:28:35 -060016163TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16164 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016166 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016167
16168 ASSERT_NO_FATAL_FAILURE(InitState());
16169
16170 // Create an image and try to create a view with no memory backing the image
16171 VkImage image;
16172
16173 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16174 const int32_t tex_width = 32;
16175 const int32_t tex_height = 32;
16176
16177 VkImageCreateInfo image_create_info = {};
16178 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16179 image_create_info.pNext = NULL;
16180 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16181 image_create_info.format = tex_format;
16182 image_create_info.extent.width = tex_width;
16183 image_create_info.extent.height = tex_height;
16184 image_create_info.extent.depth = 1;
16185 image_create_info.mipLevels = 1;
16186 image_create_info.arrayLayers = 1;
16187 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16188 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16189 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16190 image_create_info.flags = 0;
16191
16192 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16193 ASSERT_VK_SUCCESS(err);
16194
16195 VkImageViewCreateInfo image_view_create_info = {};
16196 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16197 image_view_create_info.image = image;
16198 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16199 image_view_create_info.format = tex_format;
16200 image_view_create_info.subresourceRange.layerCount = 1;
16201 image_view_create_info.subresourceRange.baseMipLevel = 0;
16202 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016203 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016204
16205 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016206 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016207
16208 m_errorMonitor->VerifyFound();
16209 vkDestroyImage(m_device->device(), image, NULL);
16210 // If last error is success, it still created the view, so delete it.
16211 if (err == VK_SUCCESS) {
16212 vkDestroyImageView(m_device->device(), view, NULL);
16213 }
Mark Youngd339ba32016-05-30 13:28:35 -060016214}
16215
Karl Schultz6addd812016-02-02 17:17:23 -070016216TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016217 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
16218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
16219 "formats must have ONLY the "
16220 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016221
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016222 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016223
Karl Schultz6addd812016-02-02 17:17:23 -070016224 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016225 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016226 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016227 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016228
16229 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016230 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016231 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016232 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16233 image_view_create_info.format = tex_format;
16234 image_view_create_info.subresourceRange.baseMipLevel = 0;
16235 image_view_create_info.subresourceRange.levelCount = 1;
16236 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016237 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016238
16239 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016240 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016241
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016242 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016243}
16244
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016245TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016246 VkResult err;
16247 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16250 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016251
Mike Stroyana3082432015-09-25 13:39:21 -060016252 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016253
16254 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016255 VkImage srcImage;
16256 VkImage dstImage;
16257 VkDeviceMemory srcMem;
16258 VkDeviceMemory destMem;
16259 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016260
16261 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016262 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16263 image_create_info.pNext = NULL;
16264 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16265 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16266 image_create_info.extent.width = 32;
16267 image_create_info.extent.height = 32;
16268 image_create_info.extent.depth = 1;
16269 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016270 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016271 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16272 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16273 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16274 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016276 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016277 ASSERT_VK_SUCCESS(err);
16278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016279 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016280 ASSERT_VK_SUCCESS(err);
16281
16282 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016283 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016284 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16285 memAlloc.pNext = NULL;
16286 memAlloc.allocationSize = 0;
16287 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016288
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016289 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016290 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016291 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016292 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016293 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016294 ASSERT_VK_SUCCESS(err);
16295
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016296 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016297 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016298 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016299 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016300 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016301 ASSERT_VK_SUCCESS(err);
16302
16303 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16304 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016305 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016306 ASSERT_VK_SUCCESS(err);
16307
16308 BeginCommandBuffer();
16309 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016310 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016311 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016312 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016313 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016314 copyRegion.srcOffset.x = 0;
16315 copyRegion.srcOffset.y = 0;
16316 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016317 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016318 copyRegion.dstSubresource.mipLevel = 0;
16319 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016320 // Introduce failure by forcing the dst layerCount to differ from src
16321 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016322 copyRegion.dstOffset.x = 0;
16323 copyRegion.dstOffset.y = 0;
16324 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016325 copyRegion.extent.width = 1;
16326 copyRegion.extent.height = 1;
16327 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016328 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016329 EndCommandBuffer();
16330
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016331 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016332
Chia-I Wuf7458c52015-10-26 21:10:41 +080016333 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016334 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016335 vkFreeMemory(m_device->device(), srcMem, NULL);
16336 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016337}
16338
Tony Barbourd6673642016-05-05 14:46:39 -060016339TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
16340
16341 TEST_DESCRIPTION("Creating images with unsuported formats ");
16342
16343 ASSERT_NO_FATAL_FAILURE(InitState());
16344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16345 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016346 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 -060016347 VK_IMAGE_TILING_OPTIMAL, 0);
16348 ASSERT_TRUE(image.initialized());
16349
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016350 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
16351 VkImageCreateInfo image_create_info;
16352 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16353 image_create_info.pNext = NULL;
16354 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16355 image_create_info.format = VK_FORMAT_UNDEFINED;
16356 image_create_info.extent.width = 32;
16357 image_create_info.extent.height = 32;
16358 image_create_info.extent.depth = 1;
16359 image_create_info.mipLevels = 1;
16360 image_create_info.arrayLayers = 1;
16361 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16362 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16363 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16364 image_create_info.flags = 0;
16365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16367 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016368
16369 VkImage localImage;
16370 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
16371 m_errorMonitor->VerifyFound();
16372
Tony Barbourd6673642016-05-05 14:46:39 -060016373 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016374 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060016375 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16376 VkFormat format = static_cast<VkFormat>(f);
16377 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016378 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016379 unsupported = format;
16380 break;
16381 }
16382 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016383
Tony Barbourd6673642016-05-05 14:46:39 -060016384 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016385 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016387
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016388 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016389 m_errorMonitor->VerifyFound();
16390 }
16391}
16392
16393TEST_F(VkLayerTest, ImageLayerViewTests) {
16394 VkResult ret;
16395 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16396
16397 ASSERT_NO_FATAL_FAILURE(InitState());
16398
16399 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016400 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 -060016401 VK_IMAGE_TILING_OPTIMAL, 0);
16402 ASSERT_TRUE(image.initialized());
16403
16404 VkImageView imgView;
16405 VkImageViewCreateInfo imgViewInfo = {};
16406 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16407 imgViewInfo.image = image.handle();
16408 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16409 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16410 imgViewInfo.subresourceRange.layerCount = 1;
16411 imgViewInfo.subresourceRange.baseMipLevel = 0;
16412 imgViewInfo.subresourceRange.levelCount = 1;
16413 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060016416 // View can't have baseMipLevel >= image's mipLevels - Expect
16417 // VIEW_CREATE_ERROR
16418 imgViewInfo.subresourceRange.baseMipLevel = 1;
16419 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16420 m_errorMonitor->VerifyFound();
16421 imgViewInfo.subresourceRange.baseMipLevel = 0;
16422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060016424 // View can't have baseArrayLayer >= image's arraySize - Expect
16425 // VIEW_CREATE_ERROR
16426 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16427 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16428 m_errorMonitor->VerifyFound();
16429 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16432 "pCreateInfo->subresourceRange."
16433 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016434 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16435 imgViewInfo.subresourceRange.levelCount = 0;
16436 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16437 m_errorMonitor->VerifyFound();
16438 imgViewInfo.subresourceRange.levelCount = 1;
16439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16441 "pCreateInfo->subresourceRange."
16442 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016443 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16444 imgViewInfo.subresourceRange.layerCount = 0;
16445 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16446 m_errorMonitor->VerifyFound();
16447 imgViewInfo.subresourceRange.layerCount = 1;
16448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060016450 // Can't use depth format for view into color image - Expect INVALID_FORMAT
16451 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
16452 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16453 m_errorMonitor->VerifyFound();
16454 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
16457 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16458 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016459 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16460 // VIEW_CREATE_ERROR
16461 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16462 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16463 m_errorMonitor->VerifyFound();
16464 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
16467 "differing formats but they must be "
16468 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060016469 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16470 // VIEW_CREATE_ERROR
16471 VkImageCreateInfo mutImgInfo = image.create_info();
16472 VkImage mutImage;
16473 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016474 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016475 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16476 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16477 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16478 ASSERT_VK_SUCCESS(ret);
16479 imgViewInfo.image = mutImage;
16480 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16481 m_errorMonitor->VerifyFound();
16482 imgViewInfo.image = image.handle();
16483 vkDestroyImage(m_device->handle(), mutImage, NULL);
16484}
16485
16486TEST_F(VkLayerTest, MiscImageLayerTests) {
16487
16488 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16489
16490 ASSERT_NO_FATAL_FAILURE(InitState());
16491
16492 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016493 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 -060016494 VK_IMAGE_TILING_OPTIMAL, 0);
16495 ASSERT_TRUE(image.initialized());
16496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060016498 vk_testing::Buffer buffer;
16499 VkMemoryPropertyFlags reqs = 0;
16500 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
16501 VkBufferImageCopy region = {};
16502 region.bufferRowLength = 128;
16503 region.bufferImageHeight = 128;
16504 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16505 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16506 region.imageSubresource.layerCount = 0;
16507 region.imageExtent.height = 4;
16508 region.imageExtent.width = 4;
16509 region.imageExtent.depth = 1;
16510 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016511 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16512 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016513 m_errorMonitor->VerifyFound();
16514 region.imageSubresource.layerCount = 1;
16515
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016516 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16517 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
16518 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
16520 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16521 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016522 m_errorMonitor->VerifyFound();
16523
16524 // BufferOffset must be a multiple of 4
16525 // Introduce failure by setting bufferOffset to a value not divisible by 4
16526 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
16528 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16529 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016530 m_errorMonitor->VerifyFound();
16531
16532 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16533 region.bufferOffset = 0;
16534 region.imageExtent.height = 128;
16535 region.imageExtent.width = 128;
16536 // Introduce failure by setting bufferRowLength > 0 but less than width
16537 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16539 "must be zero or greater-than-or-equal-to imageExtent.width");
16540 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16541 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016542 m_errorMonitor->VerifyFound();
16543
16544 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16545 region.bufferRowLength = 128;
16546 // Introduce failure by setting bufferRowHeight > 0 but less than height
16547 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16549 "must be zero or greater-than-or-equal-to imageExtent.height");
16550 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16551 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016552 m_errorMonitor->VerifyFound();
16553
16554 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
16556 "specify only COLOR or DEPTH or "
16557 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060016558 // Expect MISMATCHED_IMAGE_ASPECT
16559 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016560 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16561 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016562 m_errorMonitor->VerifyFound();
16563 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16566 "If the format of srcImage is a depth, stencil, depth stencil or "
16567 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016568 // Expect INVALID_FILTER
16569 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016570 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 -060016571 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016572 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 -060016573 VkImageBlit blitRegion = {};
16574 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16575 blitRegion.srcSubresource.baseArrayLayer = 0;
16576 blitRegion.srcSubresource.layerCount = 1;
16577 blitRegion.srcSubresource.mipLevel = 0;
16578 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16579 blitRegion.dstSubresource.baseArrayLayer = 0;
16580 blitRegion.dstSubresource.layerCount = 1;
16581 blitRegion.dstSubresource.mipLevel = 0;
16582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016583 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16584 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016585 m_errorMonitor->VerifyFound();
16586
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016587 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16589 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16590 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016591 m_errorMonitor->VerifyFound();
16592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016594 VkImageMemoryBarrier img_barrier;
16595 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16596 img_barrier.pNext = NULL;
16597 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16598 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16599 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16600 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16601 img_barrier.image = image.handle();
16602 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16603 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16604 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16605 img_barrier.subresourceRange.baseArrayLayer = 0;
16606 img_barrier.subresourceRange.baseMipLevel = 0;
16607 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16608 img_barrier.subresourceRange.layerCount = 0;
16609 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016610 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16611 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016612 m_errorMonitor->VerifyFound();
16613 img_barrier.subresourceRange.layerCount = 1;
16614}
16615
16616TEST_F(VkLayerTest, ImageFormatLimits) {
16617
16618 TEST_DESCRIPTION("Exceed the limits of image format ");
16619
Cody Northropc31a84f2016-08-22 10:41:47 -060016620 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016622 VkImageCreateInfo image_create_info = {};
16623 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16624 image_create_info.pNext = NULL;
16625 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16626 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16627 image_create_info.extent.width = 32;
16628 image_create_info.extent.height = 32;
16629 image_create_info.extent.depth = 1;
16630 image_create_info.mipLevels = 1;
16631 image_create_info.arrayLayers = 1;
16632 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16633 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16634 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16635 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16636 image_create_info.flags = 0;
16637
16638 VkImage nullImg;
16639 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016640 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16641 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016642 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16643 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16644 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16645 m_errorMonitor->VerifyFound();
16646 image_create_info.extent.depth = 1;
16647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016649 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16650 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16651 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16652 m_errorMonitor->VerifyFound();
16653 image_create_info.mipLevels = 1;
16654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016656 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16657 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16658 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16659 m_errorMonitor->VerifyFound();
16660 image_create_info.arrayLayers = 1;
16661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016663 int samples = imgFmtProps.sampleCounts >> 1;
16664 image_create_info.samples = (VkSampleCountFlagBits)samples;
16665 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16666 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16667 m_errorMonitor->VerifyFound();
16668 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16671 "VK_IMAGE_LAYOUT_UNDEFINED or "
16672 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016673 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16674 // Expect INVALID_LAYOUT
16675 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16676 m_errorMonitor->VerifyFound();
16677 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16678}
16679
Karl Schultz6addd812016-02-02 17:17:23 -070016680TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016681 VkResult err;
16682 bool pass;
16683
16684 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16686 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016687
16688 ASSERT_NO_FATAL_FAILURE(InitState());
16689
16690 // Create two images of different types and try to copy between them
16691 VkImage srcImage;
16692 VkImage dstImage;
16693 VkDeviceMemory srcMem;
16694 VkDeviceMemory destMem;
16695 VkMemoryRequirements memReqs;
16696
16697 VkImageCreateInfo image_create_info = {};
16698 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16699 image_create_info.pNext = NULL;
16700 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16701 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16702 image_create_info.extent.width = 32;
16703 image_create_info.extent.height = 32;
16704 image_create_info.extent.depth = 1;
16705 image_create_info.mipLevels = 1;
16706 image_create_info.arrayLayers = 1;
16707 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16708 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16710 image_create_info.flags = 0;
16711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016712 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016713 ASSERT_VK_SUCCESS(err);
16714
16715 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16716 // Introduce failure by creating second image with a different-sized format.
16717 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016720 ASSERT_VK_SUCCESS(err);
16721
16722 // Allocate memory
16723 VkMemoryAllocateInfo memAlloc = {};
16724 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16725 memAlloc.pNext = NULL;
16726 memAlloc.allocationSize = 0;
16727 memAlloc.memoryTypeIndex = 0;
16728
16729 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16730 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016731 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016732 ASSERT_TRUE(pass);
16733 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16734 ASSERT_VK_SUCCESS(err);
16735
16736 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16737 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016738 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016739 ASSERT_TRUE(pass);
16740 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16741 ASSERT_VK_SUCCESS(err);
16742
16743 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16744 ASSERT_VK_SUCCESS(err);
16745 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16746 ASSERT_VK_SUCCESS(err);
16747
16748 BeginCommandBuffer();
16749 VkImageCopy copyRegion;
16750 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16751 copyRegion.srcSubresource.mipLevel = 0;
16752 copyRegion.srcSubresource.baseArrayLayer = 0;
16753 copyRegion.srcSubresource.layerCount = 0;
16754 copyRegion.srcOffset.x = 0;
16755 copyRegion.srcOffset.y = 0;
16756 copyRegion.srcOffset.z = 0;
16757 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16758 copyRegion.dstSubresource.mipLevel = 0;
16759 copyRegion.dstSubresource.baseArrayLayer = 0;
16760 copyRegion.dstSubresource.layerCount = 0;
16761 copyRegion.dstOffset.x = 0;
16762 copyRegion.dstOffset.y = 0;
16763 copyRegion.dstOffset.z = 0;
16764 copyRegion.extent.width = 1;
16765 copyRegion.extent.height = 1;
16766 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016767 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016768 EndCommandBuffer();
16769
16770 m_errorMonitor->VerifyFound();
16771
16772 vkDestroyImage(m_device->device(), srcImage, NULL);
16773 vkDestroyImage(m_device->device(), dstImage, NULL);
16774 vkFreeMemory(m_device->device(), srcMem, NULL);
16775 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016776}
16777
Karl Schultz6addd812016-02-02 17:17:23 -070016778TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16779 VkResult err;
16780 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016781
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016782 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16784 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016785
Mike Stroyana3082432015-09-25 13:39:21 -060016786 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016787
16788 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016789 VkImage srcImage;
16790 VkImage dstImage;
16791 VkDeviceMemory srcMem;
16792 VkDeviceMemory destMem;
16793 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016794
16795 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016796 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16797 image_create_info.pNext = NULL;
16798 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16799 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16800 image_create_info.extent.width = 32;
16801 image_create_info.extent.height = 32;
16802 image_create_info.extent.depth = 1;
16803 image_create_info.mipLevels = 1;
16804 image_create_info.arrayLayers = 1;
16805 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16806 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16807 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16808 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016809
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016810 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016811 ASSERT_VK_SUCCESS(err);
16812
Karl Schultzbdb75952016-04-19 11:36:49 -060016813 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16814
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016815 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016816 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016817 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16818 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016820 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016821 ASSERT_VK_SUCCESS(err);
16822
16823 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016824 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016825 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16826 memAlloc.pNext = NULL;
16827 memAlloc.allocationSize = 0;
16828 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016829
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016830 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016831 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016832 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016833 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016834 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016835 ASSERT_VK_SUCCESS(err);
16836
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016837 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016838 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016839 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016840 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016841 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016842 ASSERT_VK_SUCCESS(err);
16843
16844 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16845 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016846 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016847 ASSERT_VK_SUCCESS(err);
16848
16849 BeginCommandBuffer();
16850 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016851 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016852 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016853 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016854 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016855 copyRegion.srcOffset.x = 0;
16856 copyRegion.srcOffset.y = 0;
16857 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016858 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016859 copyRegion.dstSubresource.mipLevel = 0;
16860 copyRegion.dstSubresource.baseArrayLayer = 0;
16861 copyRegion.dstSubresource.layerCount = 0;
16862 copyRegion.dstOffset.x = 0;
16863 copyRegion.dstOffset.y = 0;
16864 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016865 copyRegion.extent.width = 1;
16866 copyRegion.extent.height = 1;
16867 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016868 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016869 EndCommandBuffer();
16870
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016871 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016872
Chia-I Wuf7458c52015-10-26 21:10:41 +080016873 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016874 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016875 vkFreeMemory(m_device->device(), srcMem, NULL);
16876 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016877}
16878
Karl Schultz6addd812016-02-02 17:17:23 -070016879TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16880 VkResult err;
16881 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16884 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016885
Mike Stroyana3082432015-09-25 13:39:21 -060016886 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016887
16888 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016889 VkImage srcImage;
16890 VkImage dstImage;
16891 VkDeviceMemory srcMem;
16892 VkDeviceMemory destMem;
16893 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016894
16895 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016896 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16897 image_create_info.pNext = NULL;
16898 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16899 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16900 image_create_info.extent.width = 32;
16901 image_create_info.extent.height = 1;
16902 image_create_info.extent.depth = 1;
16903 image_create_info.mipLevels = 1;
16904 image_create_info.arrayLayers = 1;
16905 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16906 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16907 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16908 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016909
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016910 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016911 ASSERT_VK_SUCCESS(err);
16912
Karl Schultz6addd812016-02-02 17:17:23 -070016913 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016914
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016916 ASSERT_VK_SUCCESS(err);
16917
16918 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016919 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016920 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16921 memAlloc.pNext = NULL;
16922 memAlloc.allocationSize = 0;
16923 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016924
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016925 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016926 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016927 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016928 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016929 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016930 ASSERT_VK_SUCCESS(err);
16931
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016932 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016933 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016934 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016935 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016936 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016937 ASSERT_VK_SUCCESS(err);
16938
16939 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16940 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016941 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016942 ASSERT_VK_SUCCESS(err);
16943
16944 BeginCommandBuffer();
16945 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016946 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16947 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016948 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016949 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016950 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016951 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016952 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016953 resolveRegion.srcOffset.x = 0;
16954 resolveRegion.srcOffset.y = 0;
16955 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016956 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016957 resolveRegion.dstSubresource.mipLevel = 0;
16958 resolveRegion.dstSubresource.baseArrayLayer = 0;
16959 resolveRegion.dstSubresource.layerCount = 0;
16960 resolveRegion.dstOffset.x = 0;
16961 resolveRegion.dstOffset.y = 0;
16962 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016963 resolveRegion.extent.width = 1;
16964 resolveRegion.extent.height = 1;
16965 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016966 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016967 EndCommandBuffer();
16968
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016969 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016970
Chia-I Wuf7458c52015-10-26 21:10:41 +080016971 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016972 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016973 vkFreeMemory(m_device->device(), srcMem, NULL);
16974 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016975}
16976
Karl Schultz6addd812016-02-02 17:17:23 -070016977TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16978 VkResult err;
16979 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16982 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016983
Mike Stroyana3082432015-09-25 13:39:21 -060016984 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016985
Chris Forbesa7530692016-05-08 12:35:39 +120016986 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016987 VkImage srcImage;
16988 VkImage dstImage;
16989 VkDeviceMemory srcMem;
16990 VkDeviceMemory destMem;
16991 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016992
16993 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16995 image_create_info.pNext = NULL;
16996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16997 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16998 image_create_info.extent.width = 32;
16999 image_create_info.extent.height = 1;
17000 image_create_info.extent.depth = 1;
17001 image_create_info.mipLevels = 1;
17002 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017003 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017004 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17005 // Note: Some implementations expect color attachment usage for any
17006 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017007 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017008 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017010 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017011 ASSERT_VK_SUCCESS(err);
17012
Karl Schultz6addd812016-02-02 17:17:23 -070017013 // Note: Some implementations expect color attachment usage for any
17014 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017015 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017017 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017018 ASSERT_VK_SUCCESS(err);
17019
17020 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017021 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017022 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17023 memAlloc.pNext = NULL;
17024 memAlloc.allocationSize = 0;
17025 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017026
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017027 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017028 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017029 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017030 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017031 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017032 ASSERT_VK_SUCCESS(err);
17033
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017034 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017035 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017036 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017037 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017038 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017039 ASSERT_VK_SUCCESS(err);
17040
17041 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17042 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017043 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017044 ASSERT_VK_SUCCESS(err);
17045
17046 BeginCommandBuffer();
17047 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017048 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17049 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017050 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017051 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017052 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017053 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017054 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017055 resolveRegion.srcOffset.x = 0;
17056 resolveRegion.srcOffset.y = 0;
17057 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017058 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017059 resolveRegion.dstSubresource.mipLevel = 0;
17060 resolveRegion.dstSubresource.baseArrayLayer = 0;
17061 resolveRegion.dstSubresource.layerCount = 0;
17062 resolveRegion.dstOffset.x = 0;
17063 resolveRegion.dstOffset.y = 0;
17064 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017065 resolveRegion.extent.width = 1;
17066 resolveRegion.extent.height = 1;
17067 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017068 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017069 EndCommandBuffer();
17070
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017071 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017072
Chia-I Wuf7458c52015-10-26 21:10:41 +080017073 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017074 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017075 vkFreeMemory(m_device->device(), srcMem, NULL);
17076 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017077}
17078
Karl Schultz6addd812016-02-02 17:17:23 -070017079TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17080 VkResult err;
17081 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17084 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017085
Mike Stroyana3082432015-09-25 13:39:21 -060017086 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017087
17088 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017089 VkImage srcImage;
17090 VkImage dstImage;
17091 VkDeviceMemory srcMem;
17092 VkDeviceMemory destMem;
17093 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017094
17095 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017096 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17097 image_create_info.pNext = NULL;
17098 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17099 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17100 image_create_info.extent.width = 32;
17101 image_create_info.extent.height = 1;
17102 image_create_info.extent.depth = 1;
17103 image_create_info.mipLevels = 1;
17104 image_create_info.arrayLayers = 1;
17105 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17106 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17107 // Note: Some implementations expect color attachment usage for any
17108 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017109 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017110 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017112 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017113 ASSERT_VK_SUCCESS(err);
17114
Karl Schultz6addd812016-02-02 17:17:23 -070017115 // Set format to something other than source image
17116 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17117 // Note: Some implementations expect color attachment usage for any
17118 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017119 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017120 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017122 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017123 ASSERT_VK_SUCCESS(err);
17124
17125 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017126 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017127 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17128 memAlloc.pNext = NULL;
17129 memAlloc.allocationSize = 0;
17130 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017131
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017132 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017133 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017134 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017135 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017136 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017137 ASSERT_VK_SUCCESS(err);
17138
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017139 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017140 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017141 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017142 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017143 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017144 ASSERT_VK_SUCCESS(err);
17145
17146 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17147 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017148 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017149 ASSERT_VK_SUCCESS(err);
17150
17151 BeginCommandBuffer();
17152 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017153 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17154 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017155 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017156 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017157 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017158 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017159 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017160 resolveRegion.srcOffset.x = 0;
17161 resolveRegion.srcOffset.y = 0;
17162 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017163 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017164 resolveRegion.dstSubresource.mipLevel = 0;
17165 resolveRegion.dstSubresource.baseArrayLayer = 0;
17166 resolveRegion.dstSubresource.layerCount = 0;
17167 resolveRegion.dstOffset.x = 0;
17168 resolveRegion.dstOffset.y = 0;
17169 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017170 resolveRegion.extent.width = 1;
17171 resolveRegion.extent.height = 1;
17172 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017173 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017174 EndCommandBuffer();
17175
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017176 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017177
Chia-I Wuf7458c52015-10-26 21:10:41 +080017178 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017179 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017180 vkFreeMemory(m_device->device(), srcMem, NULL);
17181 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017182}
17183
Karl Schultz6addd812016-02-02 17:17:23 -070017184TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17185 VkResult err;
17186 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17189 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017190
Mike Stroyana3082432015-09-25 13:39:21 -060017191 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017192
17193 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017194 VkImage srcImage;
17195 VkImage dstImage;
17196 VkDeviceMemory srcMem;
17197 VkDeviceMemory destMem;
17198 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017199
17200 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017201 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17202 image_create_info.pNext = NULL;
17203 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17204 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17205 image_create_info.extent.width = 32;
17206 image_create_info.extent.height = 1;
17207 image_create_info.extent.depth = 1;
17208 image_create_info.mipLevels = 1;
17209 image_create_info.arrayLayers = 1;
17210 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17211 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17212 // Note: Some implementations expect color attachment usage for any
17213 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017214 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017215 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017217 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017218 ASSERT_VK_SUCCESS(err);
17219
Karl Schultz6addd812016-02-02 17:17:23 -070017220 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17221 // Note: Some implementations expect color attachment usage for any
17222 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017223 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017224 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017226 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017227 ASSERT_VK_SUCCESS(err);
17228
17229 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017230 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017231 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17232 memAlloc.pNext = NULL;
17233 memAlloc.allocationSize = 0;
17234 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017235
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017236 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017237 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017238 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017239 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017240 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017241 ASSERT_VK_SUCCESS(err);
17242
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017243 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017244 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017245 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017246 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017247 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017248 ASSERT_VK_SUCCESS(err);
17249
17250 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17251 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017252 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017253 ASSERT_VK_SUCCESS(err);
17254
17255 BeginCommandBuffer();
17256 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017257 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17258 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017259 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017260 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017261 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017262 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017263 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017264 resolveRegion.srcOffset.x = 0;
17265 resolveRegion.srcOffset.y = 0;
17266 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017267 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017268 resolveRegion.dstSubresource.mipLevel = 0;
17269 resolveRegion.dstSubresource.baseArrayLayer = 0;
17270 resolveRegion.dstSubresource.layerCount = 0;
17271 resolveRegion.dstOffset.x = 0;
17272 resolveRegion.dstOffset.y = 0;
17273 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017274 resolveRegion.extent.width = 1;
17275 resolveRegion.extent.height = 1;
17276 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017277 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017278 EndCommandBuffer();
17279
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017280 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017281
Chia-I Wuf7458c52015-10-26 21:10:41 +080017282 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017283 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017284 vkFreeMemory(m_device->device(), srcMem, NULL);
17285 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017286}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017287
Karl Schultz6addd812016-02-02 17:17:23 -070017288TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017289 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017290 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17291 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017292 // The image format check comes 2nd in validation so we trigger it first,
17293 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017294 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17297 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017298
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017299 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017300
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017301 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017302 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17303 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017304
17305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17307 ds_pool_ci.pNext = NULL;
17308 ds_pool_ci.maxSets = 1;
17309 ds_pool_ci.poolSizeCount = 1;
17310 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017311
17312 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017313 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017314 ASSERT_VK_SUCCESS(err);
17315
17316 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017317 dsl_binding.binding = 0;
17318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17319 dsl_binding.descriptorCount = 1;
17320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17321 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017322
17323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17325 ds_layout_ci.pNext = NULL;
17326 ds_layout_ci.bindingCount = 1;
17327 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017328 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017330 ASSERT_VK_SUCCESS(err);
17331
17332 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017333 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017335 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017336 alloc_info.descriptorPool = ds_pool;
17337 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017339 ASSERT_VK_SUCCESS(err);
17340
Karl Schultz6addd812016-02-02 17:17:23 -070017341 VkImage image_bad;
17342 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017343 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017344 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017345 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017346 const int32_t tex_width = 32;
17347 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017348
17349 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017350 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17351 image_create_info.pNext = NULL;
17352 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17353 image_create_info.format = tex_format_bad;
17354 image_create_info.extent.width = tex_width;
17355 image_create_info.extent.height = tex_height;
17356 image_create_info.extent.depth = 1;
17357 image_create_info.mipLevels = 1;
17358 image_create_info.arrayLayers = 1;
17359 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17360 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017361 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017362 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017364 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017365 ASSERT_VK_SUCCESS(err);
17366 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017367 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17368 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017369 ASSERT_VK_SUCCESS(err);
17370
17371 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017372 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17373 image_view_create_info.image = image_bad;
17374 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17375 image_view_create_info.format = tex_format_bad;
17376 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17377 image_view_create_info.subresourceRange.baseMipLevel = 0;
17378 image_view_create_info.subresourceRange.layerCount = 1;
17379 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017380 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017381
17382 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017383 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017384
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017385 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017386
Chia-I Wuf7458c52015-10-26 21:10:41 +080017387 vkDestroyImage(m_device->device(), image_bad, NULL);
17388 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17390 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017391}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017392
17393TEST_F(VkLayerTest, ClearImageErrors) {
17394 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
17395 "ClearDepthStencilImage with a color image.");
17396
17397 ASSERT_NO_FATAL_FAILURE(InitState());
17398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17399
17400 // Renderpass is started here so end it as Clear cmds can't be in renderpass
17401 BeginCommandBuffer();
17402 m_commandBuffer->EndRenderPass();
17403
17404 // Color image
17405 VkClearColorValue clear_color;
17406 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17407 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17408 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17409 const int32_t img_width = 32;
17410 const int32_t img_height = 32;
17411 VkImageCreateInfo image_create_info = {};
17412 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17413 image_create_info.pNext = NULL;
17414 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17415 image_create_info.format = color_format;
17416 image_create_info.extent.width = img_width;
17417 image_create_info.extent.height = img_height;
17418 image_create_info.extent.depth = 1;
17419 image_create_info.mipLevels = 1;
17420 image_create_info.arrayLayers = 1;
17421 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17422 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17423 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17424
17425 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017426 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017428 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017429
17430 // Depth/Stencil image
17431 VkClearDepthStencilValue clear_value = {0};
17432 reqs = 0; // don't need HOST_VISIBLE DS image
17433 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17434 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17435 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17436 ds_image_create_info.extent.width = 64;
17437 ds_image_create_info.extent.height = 64;
17438 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17439 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
17440
17441 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017442 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017444 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 -060017445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017448 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017449 &color_range);
17450
17451 m_errorMonitor->VerifyFound();
17452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
17454 "image created without "
17455 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017457 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017458 &color_range);
17459
17460 m_errorMonitor->VerifyFound();
17461
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017462 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17464 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017466 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
17467 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017468
17469 m_errorMonitor->VerifyFound();
17470}
Tobin Ehliscde08892015-09-22 10:11:37 -060017471#endif // IMAGE_TESTS
17472
Cody Northrop1242dfd2016-07-13 17:24:59 -060017473#if defined(ANDROID) && defined(VALIDATION_APK)
17474static bool initialized = false;
17475static bool active = false;
17476
17477// Convert Intents to argv
17478// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017479std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017480 std::vector<std::string> args;
17481 JavaVM &vm = *app.activity->vm;
17482 JNIEnv *p_env;
17483 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
17484 return args;
17485
17486 JNIEnv &env = *p_env;
17487 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017488 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017489 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017490 jmethodID get_string_extra_method =
17491 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017492 jvalue get_string_extra_args;
17493 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017494 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060017495
17496 std::string args_str;
17497 if (extra_str) {
17498 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
17499 args_str = extra_utf;
17500 env.ReleaseStringUTFChars(extra_str, extra_utf);
17501 env.DeleteLocalRef(extra_str);
17502 }
17503
17504 env.DeleteLocalRef(get_string_extra_args.l);
17505 env.DeleteLocalRef(intent);
17506 vm.DetachCurrentThread();
17507
17508 // split args_str
17509 std::stringstream ss(args_str);
17510 std::string arg;
17511 while (std::getline(ss, arg, ' ')) {
17512 if (!arg.empty())
17513 args.push_back(arg);
17514 }
17515
17516 return args;
17517}
17518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017519static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017521static void processCommand(struct android_app *app, int32_t cmd) {
17522 switch (cmd) {
17523 case APP_CMD_INIT_WINDOW: {
17524 if (app->window) {
17525 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017526 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017527 break;
17528 }
17529 case APP_CMD_GAINED_FOCUS: {
17530 active = true;
17531 break;
17532 }
17533 case APP_CMD_LOST_FOCUS: {
17534 active = false;
17535 break;
17536 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017537 }
17538}
17539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017540void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017541 app_dummy();
17542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017543 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060017544
17545 int vulkanSupport = InitVulkan();
17546 if (vulkanSupport == 0) {
17547 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
17548 return;
17549 }
17550
17551 app->onAppCmd = processCommand;
17552 app->onInputEvent = processInput;
17553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017554 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017555 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017556 struct android_poll_source *source;
17557 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017558 if (source) {
17559 source->process(app, source);
17560 }
17561
17562 if (app->destroyRequested != 0) {
17563 VkTestFramework::Finish();
17564 return;
17565 }
17566 }
17567
17568 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017569 // Use the following key to send arguments to gtest, i.e.
17570 // --es args "--gtest_filter=-VkLayerTest.foo"
17571 const char key[] = "args";
17572 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017574 std::string filter = "";
17575 if (args.size() > 0) {
17576 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17577 filter += args[0];
17578 } else {
17579 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17580 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017582 int argc = 2;
17583 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17584 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017586 // Route output to files until we can override the gtest output
17587 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17588 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017590 ::testing::InitGoogleTest(&argc, argv);
17591 VkTestFramework::InitArgs(&argc, argv);
17592 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017594 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017596 if (result != 0) {
17597 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17598 } else {
17599 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17600 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017602 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017604 fclose(stdout);
17605 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017607 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017609 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017610 }
17611 }
17612}
17613#endif
17614
Tony Barbour300a6082015-04-07 13:44:53 -060017615int main(int argc, char **argv) {
17616 int result;
17617
Cody Northrop8e54a402016-03-08 22:25:52 -070017618#ifdef ANDROID
17619 int vulkanSupport = InitVulkan();
17620 if (vulkanSupport == 0)
17621 return 1;
17622#endif
17623
Tony Barbour300a6082015-04-07 13:44:53 -060017624 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017625 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017626
17627 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17628
17629 result = RUN_ALL_TESTS();
17630
Tony Barbour6918cd52015-04-09 12:58:51 -060017631 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017632 return result;
17633}