blob: c972a6a2931e55c42d6852c6272f54e0df5f8626 [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,
7009 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
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,
7068 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
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,
7806 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
7807 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) {
7996 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7997 " no memory bound to it.");
7998
7999 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8001 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Youngd339ba32016-05-30 13:28:35 -06008002
8003 ASSERT_NO_FATAL_FAILURE(InitState());
8004
8005 // Create a buffer with no bound memory and then attempt to create
8006 // a buffer view.
8007 VkBufferCreateInfo buff_ci = {};
8008 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12008009 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06008010 buff_ci.size = 256;
8011 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8012 VkBuffer buffer;
8013 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8014 ASSERT_VK_SUCCESS(err);
8015
8016 VkBufferViewCreateInfo buff_view_ci = {};
8017 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8018 buff_view_ci.buffer = buffer;
8019 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8020 buff_view_ci.range = VK_WHOLE_SIZE;
8021 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06008023
8024 m_errorMonitor->VerifyFound();
8025 vkDestroyBuffer(m_device->device(), buffer, NULL);
8026 // If last error is success, it still created the view, so delete it.
8027 if (err == VK_SUCCESS) {
8028 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8029 }
8030}
8031
Karl Schultz6addd812016-02-02 17:17:23 -07008032TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
8033 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
8034 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07008035 // 1. No dynamicOffset supplied
8036 // 2. Too many dynamicOffsets supplied
8037 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07008038 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
8040 "0 dynamicOffsets are left in "
8041 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008042
8043 ASSERT_NO_FATAL_FAILURE(InitState());
8044 ASSERT_NO_FATAL_FAILURE(InitViewport());
8045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8046
8047 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008048 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8049 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008050
8051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8053 ds_pool_ci.pNext = NULL;
8054 ds_pool_ci.maxSets = 1;
8055 ds_pool_ci.poolSizeCount = 1;
8056 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008057
8058 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008060 ASSERT_VK_SUCCESS(err);
8061
8062 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008063 dsl_binding.binding = 0;
8064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8065 dsl_binding.descriptorCount = 1;
8066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8067 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008068
8069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8071 ds_layout_ci.pNext = NULL;
8072 ds_layout_ci.bindingCount = 1;
8073 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008074 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008076 ASSERT_VK_SUCCESS(err);
8077
8078 VkDescriptorSet descriptorSet;
8079 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008080 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008081 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008082 alloc_info.descriptorPool = ds_pool;
8083 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008085 ASSERT_VK_SUCCESS(err);
8086
8087 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008088 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8089 pipeline_layout_ci.pNext = NULL;
8090 pipeline_layout_ci.setLayoutCount = 1;
8091 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008092
8093 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008094 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008095 ASSERT_VK_SUCCESS(err);
8096
8097 // Create a buffer to update the descriptor with
8098 uint32_t qfi = 0;
8099 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008100 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8101 buffCI.size = 1024;
8102 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8103 buffCI.queueFamilyIndexCount = 1;
8104 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008105
8106 VkBuffer dyub;
8107 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8108 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008109 // Allocate memory and bind to buffer so we can make it to the appropriate
8110 // error
8111 VkMemoryAllocateInfo mem_alloc = {};
8112 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8113 mem_alloc.pNext = NULL;
8114 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12008115 mem_alloc.memoryTypeIndex = 0;
8116
8117 VkMemoryRequirements memReqs;
8118 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12008120 if (!pass) {
8121 vkDestroyBuffer(m_device->device(), dyub, NULL);
8122 return;
8123 }
8124
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008125 VkDeviceMemory mem;
8126 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8127 ASSERT_VK_SUCCESS(err);
8128 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
8129 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008130 // Correctly update descriptor to avoid "NOT_UPDATED" error
8131 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008132 buffInfo.buffer = dyub;
8133 buffInfo.offset = 0;
8134 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008135
8136 VkWriteDescriptorSet descriptor_write;
8137 memset(&descriptor_write, 0, sizeof(descriptor_write));
8138 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8139 descriptor_write.dstSet = descriptorSet;
8140 descriptor_write.dstBinding = 0;
8141 descriptor_write.descriptorCount = 1;
8142 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8143 descriptor_write.pBufferInfo = &buffInfo;
8144
8145 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8146
8147 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8149 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008150 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07008151 uint32_t pDynOff[2] = {512, 756};
8152 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8154 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
8155 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8156 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12008157 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07008158 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
8160 "offset 0 and range 1024 that "
8161 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07008162 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008163 char const *vsSource = "#version 450\n"
8164 "\n"
8165 "out gl_PerVertex { \n"
8166 " vec4 gl_Position;\n"
8167 "};\n"
8168 "void main(){\n"
8169 " gl_Position = vec4(1);\n"
8170 "}\n";
8171 char const *fsSource = "#version 450\n"
8172 "\n"
8173 "layout(location=0) out vec4 x;\n"
8174 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8175 "void main(){\n"
8176 " x = vec4(bar.y);\n"
8177 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07008178 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8179 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8180 VkPipelineObj pipe(m_device);
8181 pipe.AddShader(&vs);
8182 pipe.AddShader(&fs);
8183 pipe.AddColorAttachment();
8184 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008187 // This update should succeed, but offset size of 512 will overstep buffer
8188 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8190 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07008191 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008192 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008193
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008194 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06008195 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008196
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008197 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8200}
8201
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008202TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
8203 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
8204 "that doesn't have memory bound");
8205 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8207 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
8208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8209 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008210
8211 ASSERT_NO_FATAL_FAILURE(InitState());
8212 ASSERT_NO_FATAL_FAILURE(InitViewport());
8213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8214
8215 VkDescriptorPoolSize ds_type_count = {};
8216 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8217 ds_type_count.descriptorCount = 1;
8218
8219 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8220 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8221 ds_pool_ci.pNext = NULL;
8222 ds_pool_ci.maxSets = 1;
8223 ds_pool_ci.poolSizeCount = 1;
8224 ds_pool_ci.pPoolSizes = &ds_type_count;
8225
8226 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008228 ASSERT_VK_SUCCESS(err);
8229
8230 VkDescriptorSetLayoutBinding dsl_binding = {};
8231 dsl_binding.binding = 0;
8232 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8233 dsl_binding.descriptorCount = 1;
8234 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8235 dsl_binding.pImmutableSamplers = NULL;
8236
8237 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8238 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8239 ds_layout_ci.pNext = NULL;
8240 ds_layout_ci.bindingCount = 1;
8241 ds_layout_ci.pBindings = &dsl_binding;
8242 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008244 ASSERT_VK_SUCCESS(err);
8245
8246 VkDescriptorSet descriptorSet;
8247 VkDescriptorSetAllocateInfo alloc_info = {};
8248 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8249 alloc_info.descriptorSetCount = 1;
8250 alloc_info.descriptorPool = ds_pool;
8251 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008252 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008253 ASSERT_VK_SUCCESS(err);
8254
8255 // Create a buffer to update the descriptor with
8256 uint32_t qfi = 0;
8257 VkBufferCreateInfo buffCI = {};
8258 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8259 buffCI.size = 1024;
8260 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8261 buffCI.queueFamilyIndexCount = 1;
8262 buffCI.pQueueFamilyIndices = &qfi;
8263
8264 VkBuffer dyub;
8265 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8266 ASSERT_VK_SUCCESS(err);
8267
8268 // Attempt to update descriptor without binding memory to it
8269 VkDescriptorBufferInfo buffInfo = {};
8270 buffInfo.buffer = dyub;
8271 buffInfo.offset = 0;
8272 buffInfo.range = 1024;
8273
8274 VkWriteDescriptorSet descriptor_write;
8275 memset(&descriptor_write, 0, sizeof(descriptor_write));
8276 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8277 descriptor_write.dstSet = descriptorSet;
8278 descriptor_write.dstBinding = 0;
8279 descriptor_write.descriptorCount = 1;
8280 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8281 descriptor_write.pBufferInfo = &buffInfo;
8282
8283 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8284 m_errorMonitor->VerifyFound();
8285
8286 vkDestroyBuffer(m_device->device(), dyub, NULL);
8287 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8288 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8289}
8290
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008291TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008292 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008293 ASSERT_NO_FATAL_FAILURE(InitState());
8294 ASSERT_NO_FATAL_FAILURE(InitViewport());
8295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8296
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008297 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008298 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8301 pipeline_layout_ci.pushConstantRangeCount = 1;
8302 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8303
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008304 //
8305 // Check for invalid push constant ranges in pipeline layouts.
8306 //
8307 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008308 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008309 char const *msg;
8310 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008311
Karl Schultzc81037d2016-05-12 08:11:23 -06008312 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8313 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8314 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8315 "vkCreatePipelineLayout() call has push constants index 0 with "
8316 "size 0."},
8317 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8318 "vkCreatePipelineLayout() call has push constants index 0 with "
8319 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008320 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008321 "vkCreatePipelineLayout() call has push constants index 0 with "
8322 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008323 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008324 "vkCreatePipelineLayout() call has push constants index 0 with "
8325 "size 0."},
8326 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8327 "vkCreatePipelineLayout() call has push constants index 0 with "
8328 "offset 1. Offset must"},
8329 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8330 "vkCreatePipelineLayout() call has push constants index 0 "
8331 "with offset "},
8332 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8333 "vkCreatePipelineLayout() call has push constants "
8334 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008335 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008336 "vkCreatePipelineLayout() call has push constants index 0 "
8337 "with offset "},
8338 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8339 "vkCreatePipelineLayout() call has push "
8340 "constants index 0 with offset "},
8341 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8342 "vkCreatePipelineLayout() call has push "
8343 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008344 }};
8345
8346 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008347 for (const auto &iter : range_tests) {
8348 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008351 m_errorMonitor->VerifyFound();
8352 if (VK_SUCCESS == err) {
8353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8354 }
8355 }
8356
8357 // Check for invalid stage flag
8358 pc_range.offset = 0;
8359 pc_range.size = 16;
8360 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008361 m_errorMonitor->SetDesiredFailureMsg(
8362 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8363 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008364 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008365 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008366 if (VK_SUCCESS == err) {
8367 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8368 }
8369
8370 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008371 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008372 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008373 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008374 char const *msg;
8375 };
8376
Karl Schultzc81037d2016-05-12 08:11:23 -06008377 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008378 {{{{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},
8382 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008383 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008384 {
8385 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8386 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8387 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8388 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8389 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008390 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008391 },
8392 {
8393 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8394 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8395 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8396 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8397 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008398 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008399 },
8400 {
8401 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8402 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8403 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8404 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8405 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008406 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008407 },
8408 {
8409 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8410 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8411 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8412 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8413 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008414 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008415 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008416
Karl Schultzc81037d2016-05-12 08:11:23 -06008417 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008418 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008419 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008422 m_errorMonitor->VerifyFound();
8423 if (VK_SUCCESS == err) {
8424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8425 }
8426 }
8427
8428 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8430 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8431 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8432 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8433 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8434 ""},
8435 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8436 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8437 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8438 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8439 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8440 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008441 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008442 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8443 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008445 m_errorMonitor->VerifyNotFound();
8446 if (VK_SUCCESS == err) {
8447 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8448 }
8449 }
8450
8451 //
8452 // CmdPushConstants tests
8453 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008454 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008455
8456 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008457 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8458 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008459 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8460 "vkCmdPushConstants() call has push constants with size 1. Size "
8461 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008462 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008463 "vkCmdPushConstants() call has push constants with size 1. Size "
8464 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008465 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008466 "vkCmdPushConstants() call has push constants with offset 1. "
8467 "Offset must be a multiple of 4."},
8468 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8469 "vkCmdPushConstants() call has push constants with offset 1. "
8470 "Offset must be a multiple of 4."},
8471 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8472 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8473 "0x1 not within flag-matching ranges in pipeline layout"},
8474 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8475 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8476 "0x1 not within flag-matching ranges in pipeline layout"},
8477 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8478 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8479 "0x1 not within flag-matching ranges in pipeline layout"},
8480 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8481 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8482 "0x1 not within flag-matching ranges in pipeline layout"},
8483 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8484 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8485 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008487 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8488 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008489 }};
8490
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008491 BeginCommandBuffer();
8492
8493 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008494 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008495 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008496 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008498 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008499 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008500 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008501 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8503 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008504 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008505 m_errorMonitor->VerifyFound();
8506 }
8507
8508 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008510 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008511 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008513
Karl Schultzc81037d2016-05-12 08:11:23 -06008514 // overlapping range tests with cmd
8515 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8516 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8517 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8518 "0x1 not within flag-matching ranges in pipeline layout"},
8519 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8520 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8521 "0x1 not within flag-matching ranges in pipeline layout"},
8522 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8523 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8524 "0x1 not within flag-matching ranges in pipeline layout"},
8525 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008526 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008527 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008528 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8529 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008530 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008532 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008533 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008534 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008535 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8537 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008538 iter.range.size, dummy_values);
8539 m_errorMonitor->VerifyFound();
8540 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8542
8543 // positive overlapping range tests with cmd
8544 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8545 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8546 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8547 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8548 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8549 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008550 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008551 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008552 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8553 {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 -06008554 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008555 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008556 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008557 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008558 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008559 for (const auto &iter : cmd_overlap_tests_pos) {
8560 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008561 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008562 iter.range.size, dummy_values);
8563 m_errorMonitor->VerifyNotFound();
8564 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008565 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008566
8567 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008568}
8569
Karl Schultz6addd812016-02-02 17:17:23 -07008570TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008571 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008572 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008573
8574 ASSERT_NO_FATAL_FAILURE(InitState());
8575 ASSERT_NO_FATAL_FAILURE(InitViewport());
8576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8577
Mike Stroyanb8a61002016-06-20 16:00:28 -06008578 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8579 VkImageTiling tiling;
8580 VkFormatProperties format_properties;
8581 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008582 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008583 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008584 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008585 tiling = VK_IMAGE_TILING_OPTIMAL;
8586 } else {
8587 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8588 "skipped.\n");
8589 return;
8590 }
8591
Tobin Ehlis559c6382015-11-05 09:52:49 -07008592 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8593 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008594 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8595 ds_type_count[0].descriptorCount = 10;
8596 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8597 ds_type_count[1].descriptorCount = 2;
8598 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8599 ds_type_count[2].descriptorCount = 2;
8600 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8601 ds_type_count[3].descriptorCount = 5;
8602 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8603 // type
8604 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8605 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8606 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008607
8608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8610 ds_pool_ci.pNext = NULL;
8611 ds_pool_ci.maxSets = 5;
8612 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8613 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008614
8615 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008616 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008617 ASSERT_VK_SUCCESS(err);
8618
8619 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8620 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008621 dsl_binding[0].binding = 0;
8622 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8623 dsl_binding[0].descriptorCount = 5;
8624 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8625 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008626
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008627 // Create layout identical to set0 layout but w/ different stageFlags
8628 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008629 dsl_fs_stage_only.binding = 0;
8630 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8631 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008632 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8633 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008634 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008635 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008636 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8637 ds_layout_ci.pNext = NULL;
8638 ds_layout_ci.bindingCount = 1;
8639 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008640 static const uint32_t NUM_LAYOUTS = 4;
8641 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008642 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008643 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8644 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008646 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008647 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008649 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008650 dsl_binding[0].binding = 0;
8651 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008652 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008653 dsl_binding[1].binding = 1;
8654 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8655 dsl_binding[1].descriptorCount = 2;
8656 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8657 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008658 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008659 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008661 ASSERT_VK_SUCCESS(err);
8662 dsl_binding[0].binding = 0;
8663 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008664 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008665 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008666 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008667 ASSERT_VK_SUCCESS(err);
8668 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008669 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008671 ASSERT_VK_SUCCESS(err);
8672
8673 static const uint32_t NUM_SETS = 4;
8674 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8675 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008677 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008678 alloc_info.descriptorPool = ds_pool;
8679 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008681 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008682 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008683 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008684 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008685 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008686 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008687
8688 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008689 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8690 pipeline_layout_ci.pNext = NULL;
8691 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8692 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008693
8694 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008695 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008696 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008697 // Create pipelineLayout with only one setLayout
8698 pipeline_layout_ci.setLayoutCount = 1;
8699 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008700 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008701 ASSERT_VK_SUCCESS(err);
8702 // Create pipelineLayout with 2 descriptor setLayout at index 0
8703 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8704 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008705 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008706 ASSERT_VK_SUCCESS(err);
8707 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8708 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8709 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008710 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008711 ASSERT_VK_SUCCESS(err);
8712 // Create pipelineLayout with UB type, but stageFlags for FS only
8713 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8714 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008715 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008716 ASSERT_VK_SUCCESS(err);
8717 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8718 VkDescriptorSetLayout pl_bad_s0[2] = {};
8719 pl_bad_s0[0] = ds_layout_fs_only;
8720 pl_bad_s0[1] = ds_layout[1];
8721 pipeline_layout_ci.setLayoutCount = 2;
8722 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8723 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008725 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008726
8727 // Create a buffer to update the descriptor with
8728 uint32_t qfi = 0;
8729 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008730 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8731 buffCI.size = 1024;
8732 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8733 buffCI.queueFamilyIndexCount = 1;
8734 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008735
8736 VkBuffer dyub;
8737 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8738 ASSERT_VK_SUCCESS(err);
8739 // Correctly update descriptor to avoid "NOT_UPDATED" error
8740 static const uint32_t NUM_BUFFS = 5;
8741 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008742 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008743 buffInfo[i].buffer = dyub;
8744 buffInfo[i].offset = 0;
8745 buffInfo[i].range = 1024;
8746 }
Karl Schultz6addd812016-02-02 17:17:23 -07008747 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008748 const int32_t tex_width = 32;
8749 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008750 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008751 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8752 image_create_info.pNext = NULL;
8753 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8754 image_create_info.format = tex_format;
8755 image_create_info.extent.width = tex_width;
8756 image_create_info.extent.height = tex_height;
8757 image_create_info.extent.depth = 1;
8758 image_create_info.mipLevels = 1;
8759 image_create_info.arrayLayers = 1;
8760 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008761 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008762 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008763 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008764 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8765 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008766
Karl Schultz6addd812016-02-02 17:17:23 -07008767 VkMemoryRequirements memReqs;
8768 VkDeviceMemory imageMem;
8769 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008770 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008771 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8772 memAlloc.pNext = NULL;
8773 memAlloc.allocationSize = 0;
8774 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008775 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8776 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008777 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008778 ASSERT_TRUE(pass);
8779 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8780 ASSERT_VK_SUCCESS(err);
8781 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8782 ASSERT_VK_SUCCESS(err);
8783
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008784 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008785 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8786 image_view_create_info.image = image;
8787 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8788 image_view_create_info.format = tex_format;
8789 image_view_create_info.subresourceRange.layerCount = 1;
8790 image_view_create_info.subresourceRange.baseMipLevel = 0;
8791 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008792 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008793
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008794 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008795 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008796 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008797 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008798 imageInfo[0].imageView = view;
8799 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8800 imageInfo[1].imageView = view;
8801 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008802 imageInfo[2].imageView = view;
8803 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8804 imageInfo[3].imageView = view;
8805 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008806
8807 static const uint32_t NUM_SET_UPDATES = 3;
8808 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8809 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8810 descriptor_write[0].dstSet = descriptorSet[0];
8811 descriptor_write[0].dstBinding = 0;
8812 descriptor_write[0].descriptorCount = 5;
8813 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8814 descriptor_write[0].pBufferInfo = buffInfo;
8815 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8816 descriptor_write[1].dstSet = descriptorSet[1];
8817 descriptor_write[1].dstBinding = 0;
8818 descriptor_write[1].descriptorCount = 2;
8819 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8820 descriptor_write[1].pImageInfo = imageInfo;
8821 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8822 descriptor_write[2].dstSet = descriptorSet[1];
8823 descriptor_write[2].dstBinding = 1;
8824 descriptor_write[2].descriptorCount = 2;
8825 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008826 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008827
8828 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008829
Tobin Ehlis88452832015-12-03 09:40:56 -07008830 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 char const *vsSource = "#version 450\n"
8832 "\n"
8833 "out gl_PerVertex {\n"
8834 " vec4 gl_Position;\n"
8835 "};\n"
8836 "void main(){\n"
8837 " gl_Position = vec4(1);\n"
8838 "}\n";
8839 char const *fsSource = "#version 450\n"
8840 "\n"
8841 "layout(location=0) out vec4 x;\n"
8842 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8843 "void main(){\n"
8844 " x = vec4(bar.y);\n"
8845 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008848 VkPipelineObj pipe(m_device);
8849 pipe.AddShader(&vs);
8850 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008851 pipe.AddColorAttachment();
8852 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008853
8854 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008857 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8858 // of PSO
8859 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8860 // cmd_pipeline.c
8861 // due to the fact that cmd_alloc_dset_data() has not been called in
8862 // cmd_bind_graphics_pipeline()
8863 // TODO : Want to cause various binding incompatibility issues here to test
8864 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008865 // First cause various verify_layout_compatibility() fails
8866 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008867 // verify_set_layout_compatibility fail cases:
8868 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8870 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8871 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008872 m_errorMonitor->VerifyFound();
8873
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008874 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8876 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8877 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008878 m_errorMonitor->VerifyFound();
8879
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008880 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008881 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8882 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8884 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8885 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008886 m_errorMonitor->VerifyFound();
8887
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008888 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8889 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8891 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8892 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008893 m_errorMonitor->VerifyFound();
8894
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008895 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8896 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8898 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8899 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8900 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008901 m_errorMonitor->VerifyFound();
8902
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008903 // Cause INFO messages due to disturbing previously bound Sets
8904 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008905 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8906 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008907 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8909 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8910 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008911 m_errorMonitor->VerifyFound();
8912
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008913 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8914 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008915 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8917 "any subsequent sets were disturbed ");
8918 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8919 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008920 m_errorMonitor->VerifyFound();
8921
Tobin Ehlis10fad692016-07-07 12:00:36 -06008922 // Now that we're done actively using the pipelineLayout that gfx pipeline
8923 // was created with, we should be able to delete it. Do that now to verify
8924 // that validation obeys pipelineLayout lifetime
8925 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8926
Tobin Ehlis88452832015-12-03 09:40:56 -07008927 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008928 // 1. Error due to not binding required set (we actually use same code as
8929 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008930 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8931 &descriptorSet[0], 0, NULL);
8932 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8933 &descriptorSet[1], 0, NULL);
8934 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 -07008935 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008936 m_errorMonitor->VerifyFound();
8937
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008938 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008939 // 2. Error due to bound set not being compatible with PSO's
8940 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8942 &descriptorSet[0], 0, NULL);
8943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008944 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008945 m_errorMonitor->VerifyFound();
8946
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008947 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008948 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008949 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8950 }
8951 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008952 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8953 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008954 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008955 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008957 vkFreeMemory(m_device->device(), imageMem, NULL);
8958 vkDestroyImage(m_device->device(), image, NULL);
8959 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008960}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008961
Karl Schultz6addd812016-02-02 17:17:23 -07008962TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8965 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008966
8967 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008968 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008969 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008970 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008971
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008972 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008973}
8974
Karl Schultz6addd812016-02-02 17:17:23 -07008975TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8976 VkResult err;
8977 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008980
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008981 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008982
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008983 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008984 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008985 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008986 cmd.commandPool = m_commandPool;
8987 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008988 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008989
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008990 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008991 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008992
8993 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008994 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008995 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008996 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008997 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 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 -07008999 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06009000
9001 // The error should be caught by validation of the BeginCommandBuffer call
9002 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
9003
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009004 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009005 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06009006}
9007
Karl Schultz6addd812016-02-02 17:17:23 -07009008TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009009 // Cause error due to Begin while recording CB
9010 // Then cause 2 errors for attempting to reset CB w/o having
9011 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
9012 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009014
9015 ASSERT_NO_FATAL_FAILURE(InitState());
9016
9017 // Calls AllocateCommandBuffers
9018 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
9019
Karl Schultz6addd812016-02-02 17:17:23 -07009020 // Force the failure by setting the Renderpass and Framebuffer fields with
9021 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009022 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07009023 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009024 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9025 cmd_buf_info.pNext = NULL;
9026 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009027 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009028
9029 // Begin CB to transition to recording state
9030 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
9031 // Can't re-begin. This should trigger error
9032 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009033 m_errorMonitor->VerifyFound();
9034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009036 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
9037 // Reset attempt will trigger error due to incorrect CommandPool state
9038 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009039 m_errorMonitor->VerifyFound();
9040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009042 // Transition CB to RECORDED state
9043 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
9044 // Now attempting to Begin will implicitly reset, which triggers error
9045 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009046 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009047}
9048
Karl Schultz6addd812016-02-02 17:17:23 -07009049TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009050 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009051 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009052
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009054
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009055 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009057
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009058 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009059 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9060 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009061
9062 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009063 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9064 ds_pool_ci.pNext = NULL;
9065 ds_pool_ci.maxSets = 1;
9066 ds_pool_ci.poolSizeCount = 1;
9067 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009068
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009069 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009071 ASSERT_VK_SUCCESS(err);
9072
Tony Barboureb254902015-07-15 12:50:33 -06009073 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009074 dsl_binding.binding = 0;
9075 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9076 dsl_binding.descriptorCount = 1;
9077 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9078 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009079
Tony Barboureb254902015-07-15 12:50:33 -06009080 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009081 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9082 ds_layout_ci.pNext = NULL;
9083 ds_layout_ci.bindingCount = 1;
9084 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009085
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009086 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009087 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009088 ASSERT_VK_SUCCESS(err);
9089
9090 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009091 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009092 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009093 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009094 alloc_info.descriptorPool = ds_pool;
9095 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009096 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009097 ASSERT_VK_SUCCESS(err);
9098
Tony Barboureb254902015-07-15 12:50:33 -06009099 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009100 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9101 pipeline_layout_ci.setLayoutCount = 1;
9102 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009103
9104 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009105 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009106 ASSERT_VK_SUCCESS(err);
9107
Tobin Ehlise68360f2015-10-01 11:15:13 -06009108 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07009109 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06009110
9111 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009112 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9113 vp_state_ci.scissorCount = 1;
9114 vp_state_ci.pScissors = &sc;
9115 vp_state_ci.viewportCount = 1;
9116 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009117
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009118 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9119 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9120 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9121 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9122 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9123 rs_state_ci.depthClampEnable = VK_FALSE;
9124 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9125 rs_state_ci.depthBiasEnable = VK_FALSE;
9126
Tony Barboureb254902015-07-15 12:50:33 -06009127 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009128 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9129 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009130 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009131 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9132 gp_ci.layout = pipeline_layout;
9133 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06009134
9135 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009136 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9137 pc_ci.initialDataSize = 0;
9138 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009139
9140 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06009141 VkPipelineCache pipelineCache;
9142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009143 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06009144 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009145 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06009146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009147 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009148
Chia-I Wuf7458c52015-10-26 21:10:41 +08009149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009153}
Tobin Ehlis912df022015-09-17 08:46:18 -06009154/*// TODO : This test should be good, but needs Tess support in compiler to run
9155TEST_F(VkLayerTest, InvalidPatchControlPoints)
9156{
9157 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06009158 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009159
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009161 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
9162primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009163
Tobin Ehlis912df022015-09-17 08:46:18 -06009164 ASSERT_NO_FATAL_FAILURE(InitState());
9165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06009166
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009167 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06009168 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009169 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009170
9171 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9172 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9173 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009174 ds_pool_ci.poolSizeCount = 1;
9175 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06009176
9177 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009178 err = vkCreateDescriptorPool(m_device->device(),
9179VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06009180 ASSERT_VK_SUCCESS(err);
9181
9182 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009183 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06009184 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009185 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009186 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9187 dsl_binding.pImmutableSamplers = NULL;
9188
9189 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009190 ds_layout_ci.sType =
9191VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009192 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009193 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009194 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06009195
9196 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009197 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9198&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009199 ASSERT_VK_SUCCESS(err);
9200
9201 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009202 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
9203VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06009204 ASSERT_VK_SUCCESS(err);
9205
9206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009207 pipeline_layout_ci.sType =
9208VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009209 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009210 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009211 pipeline_layout_ci.pSetLayouts = &ds_layout;
9212
9213 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9215&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009216 ASSERT_VK_SUCCESS(err);
9217
9218 VkPipelineShaderStageCreateInfo shaderStages[3];
9219 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
9220
Karl Schultz6addd812016-02-02 17:17:23 -07009221 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
9222this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009223 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07009224 VkShaderObj
9225tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
9226this);
9227 VkShaderObj
9228te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
9229this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009230
Karl Schultz6addd812016-02-02 17:17:23 -07009231 shaderStages[0].sType =
9232VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009233 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009234 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009235 shaderStages[1].sType =
9236VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009237 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009238 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009239 shaderStages[2].sType =
9240VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009241 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009242 shaderStages[2].shader = te.handle();
9243
9244 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009245 iaCI.sType =
9246VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009247 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009248
9249 VkPipelineTessellationStateCreateInfo tsCI = {};
9250 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9251 tsCI.patchControlPoints = 0; // This will cause an error
9252
9253 VkGraphicsPipelineCreateInfo gp_ci = {};
9254 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9255 gp_ci.pNext = NULL;
9256 gp_ci.stageCount = 3;
9257 gp_ci.pStages = shaderStages;
9258 gp_ci.pVertexInputState = NULL;
9259 gp_ci.pInputAssemblyState = &iaCI;
9260 gp_ci.pTessellationState = &tsCI;
9261 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009262 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009263 gp_ci.pMultisampleState = NULL;
9264 gp_ci.pDepthStencilState = NULL;
9265 gp_ci.pColorBlendState = NULL;
9266 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9267 gp_ci.layout = pipeline_layout;
9268 gp_ci.renderPass = renderPass();
9269
9270 VkPipelineCacheCreateInfo pc_ci = {};
9271 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9272 pc_ci.pNext = NULL;
9273 pc_ci.initialSize = 0;
9274 pc_ci.initialData = 0;
9275 pc_ci.maxSize = 0;
9276
9277 VkPipeline pipeline;
9278 VkPipelineCache pipelineCache;
9279
Karl Schultz6addd812016-02-02 17:17:23 -07009280 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9281&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009282 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009283 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9284&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009285
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009286 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009287
Chia-I Wuf7458c52015-10-26 21:10:41 +08009288 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9289 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009292}
9293*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009294// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009295TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009296 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9299 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009300
Tobin Ehlise68360f2015-10-01 11:15:13 -06009301 ASSERT_NO_FATAL_FAILURE(InitState());
9302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009303
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009304 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009305 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9306 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009307
9308 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009309 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9310 ds_pool_ci.maxSets = 1;
9311 ds_pool_ci.poolSizeCount = 1;
9312 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009313
9314 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009315 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009316 ASSERT_VK_SUCCESS(err);
9317
9318 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009319 dsl_binding.binding = 0;
9320 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9321 dsl_binding.descriptorCount = 1;
9322 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009323
9324 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009325 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9326 ds_layout_ci.bindingCount = 1;
9327 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009328
9329 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009330 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009331 ASSERT_VK_SUCCESS(err);
9332
9333 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009334 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009336 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009337 alloc_info.descriptorPool = ds_pool;
9338 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009340 ASSERT_VK_SUCCESS(err);
9341
9342 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009343 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9344 pipeline_layout_ci.setLayoutCount = 1;
9345 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009346
9347 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009348 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009349 ASSERT_VK_SUCCESS(err);
9350
9351 VkViewport vp = {}; // Just need dummy vp to point to
9352
9353 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009354 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9355 vp_state_ci.scissorCount = 0;
9356 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9357 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009358
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009359 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9360 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9361 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9362 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9363 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9364 rs_state_ci.depthClampEnable = VK_FALSE;
9365 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9366 rs_state_ci.depthBiasEnable = VK_FALSE;
9367
Cody Northropeb3a6c12015-10-05 14:44:45 -06009368 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009369 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009371 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9372 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9373 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009374 shaderStages[0] = vs.GetStageCreateInfo();
9375 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009376
9377 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009378 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9379 gp_ci.stageCount = 2;
9380 gp_ci.pStages = shaderStages;
9381 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009382 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009383 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9384 gp_ci.layout = pipeline_layout;
9385 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009386
9387 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009388 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009389
9390 VkPipeline pipeline;
9391 VkPipelineCache pipelineCache;
9392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009393 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009394 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009395 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009396
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009397 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009398
Chia-I Wuf7458c52015-10-26 21:10:41 +08009399 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9400 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9401 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9402 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009403}
Karl Schultz6addd812016-02-02 17:17:23 -07009404// Don't set viewport state in PSO. This is an error b/c we always need this
9405// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009406// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009407TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009408 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009409 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009410
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009412
Tobin Ehlise68360f2015-10-01 11:15:13 -06009413 ASSERT_NO_FATAL_FAILURE(InitState());
9414 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009415
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009416 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009417 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9418 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009419
9420 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009421 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9422 ds_pool_ci.maxSets = 1;
9423 ds_pool_ci.poolSizeCount = 1;
9424 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009425
9426 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009427 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009428 ASSERT_VK_SUCCESS(err);
9429
9430 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009431 dsl_binding.binding = 0;
9432 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9433 dsl_binding.descriptorCount = 1;
9434 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009435
9436 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009437 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9438 ds_layout_ci.bindingCount = 1;
9439 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009440
9441 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009442 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009443 ASSERT_VK_SUCCESS(err);
9444
9445 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009446 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009447 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009448 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009449 alloc_info.descriptorPool = ds_pool;
9450 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009451 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009452 ASSERT_VK_SUCCESS(err);
9453
9454 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009455 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9456 pipeline_layout_ci.setLayoutCount = 1;
9457 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009458
9459 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009461 ASSERT_VK_SUCCESS(err);
9462
9463 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9464 // Set scissor as dynamic to avoid second error
9465 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009466 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9467 dyn_state_ci.dynamicStateCount = 1;
9468 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009469
Cody Northropeb3a6c12015-10-05 14:44:45 -06009470 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009471 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009472
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009473 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9474 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9475 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009476 shaderStages[0] = vs.GetStageCreateInfo();
9477 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009478
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009479 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9480 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9481 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9482 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9483 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9484 rs_state_ci.depthClampEnable = VK_FALSE;
9485 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9486 rs_state_ci.depthBiasEnable = VK_FALSE;
9487
Tobin Ehlise68360f2015-10-01 11:15:13 -06009488 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009489 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9490 gp_ci.stageCount = 2;
9491 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009492 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009493 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9494 // should cause validation error
9495 gp_ci.pDynamicState = &dyn_state_ci;
9496 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9497 gp_ci.layout = pipeline_layout;
9498 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009499
9500 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009501 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009502
9503 VkPipeline pipeline;
9504 VkPipelineCache pipelineCache;
9505
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009506 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009507 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009508 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009509
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009510 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009511
Chia-I Wuf7458c52015-10-26 21:10:41 +08009512 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9513 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9514 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9515 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009516}
9517// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009518// Then run second test where dynamic scissor count doesn't match PSO scissor
9519// count
9520TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9521 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009522
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9524 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009525
Tobin Ehlise68360f2015-10-01 11:15:13 -06009526 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009527
9528 if (!m_device->phy().features().multiViewport) {
9529 printf("Device does not support multiple viewports/scissors; skipped.\n");
9530 return;
9531 }
9532
Tobin Ehlise68360f2015-10-01 11:15:13 -06009533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009534
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009535 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009536 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9537 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009538
9539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9541 ds_pool_ci.maxSets = 1;
9542 ds_pool_ci.poolSizeCount = 1;
9543 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009544
9545 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009547 ASSERT_VK_SUCCESS(err);
9548
9549 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009550 dsl_binding.binding = 0;
9551 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9552 dsl_binding.descriptorCount = 1;
9553 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009554
9555 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009556 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9557 ds_layout_ci.bindingCount = 1;
9558 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009559
9560 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009561 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009562 ASSERT_VK_SUCCESS(err);
9563
9564 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009565 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009566 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009567 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009568 alloc_info.descriptorPool = ds_pool;
9569 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009571 ASSERT_VK_SUCCESS(err);
9572
9573 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009574 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9575 pipeline_layout_ci.setLayoutCount = 1;
9576 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009577
9578 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009580 ASSERT_VK_SUCCESS(err);
9581
9582 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009583 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9584 vp_state_ci.viewportCount = 1;
9585 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9586 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009588
9589 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9590 // Set scissor as dynamic to avoid that error
9591 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009592 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9593 dyn_state_ci.dynamicStateCount = 1;
9594 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009595
Cody Northropeb3a6c12015-10-05 14:44:45 -06009596 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009597 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009598
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009599 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9600 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9601 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009602 shaderStages[0] = vs.GetStageCreateInfo();
9603 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009604
Cody Northropf6622dc2015-10-06 10:33:21 -06009605 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9606 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9607 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009608 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009609 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009610 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009611 vi_ci.pVertexAttributeDescriptions = nullptr;
9612
9613 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9614 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9615 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9616
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009617 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009618 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009619 rs_ci.pNext = nullptr;
9620
Mark Youngc89c6312016-03-31 16:03:20 -06009621 VkPipelineColorBlendAttachmentState att = {};
9622 att.blendEnable = VK_FALSE;
9623 att.colorWriteMask = 0xf;
9624
Cody Northropf6622dc2015-10-06 10:33:21 -06009625 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9626 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9627 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009628 cb_ci.attachmentCount = 1;
9629 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009630
Tobin Ehlise68360f2015-10-01 11:15:13 -06009631 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009632 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9633 gp_ci.stageCount = 2;
9634 gp_ci.pStages = shaderStages;
9635 gp_ci.pVertexInputState = &vi_ci;
9636 gp_ci.pInputAssemblyState = &ia_ci;
9637 gp_ci.pViewportState = &vp_state_ci;
9638 gp_ci.pRasterizationState = &rs_ci;
9639 gp_ci.pColorBlendState = &cb_ci;
9640 gp_ci.pDynamicState = &dyn_state_ci;
9641 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9642 gp_ci.layout = pipeline_layout;
9643 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009644
9645 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009646 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009647
9648 VkPipeline pipeline;
9649 VkPipelineCache pipelineCache;
9650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009651 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009652 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009653 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009655 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009656
Tobin Ehlisd332f282015-10-02 11:00:56 -06009657 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009658 // First need to successfully create the PSO from above by setting
9659 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009661
9662 VkViewport vp = {}; // Just need dummy vp to point to
9663 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009664 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009665 ASSERT_VK_SUCCESS(err);
9666 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009668 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009669 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009670 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009671 Draw(1, 0, 0, 0);
9672
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009673 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009674
9675 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9676 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9677 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9678 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009679 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009680}
9681// Create PSO w/o non-zero scissorCount but no scissor data
9682// Then run second test where dynamic viewportCount doesn't match PSO
9683// viewportCount
9684TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9685 VkResult err;
9686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009687 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 -07009688
9689 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009690
9691 if (!m_device->phy().features().multiViewport) {
9692 printf("Device does not support multiple viewports/scissors; skipped.\n");
9693 return;
9694 }
9695
Karl Schultz6addd812016-02-02 17:17:23 -07009696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9697
9698 VkDescriptorPoolSize ds_type_count = {};
9699 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9700 ds_type_count.descriptorCount = 1;
9701
9702 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9703 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9704 ds_pool_ci.maxSets = 1;
9705 ds_pool_ci.poolSizeCount = 1;
9706 ds_pool_ci.pPoolSizes = &ds_type_count;
9707
9708 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009710 ASSERT_VK_SUCCESS(err);
9711
9712 VkDescriptorSetLayoutBinding dsl_binding = {};
9713 dsl_binding.binding = 0;
9714 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9715 dsl_binding.descriptorCount = 1;
9716 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9717
9718 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9719 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9720 ds_layout_ci.bindingCount = 1;
9721 ds_layout_ci.pBindings = &dsl_binding;
9722
9723 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009724 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009725 ASSERT_VK_SUCCESS(err);
9726
9727 VkDescriptorSet descriptorSet;
9728 VkDescriptorSetAllocateInfo alloc_info = {};
9729 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9730 alloc_info.descriptorSetCount = 1;
9731 alloc_info.descriptorPool = ds_pool;
9732 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009734 ASSERT_VK_SUCCESS(err);
9735
9736 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9737 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9738 pipeline_layout_ci.setLayoutCount = 1;
9739 pipeline_layout_ci.pSetLayouts = &ds_layout;
9740
9741 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009743 ASSERT_VK_SUCCESS(err);
9744
9745 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9746 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9747 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009748 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009749 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009750 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009751
9752 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9753 // Set scissor as dynamic to avoid that error
9754 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9755 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9756 dyn_state_ci.dynamicStateCount = 1;
9757 dyn_state_ci.pDynamicStates = &vp_state;
9758
9759 VkPipelineShaderStageCreateInfo shaderStages[2];
9760 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9763 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9764 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009765 shaderStages[0] = vs.GetStageCreateInfo();
9766 shaderStages[1] = fs.GetStageCreateInfo();
9767
9768 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9769 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9770 vi_ci.pNext = nullptr;
9771 vi_ci.vertexBindingDescriptionCount = 0;
9772 vi_ci.pVertexBindingDescriptions = nullptr;
9773 vi_ci.vertexAttributeDescriptionCount = 0;
9774 vi_ci.pVertexAttributeDescriptions = nullptr;
9775
9776 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9777 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9778 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9779
9780 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9781 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9782 rs_ci.pNext = nullptr;
9783
Mark Youngc89c6312016-03-31 16:03:20 -06009784 VkPipelineColorBlendAttachmentState att = {};
9785 att.blendEnable = VK_FALSE;
9786 att.colorWriteMask = 0xf;
9787
Karl Schultz6addd812016-02-02 17:17:23 -07009788 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9789 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9790 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009791 cb_ci.attachmentCount = 1;
9792 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009793
9794 VkGraphicsPipelineCreateInfo gp_ci = {};
9795 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9796 gp_ci.stageCount = 2;
9797 gp_ci.pStages = shaderStages;
9798 gp_ci.pVertexInputState = &vi_ci;
9799 gp_ci.pInputAssemblyState = &ia_ci;
9800 gp_ci.pViewportState = &vp_state_ci;
9801 gp_ci.pRasterizationState = &rs_ci;
9802 gp_ci.pColorBlendState = &cb_ci;
9803 gp_ci.pDynamicState = &dyn_state_ci;
9804 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9805 gp_ci.layout = pipeline_layout;
9806 gp_ci.renderPass = renderPass();
9807
9808 VkPipelineCacheCreateInfo pc_ci = {};
9809 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9810
9811 VkPipeline pipeline;
9812 VkPipelineCache pipelineCache;
9813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009815 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009818 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009819
9820 // Now hit second fail case where we set scissor w/ different count than PSO
9821 // First need to successfully create the PSO from above by setting
9822 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009824
Tobin Ehlisd332f282015-10-02 11:00:56 -06009825 VkRect2D sc = {}; // Just need dummy vp to point to
9826 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009827 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009828 ASSERT_VK_SUCCESS(err);
9829 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009830 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009831 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009832 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009833 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009834 Draw(1, 0, 0, 0);
9835
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009836 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009837
Chia-I Wuf7458c52015-10-26 21:10:41 +08009838 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009842 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009843}
9844
Mark Young7394fdd2016-03-31 14:56:43 -06009845TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9846 VkResult err;
9847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009849
9850 ASSERT_NO_FATAL_FAILURE(InitState());
9851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9852
9853 VkDescriptorPoolSize ds_type_count = {};
9854 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9855 ds_type_count.descriptorCount = 1;
9856
9857 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9858 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9859 ds_pool_ci.maxSets = 1;
9860 ds_pool_ci.poolSizeCount = 1;
9861 ds_pool_ci.pPoolSizes = &ds_type_count;
9862
9863 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009864 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009865 ASSERT_VK_SUCCESS(err);
9866
9867 VkDescriptorSetLayoutBinding dsl_binding = {};
9868 dsl_binding.binding = 0;
9869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9870 dsl_binding.descriptorCount = 1;
9871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9872
9873 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9874 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9875 ds_layout_ci.bindingCount = 1;
9876 ds_layout_ci.pBindings = &dsl_binding;
9877
9878 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009879 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009880 ASSERT_VK_SUCCESS(err);
9881
9882 VkDescriptorSet descriptorSet;
9883 VkDescriptorSetAllocateInfo alloc_info = {};
9884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9885 alloc_info.descriptorSetCount = 1;
9886 alloc_info.descriptorPool = ds_pool;
9887 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009888 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009889 ASSERT_VK_SUCCESS(err);
9890
9891 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9892 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9893 pipeline_layout_ci.setLayoutCount = 1;
9894 pipeline_layout_ci.pSetLayouts = &ds_layout;
9895
9896 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009897 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009898 ASSERT_VK_SUCCESS(err);
9899
9900 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9901 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9902 vp_state_ci.scissorCount = 1;
9903 vp_state_ci.pScissors = NULL;
9904 vp_state_ci.viewportCount = 1;
9905 vp_state_ci.pViewports = NULL;
9906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009907 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009908 // Set scissor as dynamic to avoid that error
9909 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9910 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9911 dyn_state_ci.dynamicStateCount = 2;
9912 dyn_state_ci.pDynamicStates = dynamic_states;
9913
9914 VkPipelineShaderStageCreateInfo shaderStages[2];
9915 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9918 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009919 this); // TODO - We shouldn't need a fragment shader
9920 // but add it to be able to run on more devices
9921 shaderStages[0] = vs.GetStageCreateInfo();
9922 shaderStages[1] = fs.GetStageCreateInfo();
9923
9924 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9925 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9926 vi_ci.pNext = nullptr;
9927 vi_ci.vertexBindingDescriptionCount = 0;
9928 vi_ci.pVertexBindingDescriptions = nullptr;
9929 vi_ci.vertexAttributeDescriptionCount = 0;
9930 vi_ci.pVertexAttributeDescriptions = nullptr;
9931
9932 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9933 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9934 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9935
9936 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9937 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9938 rs_ci.pNext = nullptr;
9939
Mark Young47107952016-05-02 15:59:55 -06009940 // Check too low (line width of -1.0f).
9941 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009942
9943 VkPipelineColorBlendAttachmentState att = {};
9944 att.blendEnable = VK_FALSE;
9945 att.colorWriteMask = 0xf;
9946
9947 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9948 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9949 cb_ci.pNext = nullptr;
9950 cb_ci.attachmentCount = 1;
9951 cb_ci.pAttachments = &att;
9952
9953 VkGraphicsPipelineCreateInfo gp_ci = {};
9954 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9955 gp_ci.stageCount = 2;
9956 gp_ci.pStages = shaderStages;
9957 gp_ci.pVertexInputState = &vi_ci;
9958 gp_ci.pInputAssemblyState = &ia_ci;
9959 gp_ci.pViewportState = &vp_state_ci;
9960 gp_ci.pRasterizationState = &rs_ci;
9961 gp_ci.pColorBlendState = &cb_ci;
9962 gp_ci.pDynamicState = &dyn_state_ci;
9963 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9964 gp_ci.layout = pipeline_layout;
9965 gp_ci.renderPass = renderPass();
9966
9967 VkPipelineCacheCreateInfo pc_ci = {};
9968 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9969
9970 VkPipeline pipeline;
9971 VkPipelineCache pipelineCache;
9972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009973 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009974 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009975 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009976
9977 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009978 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009981
9982 // Check too high (line width of 65536.0f).
9983 rs_ci.lineWidth = 65536.0f;
9984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009985 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009986 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009988
9989 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009990 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009993
9994 dyn_state_ci.dynamicStateCount = 3;
9995
9996 rs_ci.lineWidth = 1.0f;
9997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009999 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -060010001 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010002 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -060010003
10004 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -060010005 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -060010006 m_errorMonitor->VerifyFound();
10007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -060010009
10010 // Check too high with dynamic setting.
10011 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
10012 m_errorMonitor->VerifyFound();
10013 EndCommandBuffer();
10014
10015 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
10016 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10017 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010019 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -060010020}
10021
Karl Schultz6addd812016-02-02 17:17:23 -070010022TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010023 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10025 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010026
10027 ASSERT_NO_FATAL_FAILURE(InitState());
10028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010029
Tony Barbourfe3351b2015-07-28 10:17:20 -060010030 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -070010031 // Don't care about RenderPass handle b/c error should be flagged before
10032 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010035 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010036}
10037
Karl Schultz6addd812016-02-02 17:17:23 -070010038TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010039 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10041 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010042
10043 ASSERT_NO_FATAL_FAILURE(InitState());
10044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010045
Tony Barbourfe3351b2015-07-28 10:17:20 -060010046 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -070010047 // Just create a dummy Renderpass that's non-NULL so we can get to the
10048 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010049 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010050
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010051 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010052}
10053
Chris Forbes2eeabe32016-06-21 20:52:34 +120010054TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
10055 m_errorMonitor->ExpectSuccess();
10056
10057 ASSERT_NO_FATAL_FAILURE(InitState());
10058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +120010061 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
10062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +120010064 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10065 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +120010067 m_errorMonitor->VerifyNotFound();
10068 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10069 m_errorMonitor->VerifyNotFound();
10070
10071 m_commandBuffer->EndCommandBuffer();
10072 m_errorMonitor->VerifyNotFound();
10073}
10074
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010075TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
10076 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
10077 "the number of renderPass attachments that use loadOp"
10078 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
10079
10080 ASSERT_NO_FATAL_FAILURE(InitState());
10081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10082
10083 // Create a renderPass with a single attachment that uses loadOp CLEAR
10084 VkAttachmentReference attach = {};
10085 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10086 VkSubpassDescription subpass = {};
10087 subpass.inputAttachmentCount = 1;
10088 subpass.pInputAttachments = &attach;
10089 VkRenderPassCreateInfo rpci = {};
10090 rpci.subpassCount = 1;
10091 rpci.pSubpasses = &subpass;
10092 rpci.attachmentCount = 1;
10093 VkAttachmentDescription attach_desc = {};
10094 attach_desc.format = VK_FORMAT_UNDEFINED;
10095 // Set loadOp to CLEAR
10096 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10097 rpci.pAttachments = &attach_desc;
10098 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10099 VkRenderPass rp;
10100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10101
10102 VkCommandBufferInheritanceInfo hinfo = {};
10103 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10104 hinfo.renderPass = VK_NULL_HANDLE;
10105 hinfo.subpass = 0;
10106 hinfo.framebuffer = VK_NULL_HANDLE;
10107 hinfo.occlusionQueryEnable = VK_FALSE;
10108 hinfo.queryFlags = 0;
10109 hinfo.pipelineStatistics = 0;
10110 VkCommandBufferBeginInfo info = {};
10111 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
10112 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10113 info.pInheritanceInfo = &hinfo;
10114
10115 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
10116 VkRenderPassBeginInfo rp_begin = {};
10117 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10118 rp_begin.pNext = NULL;
10119 rp_begin.renderPass = renderPass();
10120 rp_begin.framebuffer = framebuffer();
10121 rp_begin.clearValueCount = 0; // Should be 1
10122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
10124 "there must be at least 1 entries in "
10125 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010127 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010128
10129 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -060010130
10131 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010132}
10133
Cody Northrop3bb4d962016-05-09 16:15:57 -060010134TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
10135
10136 TEST_DESCRIPTION("End a command buffer with an active render pass");
10137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10139 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -060010140
10141 ASSERT_NO_FATAL_FAILURE(InitState());
10142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10143
10144 // The framework's BeginCommandBuffer calls CreateRenderPass
10145 BeginCommandBuffer();
10146
10147 // Call directly into vkEndCommandBuffer instead of the
10148 // the framework's EndCommandBuffer, which inserts a
10149 // vkEndRenderPass
10150 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
10151
10152 m_errorMonitor->VerifyFound();
10153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010154 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
10155 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -060010156}
10157
Karl Schultz6addd812016-02-02 17:17:23 -070010158TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010159 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10161 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010162
10163 ASSERT_NO_FATAL_FAILURE(InitState());
10164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010165
10166 // Renderpass is started here
10167 BeginCommandBuffer();
10168
10169 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010170 vk_testing::Buffer dstBuffer;
10171 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010172
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010173 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010174
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010175 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010176}
10177
Karl Schultz6addd812016-02-02 17:17:23 -070010178TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010179 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10181 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010182
10183 ASSERT_NO_FATAL_FAILURE(InitState());
10184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010185
10186 // Renderpass is started here
10187 BeginCommandBuffer();
10188
10189 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010190 vk_testing::Buffer dstBuffer;
10191 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010192
Karl Schultz6addd812016-02-02 17:17:23 -070010193 VkDeviceSize dstOffset = 0;
10194 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -060010195 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010197 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010198
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010199 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010200}
10201
Karl Schultz6addd812016-02-02 17:17:23 -070010202TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010203 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10205 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010206
10207 ASSERT_NO_FATAL_FAILURE(InitState());
10208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010209
10210 // Renderpass is started here
10211 BeginCommandBuffer();
10212
Michael Lentine0a369f62016-02-03 16:51:46 -060010213 VkClearColorValue clear_color;
10214 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -070010215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10216 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10217 const int32_t tex_width = 32;
10218 const int32_t tex_height = 32;
10219 VkImageCreateInfo image_create_info = {};
10220 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10221 image_create_info.pNext = NULL;
10222 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10223 image_create_info.format = tex_format;
10224 image_create_info.extent.width = tex_width;
10225 image_create_info.extent.height = tex_height;
10226 image_create_info.extent.depth = 1;
10227 image_create_info.mipLevels = 1;
10228 image_create_info.arrayLayers = 1;
10229 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10230 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10231 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010232
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010233 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010238 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010239
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010240 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010241}
10242
Karl Schultz6addd812016-02-02 17:17:23 -070010243TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010244 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10246 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010247
10248 ASSERT_NO_FATAL_FAILURE(InitState());
10249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010250
10251 // Renderpass is started here
10252 BeginCommandBuffer();
10253
10254 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010255 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010256 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10257 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10258 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10259 image_create_info.extent.width = 64;
10260 image_create_info.extent.height = 64;
10261 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10262 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010263
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010264 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010267 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010269 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10270 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010271
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010272 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010273}
10274
Karl Schultz6addd812016-02-02 17:17:23 -070010275TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010276 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010277 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10280 "must be issued inside an active "
10281 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010282
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010283 ASSERT_NO_FATAL_FAILURE(InitState());
10284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010285
10286 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010287 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010288 ASSERT_VK_SUCCESS(err);
10289
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010290 VkClearAttachment color_attachment;
10291 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10292 color_attachment.clearValue.color.float32[0] = 0;
10293 color_attachment.clearValue.color.float32[1] = 0;
10294 color_attachment.clearValue.color.float32[2] = 0;
10295 color_attachment.clearValue.color.float32[3] = 0;
10296 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010297 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010300 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010301}
10302
Chris Forbes3b97e932016-09-07 11:29:24 +120010303TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10304 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10305 "called too many times in a renderpass instance");
10306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10308 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010309
10310 ASSERT_NO_FATAL_FAILURE(InitState());
10311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10312
10313 BeginCommandBuffer();
10314
10315 // error here.
10316 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10317 m_errorMonitor->VerifyFound();
10318
10319 EndCommandBuffer();
10320}
10321
Chris Forbes6d624702016-09-07 13:57:05 +120010322TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10323 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10324 "called before the final subpass has been reached");
10325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10327 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010328
10329 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10331 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010333 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010334
10335 VkRenderPass rp;
10336 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10337 ASSERT_VK_SUCCESS(err);
10338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010339 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010340
10341 VkFramebuffer fb;
10342 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10343 ASSERT_VK_SUCCESS(err);
10344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010345 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 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 +120010348
10349 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10350
10351 // Error here.
10352 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10353 m_errorMonitor->VerifyFound();
10354
10355 // Clean up.
10356 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10357 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10358}
10359
Karl Schultz9e66a292016-04-21 15:57:51 -060010360TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10361 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10363 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010364
10365 ASSERT_NO_FATAL_FAILURE(InitState());
10366 BeginCommandBuffer();
10367
10368 VkBufferMemoryBarrier buf_barrier = {};
10369 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10370 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10371 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10372 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10373 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10374 buf_barrier.buffer = VK_NULL_HANDLE;
10375 buf_barrier.offset = 0;
10376 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010377 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10378 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010379
10380 m_errorMonitor->VerifyFound();
10381}
10382
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010383TEST_F(VkLayerTest, InvalidBarriers) {
10384 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010387
10388 ASSERT_NO_FATAL_FAILURE(InitState());
10389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10390
10391 VkMemoryBarrier mem_barrier = {};
10392 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10393 mem_barrier.pNext = NULL;
10394 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10395 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10396 BeginCommandBuffer();
10397 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010398 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010399 &mem_barrier, 0, nullptr, 0, nullptr);
10400 m_errorMonitor->VerifyFound();
10401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010403 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 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 -060010405 ASSERT_TRUE(image.initialized());
10406 VkImageMemoryBarrier img_barrier = {};
10407 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10408 img_barrier.pNext = NULL;
10409 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10410 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10411 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10412 // New layout can't be UNDEFINED
10413 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10414 img_barrier.image = image.handle();
10415 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10416 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10417 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10418 img_barrier.subresourceRange.baseArrayLayer = 0;
10419 img_barrier.subresourceRange.baseMipLevel = 0;
10420 img_barrier.subresourceRange.layerCount = 1;
10421 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10423 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010424 m_errorMonitor->VerifyFound();
10425 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10428 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010429 // baseArrayLayer + layerCount must be <= image's arrayLayers
10430 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10432 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010433 m_errorMonitor->VerifyFound();
10434 img_barrier.subresourceRange.baseArrayLayer = 0;
10435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010437 // baseMipLevel + levelCount must be <= image's mipLevels
10438 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010439 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10440 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010441 m_errorMonitor->VerifyFound();
10442 img_barrier.subresourceRange.baseMipLevel = 0;
10443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010444 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 -060010445 vk_testing::Buffer buffer;
10446 buffer.init(*m_device, 256);
10447 VkBufferMemoryBarrier buf_barrier = {};
10448 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10449 buf_barrier.pNext = NULL;
10450 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10451 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10452 buf_barrier.buffer = buffer.handle();
10453 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10454 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10455 buf_barrier.offset = 0;
10456 buf_barrier.size = VK_WHOLE_SIZE;
10457 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010458 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10459 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010460 m_errorMonitor->VerifyFound();
10461 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010464 buf_barrier.offset = 257;
10465 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10467 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010468 m_errorMonitor->VerifyFound();
10469 buf_barrier.offset = 0;
10470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010472 buf_barrier.size = 257;
10473 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010474 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10475 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010476 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010477
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010478 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10480 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10481 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010482 VkDepthStencilObj ds_image(m_device);
10483 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10484 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010485 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10486 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010487 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010488 // Use of COLOR aspect on DS image is error
10489 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10491 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010492 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010493 // Now test depth-only
10494 VkFormatProperties format_props;
10495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10497 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10499 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010500 VkDepthStencilObj d_image(m_device);
10501 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10502 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010503 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010504 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010505 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010506 // Use of COLOR aspect on depth image is error
10507 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010508 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10509 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010510 m_errorMonitor->VerifyFound();
10511 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010512 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10513 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010514 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10516 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010517 VkDepthStencilObj s_image(m_device);
10518 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10519 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010520 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010521 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010522 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010523 // Use of COLOR aspect on depth image is error
10524 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10526 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010527 m_errorMonitor->VerifyFound();
10528 }
10529 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10531 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010532 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 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 -060010534 ASSERT_TRUE(c_image.initialized());
10535 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10536 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10537 img_barrier.image = c_image.handle();
10538 // Set aspect to depth (non-color)
10539 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010540 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10541 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010542 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010543}
10544
Karl Schultz6addd812016-02-02 17:17:23 -070010545TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010546 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010547 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010550
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010551 ASSERT_NO_FATAL_FAILURE(InitState());
10552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010553 uint32_t qfi = 0;
10554 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010555 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10556 buffCI.size = 1024;
10557 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10558 buffCI.queueFamilyIndexCount = 1;
10559 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010560
10561 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010562 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010563 ASSERT_VK_SUCCESS(err);
10564
10565 BeginCommandBuffer();
10566 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010567 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10568 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010569 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010571
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010572 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010573
Chia-I Wuf7458c52015-10-26 21:10:41 +080010574 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010575}
10576
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010577TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10578 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10580 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10581 "of the indices specified when the device was created, via the "
10582 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010583
10584 ASSERT_NO_FATAL_FAILURE(InitState());
10585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10586 VkBufferCreateInfo buffCI = {};
10587 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10588 buffCI.size = 1024;
10589 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10590 buffCI.queueFamilyIndexCount = 1;
10591 // Introduce failure by specifying invalid queue_family_index
10592 uint32_t qfi = 777;
10593 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010594 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010595
10596 VkBuffer ib;
10597 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10598
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010599 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010600 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010601}
10602
Karl Schultz6addd812016-02-02 17:17:23 -070010603TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010604 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10605 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010608
10609 ASSERT_NO_FATAL_FAILURE(InitState());
10610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010611
10612 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010613
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010614 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10615 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010616
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010617 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010618}
10619
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010620TEST_F(VkLayerTest, DSUsageBitsErrors) {
10621 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10622 "that do not have correct usage bits sets.");
10623 VkResult err;
10624
10625 ASSERT_NO_FATAL_FAILURE(InitState());
10626 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10627 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10628 ds_type_count[i].type = VkDescriptorType(i);
10629 ds_type_count[i].descriptorCount = 1;
10630 }
10631 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10632 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10633 ds_pool_ci.pNext = NULL;
10634 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10635 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10636 ds_pool_ci.pPoolSizes = ds_type_count;
10637
10638 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010639 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010640 ASSERT_VK_SUCCESS(err);
10641
10642 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010643 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010644 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10645 dsl_binding[i].binding = 0;
10646 dsl_binding[i].descriptorType = VkDescriptorType(i);
10647 dsl_binding[i].descriptorCount = 1;
10648 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10649 dsl_binding[i].pImmutableSamplers = NULL;
10650 }
10651
10652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10654 ds_layout_ci.pNext = NULL;
10655 ds_layout_ci.bindingCount = 1;
10656 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10657 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10658 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010660 ASSERT_VK_SUCCESS(err);
10661 }
10662 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10663 VkDescriptorSetAllocateInfo alloc_info = {};
10664 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10665 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10666 alloc_info.descriptorPool = ds_pool;
10667 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010668 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010669 ASSERT_VK_SUCCESS(err);
10670
10671 // Create a buffer & bufferView to be used for invalid updates
10672 VkBufferCreateInfo buff_ci = {};
10673 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10674 // This usage is not valid for any descriptor type
10675 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10676 buff_ci.size = 256;
10677 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10678 VkBuffer buffer;
10679 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10680 ASSERT_VK_SUCCESS(err);
10681
10682 VkBufferViewCreateInfo buff_view_ci = {};
10683 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10684 buff_view_ci.buffer = buffer;
10685 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10686 buff_view_ci.range = VK_WHOLE_SIZE;
10687 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010688 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010689 ASSERT_VK_SUCCESS(err);
10690
10691 // Create an image to be used for invalid updates
10692 VkImageCreateInfo image_ci = {};
10693 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10694 image_ci.imageType = VK_IMAGE_TYPE_2D;
10695 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10696 image_ci.extent.width = 64;
10697 image_ci.extent.height = 64;
10698 image_ci.extent.depth = 1;
10699 image_ci.mipLevels = 1;
10700 image_ci.arrayLayers = 1;
10701 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10702 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10703 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10704 // This usage is not valid for any descriptor type
10705 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10706 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10707 VkImage image;
10708 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10709 ASSERT_VK_SUCCESS(err);
10710 // Bind memory to image
10711 VkMemoryRequirements mem_reqs;
10712 VkDeviceMemory image_mem;
10713 bool pass;
10714 VkMemoryAllocateInfo mem_alloc = {};
10715 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10716 mem_alloc.pNext = NULL;
10717 mem_alloc.allocationSize = 0;
10718 mem_alloc.memoryTypeIndex = 0;
10719 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10720 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010721 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010722 ASSERT_TRUE(pass);
10723 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10724 ASSERT_VK_SUCCESS(err);
10725 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10726 ASSERT_VK_SUCCESS(err);
10727 // Now create view for image
10728 VkImageViewCreateInfo image_view_ci = {};
10729 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10730 image_view_ci.image = image;
10731 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10732 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10733 image_view_ci.subresourceRange.layerCount = 1;
10734 image_view_ci.subresourceRange.baseArrayLayer = 0;
10735 image_view_ci.subresourceRange.levelCount = 1;
10736 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10737 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010738 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010739 ASSERT_VK_SUCCESS(err);
10740
10741 VkDescriptorBufferInfo buff_info = {};
10742 buff_info.buffer = buffer;
10743 VkDescriptorImageInfo img_info = {};
10744 img_info.imageView = image_view;
10745 VkWriteDescriptorSet descriptor_write = {};
10746 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10747 descriptor_write.dstBinding = 0;
10748 descriptor_write.descriptorCount = 1;
10749 descriptor_write.pTexelBufferView = &buff_view;
10750 descriptor_write.pBufferInfo = &buff_info;
10751 descriptor_write.pImageInfo = &img_info;
10752
10753 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10755 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10756 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10757 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10758 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10759 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10760 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10761 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10762 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10763 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10764 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010765 // Start loop at 1 as SAMPLER desc type has no usage bit error
10766 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10767 descriptor_write.descriptorType = VkDescriptorType(i);
10768 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010771 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010772
10773 m_errorMonitor->VerifyFound();
10774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10775 }
10776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10777 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010778 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010779 vkDestroyImageView(m_device->device(), image_view, NULL);
10780 vkDestroyBuffer(m_device->device(), buffer, NULL);
10781 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010782 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010783 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10784}
10785
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010786TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010787 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10788 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10789 "1. offset value greater than buffer size\n"
10790 "2. range value of 0\n"
10791 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010792 VkResult err;
10793
10794 ASSERT_NO_FATAL_FAILURE(InitState());
10795 VkDescriptorPoolSize ds_type_count = {};
10796 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10797 ds_type_count.descriptorCount = 1;
10798
10799 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10800 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10801 ds_pool_ci.pNext = NULL;
10802 ds_pool_ci.maxSets = 1;
10803 ds_pool_ci.poolSizeCount = 1;
10804 ds_pool_ci.pPoolSizes = &ds_type_count;
10805
10806 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010807 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010808 ASSERT_VK_SUCCESS(err);
10809
10810 // Create layout with single uniform buffer descriptor
10811 VkDescriptorSetLayoutBinding dsl_binding = {};
10812 dsl_binding.binding = 0;
10813 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10814 dsl_binding.descriptorCount = 1;
10815 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10816 dsl_binding.pImmutableSamplers = NULL;
10817
10818 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10819 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10820 ds_layout_ci.pNext = NULL;
10821 ds_layout_ci.bindingCount = 1;
10822 ds_layout_ci.pBindings = &dsl_binding;
10823 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010825 ASSERT_VK_SUCCESS(err);
10826
10827 VkDescriptorSet descriptor_set = {};
10828 VkDescriptorSetAllocateInfo alloc_info = {};
10829 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10830 alloc_info.descriptorSetCount = 1;
10831 alloc_info.descriptorPool = ds_pool;
10832 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010834 ASSERT_VK_SUCCESS(err);
10835
10836 // Create a buffer to be used for invalid updates
10837 VkBufferCreateInfo buff_ci = {};
10838 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10839 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10840 buff_ci.size = 256;
10841 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10842 VkBuffer buffer;
10843 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10844 ASSERT_VK_SUCCESS(err);
10845 // Have to bind memory to buffer before descriptor update
10846 VkMemoryAllocateInfo mem_alloc = {};
10847 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10848 mem_alloc.pNext = NULL;
10849 mem_alloc.allocationSize = 256;
10850 mem_alloc.memoryTypeIndex = 0;
10851
10852 VkMemoryRequirements mem_reqs;
10853 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010855 if (!pass) {
10856 vkDestroyBuffer(m_device->device(), buffer, NULL);
10857 return;
10858 }
10859
10860 VkDeviceMemory mem;
10861 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10862 ASSERT_VK_SUCCESS(err);
10863 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10864 ASSERT_VK_SUCCESS(err);
10865
10866 VkDescriptorBufferInfo buff_info = {};
10867 buff_info.buffer = buffer;
10868 // First make offset 1 larger than buffer size
10869 buff_info.offset = 257;
10870 buff_info.range = VK_WHOLE_SIZE;
10871 VkWriteDescriptorSet descriptor_write = {};
10872 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10873 descriptor_write.dstBinding = 0;
10874 descriptor_write.descriptorCount = 1;
10875 descriptor_write.pTexelBufferView = nullptr;
10876 descriptor_write.pBufferInfo = &buff_info;
10877 descriptor_write.pImageInfo = nullptr;
10878
10879 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10880 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010882
10883 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10884
10885 m_errorMonitor->VerifyFound();
10886 // Now cause error due to range of 0
10887 buff_info.offset = 0;
10888 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10890 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010891
10892 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10893
10894 m_errorMonitor->VerifyFound();
10895 // Now cause error due to range exceeding buffer size - offset
10896 buff_info.offset = 128;
10897 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010898 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 -060010899
10900 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10901
10902 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010903 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010904 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10905 vkDestroyBuffer(m_device->device(), buffer, NULL);
10906 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10908}
10909
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010910TEST_F(VkLayerTest, DSAspectBitsErrors) {
10911 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10912 // are set, but could expand this test to hit more cases.
10913 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10914 "that do not have correct aspect bits sets.");
10915 VkResult err;
10916
10917 ASSERT_NO_FATAL_FAILURE(InitState());
10918 VkDescriptorPoolSize ds_type_count = {};
10919 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10920 ds_type_count.descriptorCount = 1;
10921
10922 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10923 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10924 ds_pool_ci.pNext = NULL;
10925 ds_pool_ci.maxSets = 5;
10926 ds_pool_ci.poolSizeCount = 1;
10927 ds_pool_ci.pPoolSizes = &ds_type_count;
10928
10929 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010930 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010931 ASSERT_VK_SUCCESS(err);
10932
10933 VkDescriptorSetLayoutBinding dsl_binding = {};
10934 dsl_binding.binding = 0;
10935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10936 dsl_binding.descriptorCount = 1;
10937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10938 dsl_binding.pImmutableSamplers = NULL;
10939
10940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10942 ds_layout_ci.pNext = NULL;
10943 ds_layout_ci.bindingCount = 1;
10944 ds_layout_ci.pBindings = &dsl_binding;
10945 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010947 ASSERT_VK_SUCCESS(err);
10948
10949 VkDescriptorSet descriptor_set = {};
10950 VkDescriptorSetAllocateInfo alloc_info = {};
10951 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10952 alloc_info.descriptorSetCount = 1;
10953 alloc_info.descriptorPool = ds_pool;
10954 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010956 ASSERT_VK_SUCCESS(err);
10957
10958 // Create an image to be used for invalid updates
10959 VkImageCreateInfo image_ci = {};
10960 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10961 image_ci.imageType = VK_IMAGE_TYPE_2D;
10962 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10963 image_ci.extent.width = 64;
10964 image_ci.extent.height = 64;
10965 image_ci.extent.depth = 1;
10966 image_ci.mipLevels = 1;
10967 image_ci.arrayLayers = 1;
10968 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10969 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10970 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10971 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10972 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10973 VkImage image;
10974 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10975 ASSERT_VK_SUCCESS(err);
10976 // Bind memory to image
10977 VkMemoryRequirements mem_reqs;
10978 VkDeviceMemory image_mem;
10979 bool pass;
10980 VkMemoryAllocateInfo mem_alloc = {};
10981 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10982 mem_alloc.pNext = NULL;
10983 mem_alloc.allocationSize = 0;
10984 mem_alloc.memoryTypeIndex = 0;
10985 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10986 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010987 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010988 ASSERT_TRUE(pass);
10989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10990 ASSERT_VK_SUCCESS(err);
10991 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10992 ASSERT_VK_SUCCESS(err);
10993 // Now create view for image
10994 VkImageViewCreateInfo image_view_ci = {};
10995 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10996 image_view_ci.image = image;
10997 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10998 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10999 image_view_ci.subresourceRange.layerCount = 1;
11000 image_view_ci.subresourceRange.baseArrayLayer = 0;
11001 image_view_ci.subresourceRange.levelCount = 1;
11002 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011003 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011004
11005 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011007 ASSERT_VK_SUCCESS(err);
11008
11009 VkDescriptorImageInfo img_info = {};
11010 img_info.imageView = image_view;
11011 VkWriteDescriptorSet descriptor_write = {};
11012 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11013 descriptor_write.dstBinding = 0;
11014 descriptor_write.descriptorCount = 1;
11015 descriptor_write.pTexelBufferView = NULL;
11016 descriptor_write.pBufferInfo = NULL;
11017 descriptor_write.pImageInfo = &img_info;
11018 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
11019 descriptor_write.dstSet = descriptor_set;
11020 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
11021 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011023
11024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11025
11026 m_errorMonitor->VerifyFound();
11027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11028 vkDestroyImage(m_device->device(), image, NULL);
11029 vkFreeMemory(m_device->device(), image_mem, NULL);
11030 vkDestroyImageView(m_device->device(), image_view, NULL);
11031 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11032 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11033}
11034
Karl Schultz6addd812016-02-02 17:17:23 -070011035TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011036 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070011037 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11040 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
11041 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011042
Tobin Ehlis3b780662015-05-28 12:11:26 -060011043 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011044 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011045 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011046 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11047 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011048
11049 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011050 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11051 ds_pool_ci.pNext = NULL;
11052 ds_pool_ci.maxSets = 1;
11053 ds_pool_ci.poolSizeCount = 1;
11054 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011055
Tobin Ehlis3b780662015-05-28 12:11:26 -060011056 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011057 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011058 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011059 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011060 dsl_binding.binding = 0;
11061 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11062 dsl_binding.descriptorCount = 1;
11063 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11064 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011065
Tony Barboureb254902015-07-15 12:50:33 -060011066 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011067 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11068 ds_layout_ci.pNext = NULL;
11069 ds_layout_ci.bindingCount = 1;
11070 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011071
Tobin Ehlis3b780662015-05-28 12:11:26 -060011072 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011073 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011074 ASSERT_VK_SUCCESS(err);
11075
11076 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011077 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011078 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011079 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011080 alloc_info.descriptorPool = ds_pool;
11081 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011082 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011083 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011084
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011085 VkSamplerCreateInfo sampler_ci = {};
11086 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11087 sampler_ci.pNext = NULL;
11088 sampler_ci.magFilter = VK_FILTER_NEAREST;
11089 sampler_ci.minFilter = VK_FILTER_NEAREST;
11090 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11091 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11092 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11093 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11094 sampler_ci.mipLodBias = 1.0;
11095 sampler_ci.anisotropyEnable = VK_FALSE;
11096 sampler_ci.maxAnisotropy = 1;
11097 sampler_ci.compareEnable = VK_FALSE;
11098 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11099 sampler_ci.minLod = 1.0;
11100 sampler_ci.maxLod = 1.0;
11101 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11102 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11103 VkSampler sampler;
11104 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11105 ASSERT_VK_SUCCESS(err);
11106
11107 VkDescriptorImageInfo info = {};
11108 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011109
11110 VkWriteDescriptorSet descriptor_write;
11111 memset(&descriptor_write, 0, sizeof(descriptor_write));
11112 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011113 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011114 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011115 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011116 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011117 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011118
11119 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011121 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011122
Chia-I Wuf7458c52015-10-26 21:10:41 +080011123 vkDestroySampler(m_device->device(), sampler, NULL);
11124 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11125 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011126}
11127
Karl Schultz6addd812016-02-02 17:17:23 -070011128TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011129 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070011130 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11133 " binding #0 with 1 total descriptors but update of 1 descriptors "
11134 "starting at binding offset of 0 combined with update array element "
11135 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011136
Tobin Ehlis3b780662015-05-28 12:11:26 -060011137 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011138 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011139 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011140 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11141 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011142
11143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11145 ds_pool_ci.pNext = NULL;
11146 ds_pool_ci.maxSets = 1;
11147 ds_pool_ci.poolSizeCount = 1;
11148 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011149
Tobin Ehlis3b780662015-05-28 12:11:26 -060011150 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011152 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011153
Tony Barboureb254902015-07-15 12:50:33 -060011154 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011155 dsl_binding.binding = 0;
11156 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11157 dsl_binding.descriptorCount = 1;
11158 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11159 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011160
11161 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011162 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11163 ds_layout_ci.pNext = NULL;
11164 ds_layout_ci.bindingCount = 1;
11165 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011166
Tobin Ehlis3b780662015-05-28 12:11:26 -060011167 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011168 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011169 ASSERT_VK_SUCCESS(err);
11170
11171 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011172 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011174 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011175 alloc_info.descriptorPool = ds_pool;
11176 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011177 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011178 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011179
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011180 // Correctly update descriptor to avoid "NOT_UPDATED" error
11181 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011182 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011183 buff_info.offset = 0;
11184 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011185
11186 VkWriteDescriptorSet descriptor_write;
11187 memset(&descriptor_write, 0, sizeof(descriptor_write));
11188 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011189 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011191 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11193 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011194
11195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11196
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011197 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011198
Chia-I Wuf7458c52015-10-26 21:10:41 +080011199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11200 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011201}
11202
Karl Schultz6addd812016-02-02 17:17:23 -070011203TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
11204 // Create layout w/ count of 1 and attempt update to that layout w/ binding
11205 // index 2
11206 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011209
Tobin Ehlis3b780662015-05-28 12:11:26 -060011210 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011211 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011212 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011213 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11214 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011215
11216 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011217 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11218 ds_pool_ci.pNext = NULL;
11219 ds_pool_ci.maxSets = 1;
11220 ds_pool_ci.poolSizeCount = 1;
11221 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011222
Tobin Ehlis3b780662015-05-28 12:11:26 -060011223 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011224 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011225 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011226
Tony Barboureb254902015-07-15 12:50:33 -060011227 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011228 dsl_binding.binding = 0;
11229 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11230 dsl_binding.descriptorCount = 1;
11231 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11232 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011233
11234 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011235 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11236 ds_layout_ci.pNext = NULL;
11237 ds_layout_ci.bindingCount = 1;
11238 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011239 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011240 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011241 ASSERT_VK_SUCCESS(err);
11242
11243 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011244 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011245 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011246 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011247 alloc_info.descriptorPool = ds_pool;
11248 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011249 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011250 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011251
Tony Barboureb254902015-07-15 12:50:33 -060011252 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011253 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11254 sampler_ci.pNext = NULL;
11255 sampler_ci.magFilter = VK_FILTER_NEAREST;
11256 sampler_ci.minFilter = VK_FILTER_NEAREST;
11257 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11258 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11259 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11260 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11261 sampler_ci.mipLodBias = 1.0;
11262 sampler_ci.anisotropyEnable = VK_FALSE;
11263 sampler_ci.maxAnisotropy = 1;
11264 sampler_ci.compareEnable = VK_FALSE;
11265 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11266 sampler_ci.minLod = 1.0;
11267 sampler_ci.maxLod = 1.0;
11268 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11269 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011270
Tobin Ehlis3b780662015-05-28 12:11:26 -060011271 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011272 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011273 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011274
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011275 VkDescriptorImageInfo info = {};
11276 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011277
11278 VkWriteDescriptorSet descriptor_write;
11279 memset(&descriptor_write, 0, sizeof(descriptor_write));
11280 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011281 descriptor_write.dstSet = descriptorSet;
11282 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011283 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011284 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011285 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011286 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011287
11288 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11289
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011290 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011291
Chia-I Wuf7458c52015-10-26 21:10:41 +080011292 vkDestroySampler(m_device->device(), sampler, NULL);
11293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11294 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011295}
11296
Karl Schultz6addd812016-02-02 17:17:23 -070011297TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11298 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11299 // types
11300 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011302 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 -060011303
Tobin Ehlis3b780662015-05-28 12:11:26 -060011304 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011305
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011306 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011307 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11308 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011309
11310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11312 ds_pool_ci.pNext = NULL;
11313 ds_pool_ci.maxSets = 1;
11314 ds_pool_ci.poolSizeCount = 1;
11315 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011316
Tobin Ehlis3b780662015-05-28 12:11:26 -060011317 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011318 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011319 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011321 dsl_binding.binding = 0;
11322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11323 dsl_binding.descriptorCount = 1;
11324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11325 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011326
Tony Barboureb254902015-07-15 12:50:33 -060011327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11329 ds_layout_ci.pNext = NULL;
11330 ds_layout_ci.bindingCount = 1;
11331 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011332
Tobin Ehlis3b780662015-05-28 12:11:26 -060011333 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011335 ASSERT_VK_SUCCESS(err);
11336
11337 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011338 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011339 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011340 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011341 alloc_info.descriptorPool = ds_pool;
11342 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011343 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011344 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011345
Tony Barboureb254902015-07-15 12:50:33 -060011346 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011347 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11348 sampler_ci.pNext = NULL;
11349 sampler_ci.magFilter = VK_FILTER_NEAREST;
11350 sampler_ci.minFilter = VK_FILTER_NEAREST;
11351 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11352 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11353 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11354 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11355 sampler_ci.mipLodBias = 1.0;
11356 sampler_ci.anisotropyEnable = VK_FALSE;
11357 sampler_ci.maxAnisotropy = 1;
11358 sampler_ci.compareEnable = VK_FALSE;
11359 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11360 sampler_ci.minLod = 1.0;
11361 sampler_ci.maxLod = 1.0;
11362 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11363 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011364 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011365 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011366 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011367
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011368 VkDescriptorImageInfo info = {};
11369 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011370
11371 VkWriteDescriptorSet descriptor_write;
11372 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011373 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011374 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011375 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011376 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011377 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011378 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011379
11380 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11381
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011382 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011383
Chia-I Wuf7458c52015-10-26 21:10:41 +080011384 vkDestroySampler(m_device->device(), sampler, NULL);
11385 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11386 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011387}
11388
Karl Schultz6addd812016-02-02 17:17:23 -070011389TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011390 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011391 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11394 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011395
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011396 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011397 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11398 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011399 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011400 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11401 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011402
11403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11405 ds_pool_ci.pNext = NULL;
11406 ds_pool_ci.maxSets = 1;
11407 ds_pool_ci.poolSizeCount = 1;
11408 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011409
11410 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011411 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011412 ASSERT_VK_SUCCESS(err);
11413
11414 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011415 dsl_binding.binding = 0;
11416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11417 dsl_binding.descriptorCount = 1;
11418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11419 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011420
11421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11423 ds_layout_ci.pNext = NULL;
11424 ds_layout_ci.bindingCount = 1;
11425 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011426 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011427 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011428 ASSERT_VK_SUCCESS(err);
11429
11430 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011431 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011432 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011433 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011434 alloc_info.descriptorPool = ds_pool;
11435 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011436 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011437 ASSERT_VK_SUCCESS(err);
11438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011439 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011440
11441 VkDescriptorImageInfo descriptor_info;
11442 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11443 descriptor_info.sampler = sampler;
11444
11445 VkWriteDescriptorSet descriptor_write;
11446 memset(&descriptor_write, 0, sizeof(descriptor_write));
11447 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011448 descriptor_write.dstSet = descriptorSet;
11449 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011450 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011451 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11452 descriptor_write.pImageInfo = &descriptor_info;
11453
11454 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11455
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011456 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011457
Chia-I Wuf7458c52015-10-26 21:10:41 +080011458 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011460}
11461
Karl Schultz6addd812016-02-02 17:17:23 -070011462TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11463 // Create a single combined Image/Sampler descriptor and send it an invalid
11464 // imageView
11465 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11468 "image sampler descriptor failed due "
11469 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011470
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011471 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011472 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011473 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11474 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011475
11476 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011477 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11478 ds_pool_ci.pNext = NULL;
11479 ds_pool_ci.maxSets = 1;
11480 ds_pool_ci.poolSizeCount = 1;
11481 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011482
11483 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011484 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011485 ASSERT_VK_SUCCESS(err);
11486
11487 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011488 dsl_binding.binding = 0;
11489 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11490 dsl_binding.descriptorCount = 1;
11491 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11492 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011493
11494 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011495 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11496 ds_layout_ci.pNext = NULL;
11497 ds_layout_ci.bindingCount = 1;
11498 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011499 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011501 ASSERT_VK_SUCCESS(err);
11502
11503 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011504 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011506 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011507 alloc_info.descriptorPool = ds_pool;
11508 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011510 ASSERT_VK_SUCCESS(err);
11511
11512 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011513 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11514 sampler_ci.pNext = NULL;
11515 sampler_ci.magFilter = VK_FILTER_NEAREST;
11516 sampler_ci.minFilter = VK_FILTER_NEAREST;
11517 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11518 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11519 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11520 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11521 sampler_ci.mipLodBias = 1.0;
11522 sampler_ci.anisotropyEnable = VK_FALSE;
11523 sampler_ci.maxAnisotropy = 1;
11524 sampler_ci.compareEnable = VK_FALSE;
11525 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11526 sampler_ci.minLod = 1.0;
11527 sampler_ci.maxLod = 1.0;
11528 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11529 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011530
11531 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011532 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011533 ASSERT_VK_SUCCESS(err);
11534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011536
11537 VkDescriptorImageInfo descriptor_info;
11538 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11539 descriptor_info.sampler = sampler;
11540 descriptor_info.imageView = view;
11541
11542 VkWriteDescriptorSet descriptor_write;
11543 memset(&descriptor_write, 0, sizeof(descriptor_write));
11544 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011545 descriptor_write.dstSet = descriptorSet;
11546 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011547 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011548 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11549 descriptor_write.pImageInfo = &descriptor_info;
11550
11551 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11552
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011553 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011554
Chia-I Wuf7458c52015-10-26 21:10:41 +080011555 vkDestroySampler(m_device->device(), sampler, NULL);
11556 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011558}
11559
Karl Schultz6addd812016-02-02 17:17:23 -070011560TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11561 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11562 // into the other
11563 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11566 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11567 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011568
Tobin Ehlis04356f92015-10-27 16:35:27 -060011569 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011570 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011571 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011572 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11573 ds_type_count[0].descriptorCount = 1;
11574 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11575 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011576
11577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11579 ds_pool_ci.pNext = NULL;
11580 ds_pool_ci.maxSets = 1;
11581 ds_pool_ci.poolSizeCount = 2;
11582 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011583
11584 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011585 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011586 ASSERT_VK_SUCCESS(err);
11587 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011588 dsl_binding[0].binding = 0;
11589 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11590 dsl_binding[0].descriptorCount = 1;
11591 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11592 dsl_binding[0].pImmutableSamplers = NULL;
11593 dsl_binding[1].binding = 1;
11594 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11595 dsl_binding[1].descriptorCount = 1;
11596 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11597 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011598
11599 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011600 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11601 ds_layout_ci.pNext = NULL;
11602 ds_layout_ci.bindingCount = 2;
11603 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011604
11605 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011606 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011607 ASSERT_VK_SUCCESS(err);
11608
11609 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011610 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011611 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011612 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011613 alloc_info.descriptorPool = ds_pool;
11614 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011616 ASSERT_VK_SUCCESS(err);
11617
11618 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011619 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11620 sampler_ci.pNext = NULL;
11621 sampler_ci.magFilter = VK_FILTER_NEAREST;
11622 sampler_ci.minFilter = VK_FILTER_NEAREST;
11623 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11624 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11625 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11626 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11627 sampler_ci.mipLodBias = 1.0;
11628 sampler_ci.anisotropyEnable = VK_FALSE;
11629 sampler_ci.maxAnisotropy = 1;
11630 sampler_ci.compareEnable = VK_FALSE;
11631 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11632 sampler_ci.minLod = 1.0;
11633 sampler_ci.maxLod = 1.0;
11634 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11635 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011636
11637 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011638 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011639 ASSERT_VK_SUCCESS(err);
11640
11641 VkDescriptorImageInfo info = {};
11642 info.sampler = sampler;
11643
11644 VkWriteDescriptorSet descriptor_write;
11645 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11646 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011647 descriptor_write.dstSet = descriptorSet;
11648 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011649 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011650 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11651 descriptor_write.pImageInfo = &info;
11652 // This write update should succeed
11653 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11654 // Now perform a copy update that fails due to type mismatch
11655 VkCopyDescriptorSet copy_ds_update;
11656 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11657 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11658 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011659 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011660 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011661 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011662 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011663 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011665 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011666 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011667 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 -060011668 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11669 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11670 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011671 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011672 copy_ds_update.dstSet = descriptorSet;
11673 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011674 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011675 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11676
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011677 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011678
Tobin Ehlis04356f92015-10-27 16:35:27 -060011679 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11681 "update array offset of 0 and update of "
11682 "5 descriptors oversteps total number "
11683 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011684
Tobin Ehlis04356f92015-10-27 16:35:27 -060011685 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11686 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11687 copy_ds_update.srcSet = descriptorSet;
11688 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011689 copy_ds_update.dstSet = descriptorSet;
11690 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011691 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011692 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11693
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011694 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011695
Chia-I Wuf7458c52015-10-26 21:10:41 +080011696 vkDestroySampler(m_device->device(), sampler, NULL);
11697 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11698 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011699}
11700
Karl Schultz6addd812016-02-02 17:17:23 -070011701TEST_F(VkLayerTest, NumSamplesMismatch) {
11702 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11703 // sampleCount
11704 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011707
Tobin Ehlis3b780662015-05-28 12:11:26 -060011708 ASSERT_NO_FATAL_FAILURE(InitState());
11709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011710 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011711 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011712 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011713
11714 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011715 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11716 ds_pool_ci.pNext = NULL;
11717 ds_pool_ci.maxSets = 1;
11718 ds_pool_ci.poolSizeCount = 1;
11719 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011720
Tobin Ehlis3b780662015-05-28 12:11:26 -060011721 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011722 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011723 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011724
Tony Barboureb254902015-07-15 12:50:33 -060011725 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011726 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011727 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011728 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011729 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11730 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011731
Tony Barboureb254902015-07-15 12:50:33 -060011732 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11733 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11734 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011735 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011736 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011737
Tobin Ehlis3b780662015-05-28 12:11:26 -060011738 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011740 ASSERT_VK_SUCCESS(err);
11741
11742 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011743 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011744 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011745 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011746 alloc_info.descriptorPool = ds_pool;
11747 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011749 ASSERT_VK_SUCCESS(err);
11750
Tony Barboureb254902015-07-15 12:50:33 -060011751 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011752 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011753 pipe_ms_state_ci.pNext = NULL;
11754 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11755 pipe_ms_state_ci.sampleShadingEnable = 0;
11756 pipe_ms_state_ci.minSampleShading = 1.0;
11757 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011758
Tony Barboureb254902015-07-15 12:50:33 -060011759 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011760 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11761 pipeline_layout_ci.pNext = NULL;
11762 pipeline_layout_ci.setLayoutCount = 1;
11763 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011764
11765 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011766 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011767 ASSERT_VK_SUCCESS(err);
11768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011769 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11770 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11771 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011772 VkPipelineObj pipe(m_device);
11773 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011774 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011775 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011776 pipe.SetMSAA(&pipe_ms_state_ci);
11777 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011778
Tony Barbourfe3351b2015-07-28 10:17:20 -060011779 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011780 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011781
Mark Young29927482016-05-04 14:38:51 -060011782 // Render triangle (the error should trigger on the attempt to draw).
11783 Draw(3, 1, 0, 0);
11784
11785 // Finalize recording of the command buffer
11786 EndCommandBuffer();
11787
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011788 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011789
Chia-I Wuf7458c52015-10-26 21:10:41 +080011790 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11792 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011793}
Mark Young29927482016-05-04 14:38:51 -060011794
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011795TEST_F(VkLayerTest, RenderPassIncompatible) {
11796 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11797 "Initial case is drawing with an active renderpass that's "
11798 "not compatible with the bound PSO's creation renderpass");
11799 VkResult err;
11800
11801 ASSERT_NO_FATAL_FAILURE(InitState());
11802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11803
11804 VkDescriptorSetLayoutBinding dsl_binding = {};
11805 dsl_binding.binding = 0;
11806 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11807 dsl_binding.descriptorCount = 1;
11808 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11809 dsl_binding.pImmutableSamplers = NULL;
11810
11811 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11812 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11813 ds_layout_ci.pNext = NULL;
11814 ds_layout_ci.bindingCount = 1;
11815 ds_layout_ci.pBindings = &dsl_binding;
11816
11817 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011818 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011819 ASSERT_VK_SUCCESS(err);
11820
11821 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11822 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11823 pipeline_layout_ci.pNext = NULL;
11824 pipeline_layout_ci.setLayoutCount = 1;
11825 pipeline_layout_ci.pSetLayouts = &ds_layout;
11826
11827 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011828 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011829 ASSERT_VK_SUCCESS(err);
11830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011831 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11832 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11833 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011834 // Create a renderpass that will be incompatible with default renderpass
11835 VkAttachmentReference attach = {};
11836 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11837 VkAttachmentReference color_att = {};
11838 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11839 VkSubpassDescription subpass = {};
11840 subpass.inputAttachmentCount = 1;
11841 subpass.pInputAttachments = &attach;
11842 subpass.colorAttachmentCount = 1;
11843 subpass.pColorAttachments = &color_att;
11844 VkRenderPassCreateInfo rpci = {};
11845 rpci.subpassCount = 1;
11846 rpci.pSubpasses = &subpass;
11847 rpci.attachmentCount = 1;
11848 VkAttachmentDescription attach_desc = {};
11849 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011850 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11851 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011852 rpci.pAttachments = &attach_desc;
11853 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11854 VkRenderPass rp;
11855 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11856 VkPipelineObj pipe(m_device);
11857 pipe.AddShader(&vs);
11858 pipe.AddShader(&fs);
11859 pipe.AddColorAttachment();
11860 VkViewport view_port = {};
11861 m_viewports.push_back(view_port);
11862 pipe.SetViewport(m_viewports);
11863 VkRect2D rect = {};
11864 m_scissors.push_back(rect);
11865 pipe.SetScissor(m_scissors);
11866 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11867
11868 VkCommandBufferInheritanceInfo cbii = {};
11869 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11870 cbii.renderPass = rp;
11871 cbii.subpass = 0;
11872 VkCommandBufferBeginInfo cbbi = {};
11873 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11874 cbbi.pInheritanceInfo = &cbii;
11875 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11876 VkRenderPassBeginInfo rpbi = {};
11877 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11878 rpbi.framebuffer = m_framebuffer;
11879 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011880 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11881 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011884 // Render triangle (the error should trigger on the attempt to draw).
11885 Draw(3, 1, 0, 0);
11886
11887 // Finalize recording of the command buffer
11888 EndCommandBuffer();
11889
11890 m_errorMonitor->VerifyFound();
11891
11892 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11893 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11894 vkDestroyRenderPass(m_device->device(), rp, NULL);
11895}
11896
Mark Youngc89c6312016-03-31 16:03:20 -060011897TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11898 // Create Pipeline where the number of blend attachments doesn't match the
11899 // number of color attachments. In this case, we don't add any color
11900 // blend attachments even though we have a color attachment.
11901 VkResult err;
11902
11903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011904 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011905
11906 ASSERT_NO_FATAL_FAILURE(InitState());
11907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11908 VkDescriptorPoolSize ds_type_count = {};
11909 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11910 ds_type_count.descriptorCount = 1;
11911
11912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11914 ds_pool_ci.pNext = NULL;
11915 ds_pool_ci.maxSets = 1;
11916 ds_pool_ci.poolSizeCount = 1;
11917 ds_pool_ci.pPoolSizes = &ds_type_count;
11918
11919 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011920 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011921 ASSERT_VK_SUCCESS(err);
11922
11923 VkDescriptorSetLayoutBinding dsl_binding = {};
11924 dsl_binding.binding = 0;
11925 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11926 dsl_binding.descriptorCount = 1;
11927 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11928 dsl_binding.pImmutableSamplers = NULL;
11929
11930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11932 ds_layout_ci.pNext = NULL;
11933 ds_layout_ci.bindingCount = 1;
11934 ds_layout_ci.pBindings = &dsl_binding;
11935
11936 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011938 ASSERT_VK_SUCCESS(err);
11939
11940 VkDescriptorSet descriptorSet;
11941 VkDescriptorSetAllocateInfo alloc_info = {};
11942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11943 alloc_info.descriptorSetCount = 1;
11944 alloc_info.descriptorPool = ds_pool;
11945 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011946 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011947 ASSERT_VK_SUCCESS(err);
11948
11949 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011950 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011951 pipe_ms_state_ci.pNext = NULL;
11952 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11953 pipe_ms_state_ci.sampleShadingEnable = 0;
11954 pipe_ms_state_ci.minSampleShading = 1.0;
11955 pipe_ms_state_ci.pSampleMask = NULL;
11956
11957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11958 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11959 pipeline_layout_ci.pNext = NULL;
11960 pipeline_layout_ci.setLayoutCount = 1;
11961 pipeline_layout_ci.pSetLayouts = &ds_layout;
11962
11963 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011964 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011965 ASSERT_VK_SUCCESS(err);
11966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011967 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11968 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11969 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011970 VkPipelineObj pipe(m_device);
11971 pipe.AddShader(&vs);
11972 pipe.AddShader(&fs);
11973 pipe.SetMSAA(&pipe_ms_state_ci);
11974 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11975
11976 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011977 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011978
Mark Young29927482016-05-04 14:38:51 -060011979 // Render triangle (the error should trigger on the attempt to draw).
11980 Draw(3, 1, 0, 0);
11981
11982 // Finalize recording of the command buffer
11983 EndCommandBuffer();
11984
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011985 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011986
11987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11990}
Mark Young29927482016-05-04 14:38:51 -060011991
Mark Muellerd4914412016-06-13 17:52:06 -060011992TEST_F(VkLayerTest, MissingClearAttachment) {
11993 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11994 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011995 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011997 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011998
11999 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
12000 m_errorMonitor->VerifyFound();
12001}
12002
Karl Schultz6addd812016-02-02 17:17:23 -070012003TEST_F(VkLayerTest, ClearCmdNoDraw) {
12004 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
12005 // to issuing a Draw
12006 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12009 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012010
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012011 ASSERT_NO_FATAL_FAILURE(InitState());
12012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012013
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012014 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012015 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12016 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012017
12018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12020 ds_pool_ci.pNext = NULL;
12021 ds_pool_ci.maxSets = 1;
12022 ds_pool_ci.poolSizeCount = 1;
12023 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012024
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012025 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012027 ASSERT_VK_SUCCESS(err);
12028
Tony Barboureb254902015-07-15 12:50:33 -060012029 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012030 dsl_binding.binding = 0;
12031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12032 dsl_binding.descriptorCount = 1;
12033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12034 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012035
Tony Barboureb254902015-07-15 12:50:33 -060012036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12038 ds_layout_ci.pNext = NULL;
12039 ds_layout_ci.bindingCount = 1;
12040 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012041
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012042 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012044 ASSERT_VK_SUCCESS(err);
12045
12046 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012047 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012049 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012050 alloc_info.descriptorPool = ds_pool;
12051 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012053 ASSERT_VK_SUCCESS(err);
12054
Tony Barboureb254902015-07-15 12:50:33 -060012055 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012056 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012057 pipe_ms_state_ci.pNext = NULL;
12058 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
12059 pipe_ms_state_ci.sampleShadingEnable = 0;
12060 pipe_ms_state_ci.minSampleShading = 1.0;
12061 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012062
Tony Barboureb254902015-07-15 12:50:33 -060012063 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012064 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12065 pipeline_layout_ci.pNext = NULL;
12066 pipeline_layout_ci.setLayoutCount = 1;
12067 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012068
12069 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012070 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012071 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012073 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060012074 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070012075 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012076 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012077
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012078 VkPipelineObj pipe(m_device);
12079 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012080 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012081 pipe.SetMSAA(&pipe_ms_state_ci);
12082 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012083
12084 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012085
Karl Schultz6addd812016-02-02 17:17:23 -070012086 // Main thing we care about for this test is that the VkImage obj we're
12087 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012088 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060012089 VkClearAttachment color_attachment;
12090 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12091 color_attachment.clearValue.color.float32[0] = 1.0;
12092 color_attachment.clearValue.color.float32[1] = 1.0;
12093 color_attachment.clearValue.color.float32[2] = 1.0;
12094 color_attachment.clearValue.color.float32[3] = 1.0;
12095 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012096 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012098 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012099
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012100 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012101
Chia-I Wuf7458c52015-10-26 21:10:41 +080012102 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12103 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12104 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012105}
12106
Karl Schultz6addd812016-02-02 17:17:23 -070012107TEST_F(VkLayerTest, VtxBufferBadIndex) {
12108 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12111 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012112
Tobin Ehlis502480b2015-06-24 15:53:07 -060012113 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012114 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012116
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012117 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012118 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12119 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012120
12121 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012122 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12123 ds_pool_ci.pNext = NULL;
12124 ds_pool_ci.maxSets = 1;
12125 ds_pool_ci.poolSizeCount = 1;
12126 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012127
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012128 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012129 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012130 ASSERT_VK_SUCCESS(err);
12131
Tony Barboureb254902015-07-15 12:50:33 -060012132 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012133 dsl_binding.binding = 0;
12134 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12135 dsl_binding.descriptorCount = 1;
12136 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12137 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012138
Tony Barboureb254902015-07-15 12:50:33 -060012139 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012140 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12141 ds_layout_ci.pNext = NULL;
12142 ds_layout_ci.bindingCount = 1;
12143 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012144
Tobin Ehlis502480b2015-06-24 15:53:07 -060012145 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012146 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012147 ASSERT_VK_SUCCESS(err);
12148
12149 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012150 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012151 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012152 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012153 alloc_info.descriptorPool = ds_pool;
12154 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012155 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012156 ASSERT_VK_SUCCESS(err);
12157
Tony Barboureb254902015-07-15 12:50:33 -060012158 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012159 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012160 pipe_ms_state_ci.pNext = NULL;
12161 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12162 pipe_ms_state_ci.sampleShadingEnable = 0;
12163 pipe_ms_state_ci.minSampleShading = 1.0;
12164 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012165
Tony Barboureb254902015-07-15 12:50:33 -060012166 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012167 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12168 pipeline_layout_ci.pNext = NULL;
12169 pipeline_layout_ci.setLayoutCount = 1;
12170 pipeline_layout_ci.pSetLayouts = &ds_layout;
12171 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012173 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012174 ASSERT_VK_SUCCESS(err);
12175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012176 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12177 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
12178 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012179 VkPipelineObj pipe(m_device);
12180 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012181 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012182 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012183 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012184 pipe.SetViewport(m_viewports);
12185 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012186 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012187
12188 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012189 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012190 // Don't care about actual data, just need to get to draw to flag error
12191 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012192 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012193 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012194 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012195
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012196 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012197
Chia-I Wuf7458c52015-10-26 21:10:41 +080012198 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12200 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012201}
Mark Muellerdfe37552016-07-07 14:47:42 -060012202
Mark Mueller2ee294f2016-08-04 12:59:48 -060012203TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
12204 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
12205 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060012206 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012208 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
12209 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012211 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
12212 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012214 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060012217 // The following test fails with recent NVidia drivers.
12218 // By the time core_validation is reached, the NVidia
12219 // driver has sanitized the invalid condition and core_validation
12220 // is not introduced to the failure condition. This is not the case
12221 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 // uint32_t count = static_cast<uint32_t>(~0);
12223 // VkPhysicalDevice physical_device;
12224 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12225 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012228 float queue_priority = 0.0;
12229
12230 VkDeviceQueueCreateInfo queue_create_info = {};
12231 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12232 queue_create_info.queueCount = 1;
12233 queue_create_info.pQueuePriorities = &queue_priority;
12234 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12235
12236 VkPhysicalDeviceFeatures features = m_device->phy().features();
12237 VkDevice testDevice;
12238 VkDeviceCreateInfo device_create_info = {};
12239 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12240 device_create_info.queueCreateInfoCount = 1;
12241 device_create_info.pQueueCreateInfos = &queue_create_info;
12242 device_create_info.pEnabledFeatures = &features;
12243 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12244 m_errorMonitor->VerifyFound();
12245
12246 queue_create_info.queueFamilyIndex = 1;
12247
12248 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12249 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12250 for (unsigned i = 0; i < feature_count; i++) {
12251 if (VK_FALSE == feature_array[i]) {
12252 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012254 device_create_info.pEnabledFeatures = &features;
12255 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12256 m_errorMonitor->VerifyFound();
12257 break;
12258 }
12259 }
12260}
12261
12262TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12263 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12264 "End a command buffer with a query still in progress.");
12265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012266 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12267 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12268 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012273
12274 ASSERT_NO_FATAL_FAILURE(InitState());
12275
12276 VkEvent event;
12277 VkEventCreateInfo event_create_info{};
12278 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12279 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12280
Mark Mueller2ee294f2016-08-04 12:59:48 -060012281 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012283
12284 BeginCommandBuffer();
12285
12286 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012287 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 -060012288 ASSERT_TRUE(image.initialized());
12289 VkImageMemoryBarrier img_barrier = {};
12290 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12291 img_barrier.pNext = NULL;
12292 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12293 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12294 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12295 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12296 img_barrier.image = image.handle();
12297 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012298
12299 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12300 // that layer validation catches the case when it is not.
12301 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012302 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12303 img_barrier.subresourceRange.baseArrayLayer = 0;
12304 img_barrier.subresourceRange.baseMipLevel = 0;
12305 img_barrier.subresourceRange.layerCount = 1;
12306 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012307 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12308 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012309 m_errorMonitor->VerifyFound();
12310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012312
12313 VkQueryPool query_pool;
12314 VkQueryPoolCreateInfo query_pool_create_info = {};
12315 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12316 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12317 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012318 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012321 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12322
12323 vkEndCommandBuffer(m_commandBuffer->handle());
12324 m_errorMonitor->VerifyFound();
12325
12326 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12327 vkDestroyEvent(m_device->device(), event, nullptr);
12328}
12329
Mark Muellerdfe37552016-07-07 14:47:42 -060012330TEST_F(VkLayerTest, VertexBufferInvalid) {
12331 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12332 "delete a buffer twice, use an invalid offset for each "
12333 "buffer type, and attempt to bind a null buffer");
12334
12335 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12336 "using deleted buffer ";
12337 const char *double_destroy_message = "Cannot free buffer 0x";
12338 const char *invalid_offset_message = "vkBindBufferMemory(): "
12339 "memoryOffset is 0x";
12340 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12341 "storage memoryOffset "
12342 "is 0x";
12343 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12344 "texel memoryOffset "
12345 "is 0x";
12346 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12347 "uniform memoryOffset "
12348 "is 0x";
12349 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12350 " to Bind Obj(0x";
12351 const char *free_invalid_buffer_message = "Request to delete memory "
12352 "object 0x";
12353
12354 ASSERT_NO_FATAL_FAILURE(InitState());
12355 ASSERT_NO_FATAL_FAILURE(InitViewport());
12356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12357
12358 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012360 pipe_ms_state_ci.pNext = NULL;
12361 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12362 pipe_ms_state_ci.sampleShadingEnable = 0;
12363 pipe_ms_state_ci.minSampleShading = 1.0;
12364 pipe_ms_state_ci.pSampleMask = nullptr;
12365
12366 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12367 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12368 VkPipelineLayout pipeline_layout;
12369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012371 ASSERT_VK_SUCCESS(err);
12372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012373 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12374 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012375 VkPipelineObj pipe(m_device);
12376 pipe.AddShader(&vs);
12377 pipe.AddShader(&fs);
12378 pipe.AddColorAttachment();
12379 pipe.SetMSAA(&pipe_ms_state_ci);
12380 pipe.SetViewport(m_viewports);
12381 pipe.SetScissor(m_scissors);
12382 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12383
12384 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012385 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012386
12387 {
12388 // Create and bind a vertex buffer in a reduced scope, which will cause
12389 // it to be deleted upon leaving this scope
12390 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012392 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12393 draw_verticies.AddVertexInputToPipe(pipe);
12394 }
12395
12396 Draw(1, 0, 0, 0);
12397
12398 EndCommandBuffer();
12399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012401 QueueCommandBuffer(false);
12402 m_errorMonitor->VerifyFound();
12403
12404 {
12405 // Create and bind a vertex buffer in a reduced scope, and delete it
12406 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012407 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012409 buffer_test.TestDoubleDestroy();
12410 }
12411 m_errorMonitor->VerifyFound();
12412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012413 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012414 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12416 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12417 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012418 m_errorMonitor->VerifyFound();
12419 }
12420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012421 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12422 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012423 // Create and bind a memory buffer with an invalid offset again,
12424 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12426 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12427 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012428 m_errorMonitor->VerifyFound();
12429 }
12430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012431 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012432 // Create and bind a memory buffer with an invalid offset again, but
12433 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12435 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12436 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012437 m_errorMonitor->VerifyFound();
12438 }
12439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012440 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012441 // Create and bind a memory buffer with an invalid offset again, but
12442 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12444 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12445 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012446 m_errorMonitor->VerifyFound();
12447 }
12448
12449 {
12450 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12452 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12453 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012454 m_errorMonitor->VerifyFound();
12455 }
12456
12457 {
12458 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12460 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12461 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012462 }
12463 m_errorMonitor->VerifyFound();
12464
12465 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12466}
12467
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012468// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12469TEST_F(VkLayerTest, InvalidImageLayout) {
12470 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012471 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12472 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012473 // 3 in ValidateCmdBufImageLayouts
12474 // * -1 Attempt to submit cmd buf w/ deleted image
12475 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12476 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12478 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012479
12480 ASSERT_NO_FATAL_FAILURE(InitState());
12481 // Create src & dst images to use for copy operations
12482 VkImage src_image;
12483 VkImage dst_image;
12484
12485 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12486 const int32_t tex_width = 32;
12487 const int32_t tex_height = 32;
12488
12489 VkImageCreateInfo image_create_info = {};
12490 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12491 image_create_info.pNext = NULL;
12492 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12493 image_create_info.format = tex_format;
12494 image_create_info.extent.width = tex_width;
12495 image_create_info.extent.height = tex_height;
12496 image_create_info.extent.depth = 1;
12497 image_create_info.mipLevels = 1;
12498 image_create_info.arrayLayers = 4;
12499 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12500 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12501 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12502 image_create_info.flags = 0;
12503
12504 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12505 ASSERT_VK_SUCCESS(err);
12506 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12507 ASSERT_VK_SUCCESS(err);
12508
12509 BeginCommandBuffer();
12510 VkImageCopy copyRegion;
12511 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12512 copyRegion.srcSubresource.mipLevel = 0;
12513 copyRegion.srcSubresource.baseArrayLayer = 0;
12514 copyRegion.srcSubresource.layerCount = 1;
12515 copyRegion.srcOffset.x = 0;
12516 copyRegion.srcOffset.y = 0;
12517 copyRegion.srcOffset.z = 0;
12518 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12519 copyRegion.dstSubresource.mipLevel = 0;
12520 copyRegion.dstSubresource.baseArrayLayer = 0;
12521 copyRegion.dstSubresource.layerCount = 1;
12522 copyRegion.dstOffset.x = 0;
12523 copyRegion.dstOffset.y = 0;
12524 copyRegion.dstOffset.z = 0;
12525 copyRegion.extent.width = 1;
12526 copyRegion.extent.height = 1;
12527 copyRegion.extent.depth = 1;
12528 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12529 m_errorMonitor->VerifyFound();
12530 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12532 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12533 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012534 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12535 m_errorMonitor->VerifyFound();
12536 // Final src error is due to bad layout type
12537 m_errorMonitor->SetDesiredFailureMsg(
12538 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12539 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12540 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12541 m_errorMonitor->VerifyFound();
12542 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12544 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012545 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12546 m_errorMonitor->VerifyFound();
12547 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12549 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12550 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012551 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12552 m_errorMonitor->VerifyFound();
12553 m_errorMonitor->SetDesiredFailureMsg(
12554 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12555 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12556 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12557 m_errorMonitor->VerifyFound();
12558 // Now cause error due to bad image layout transition in PipelineBarrier
12559 VkImageMemoryBarrier image_barrier[1] = {};
12560 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12561 image_barrier[0].image = src_image;
12562 image_barrier[0].subresourceRange.layerCount = 2;
12563 image_barrier[0].subresourceRange.levelCount = 2;
12564 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12566 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12567 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12568 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12569 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012570 m_errorMonitor->VerifyFound();
12571
12572 // Finally some layout errors at RenderPass create time
12573 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12574 VkAttachmentReference attach = {};
12575 // perf warning for GENERAL layout w/ non-DS input attachment
12576 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12577 VkSubpassDescription subpass = {};
12578 subpass.inputAttachmentCount = 1;
12579 subpass.pInputAttachments = &attach;
12580 VkRenderPassCreateInfo rpci = {};
12581 rpci.subpassCount = 1;
12582 rpci.pSubpasses = &subpass;
12583 rpci.attachmentCount = 1;
12584 VkAttachmentDescription attach_desc = {};
12585 attach_desc.format = VK_FORMAT_UNDEFINED;
12586 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012587 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012588 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12590 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012591 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12592 m_errorMonitor->VerifyFound();
12593 // error w/ non-general layout
12594 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12595
12596 m_errorMonitor->SetDesiredFailureMsg(
12597 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12598 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12599 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12600 m_errorMonitor->VerifyFound();
12601 subpass.inputAttachmentCount = 0;
12602 subpass.colorAttachmentCount = 1;
12603 subpass.pColorAttachments = &attach;
12604 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12605 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12607 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012608 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12609 m_errorMonitor->VerifyFound();
12610 // error w/ non-color opt or GENERAL layout for color attachment
12611 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12612 m_errorMonitor->SetDesiredFailureMsg(
12613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12614 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12615 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12616 m_errorMonitor->VerifyFound();
12617 subpass.colorAttachmentCount = 0;
12618 subpass.pDepthStencilAttachment = &attach;
12619 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12620 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12622 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012623 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12624 m_errorMonitor->VerifyFound();
12625 // error w/ non-ds opt or GENERAL layout for color attachment
12626 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12628 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12629 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012630 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12631 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012632 // For this error we need a valid renderpass so create default one
12633 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12634 attach.attachment = 0;
12635 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12636 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12637 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12638 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12639 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12640 // Can't do a CLEAR load on READ_ONLY initialLayout
12641 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12642 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12643 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12645 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12646 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012647 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12648 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012649
12650 vkDestroyImage(m_device->device(), src_image, NULL);
12651 vkDestroyImage(m_device->device(), dst_image, NULL);
12652}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012653
12654TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12655 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12656 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12657 "has a valid layout, and a second subpass then uses a "
12658 "valid *READ_ONLY* layout.");
12659 m_errorMonitor->ExpectSuccess();
12660 ASSERT_NO_FATAL_FAILURE(InitState());
12661
12662 VkAttachmentReference attach[2] = {};
12663 attach[0].attachment = 0;
12664 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12665 attach[1].attachment = 0;
12666 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12667 VkSubpassDescription subpasses[2] = {};
12668 // First subpass clears DS attach on load
12669 subpasses[0].pDepthStencilAttachment = &attach[0];
12670 // 2nd subpass reads in DS as input attachment
12671 subpasses[1].inputAttachmentCount = 1;
12672 subpasses[1].pInputAttachments = &attach[1];
12673 VkAttachmentDescription attach_desc = {};
12674 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12675 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12676 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12677 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12678 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12679 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012680 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012681 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12682 VkRenderPassCreateInfo rpci = {};
12683 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12684 rpci.attachmentCount = 1;
12685 rpci.pAttachments = &attach_desc;
12686 rpci.subpassCount = 2;
12687 rpci.pSubpasses = subpasses;
12688
12689 // Now create RenderPass and verify no errors
12690 VkRenderPass rp;
12691 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12692 m_errorMonitor->VerifyNotFound();
12693
12694 vkDestroyRenderPass(m_device->device(), rp, NULL);
12695}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012696
Mark Mueller93b938f2016-08-18 10:27:40 -060012697TEST_F(VkLayerTest, SimultaneousUse) {
12698 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12699 "in primary and secondary command buffers.");
12700
12701 ASSERT_NO_FATAL_FAILURE(InitState());
12702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12703
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012704 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12705 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12706 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012707
12708 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012709 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012710 command_buffer_allocate_info.commandPool = m_commandPool;
12711 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12712 command_buffer_allocate_info.commandBufferCount = 1;
12713
12714 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012715 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012716 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12717 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012718 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012719 command_buffer_inheritance_info.renderPass = m_renderPass;
12720 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12721 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012722 command_buffer_begin_info.flags =
12723 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012724 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12725
12726 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012727 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12728 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012729 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012730 vkEndCommandBuffer(secondary_command_buffer);
12731
Mark Mueller93b938f2016-08-18 10:27:40 -060012732 VkSubmitInfo submit_info = {};
12733 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12734 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012735 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012736 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012737
Mark Mueller4042b652016-09-05 22:52:21 -060012738 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012739 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12741 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012742 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012743 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12744 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012745
12746 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012747 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12748
Mark Mueller4042b652016-09-05 22:52:21 -060012749 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012750 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012751 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012752
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12754 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012755 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012756 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12757 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012758}
12759
Mark Mueller917f6bc2016-08-30 10:57:19 -060012760TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12761 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12762 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012763 "Delete objects that are inuse. Call VkQueueSubmit "
12764 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012765
12766 ASSERT_NO_FATAL_FAILURE(InitState());
12767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012769 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12770 const char *cannot_delete_event_message = "Cannot delete event 0x";
12771 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12772 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012773
12774 BeginCommandBuffer();
12775
12776 VkEvent event;
12777 VkEventCreateInfo event_create_info = {};
12778 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12779 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012780 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012781
Mark Muellerc8d441e2016-08-23 17:36:00 -060012782 EndCommandBuffer();
12783 vkDestroyEvent(m_device->device(), event, nullptr);
12784
12785 VkSubmitInfo submit_info = {};
12786 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12787 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12791 m_errorMonitor->VerifyFound();
12792
12793 m_errorMonitor->SetDesiredFailureMsg(0, "");
12794 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12795
12796 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12797
Mark Mueller917f6bc2016-08-30 10:57:19 -060012798 VkSemaphoreCreateInfo semaphore_create_info = {};
12799 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12800 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012801 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012802 VkFenceCreateInfo fence_create_info = {};
12803 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12804 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012805 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012806
12807 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012808 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012809 descriptor_pool_type_count.descriptorCount = 1;
12810
12811 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12812 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12813 descriptor_pool_create_info.maxSets = 1;
12814 descriptor_pool_create_info.poolSizeCount = 1;
12815 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012816 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012817
12818 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012819 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012820
12821 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012822 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012823 descriptorset_layout_binding.descriptorCount = 1;
12824 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12825
12826 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012827 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012828 descriptorset_layout_create_info.bindingCount = 1;
12829 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12830
12831 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012832 ASSERT_VK_SUCCESS(
12833 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012834
12835 VkDescriptorSet descriptorset;
12836 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012837 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012838 descriptorset_allocate_info.descriptorSetCount = 1;
12839 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12840 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012841 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012842
Mark Mueller4042b652016-09-05 22:52:21 -060012843 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12844
12845 VkDescriptorBufferInfo buffer_info = {};
12846 buffer_info.buffer = buffer_test.GetBuffer();
12847 buffer_info.offset = 0;
12848 buffer_info.range = 1024;
12849
12850 VkWriteDescriptorSet write_descriptor_set = {};
12851 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12852 write_descriptor_set.dstSet = descriptorset;
12853 write_descriptor_set.descriptorCount = 1;
12854 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12855 write_descriptor_set.pBufferInfo = &buffer_info;
12856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012857 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012859 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12860 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012861
12862 VkPipelineObj pipe(m_device);
12863 pipe.AddColorAttachment();
12864 pipe.AddShader(&vs);
12865 pipe.AddShader(&fs);
12866
12867 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012868 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012869 pipeline_layout_create_info.setLayoutCount = 1;
12870 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12871
12872 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012873 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012874
12875 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12876
Mark Muellerc8d441e2016-08-23 17:36:00 -060012877 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012878 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012880 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12881 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12882 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012883
Mark Muellerc8d441e2016-08-23 17:36:00 -060012884 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012885
Mark Mueller917f6bc2016-08-30 10:57:19 -060012886 submit_info.signalSemaphoreCount = 1;
12887 submit_info.pSignalSemaphores = &semaphore;
12888 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012891 vkDestroyEvent(m_device->device(), event, nullptr);
12892 m_errorMonitor->VerifyFound();
12893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012895 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12896 m_errorMonitor->VerifyFound();
12897
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012899 vkDestroyFence(m_device->device(), fence, nullptr);
12900 m_errorMonitor->VerifyFound();
12901
Tobin Ehlis122207b2016-09-01 08:50:06 -070012902 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012903 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12904 vkDestroyFence(m_device->device(), fence, nullptr);
12905 vkDestroyEvent(m_device->device(), event, nullptr);
12906 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012907 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012908 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12909}
12910
Tobin Ehlis2adda372016-09-01 08:51:06 -070012911TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12912 TEST_DESCRIPTION("Delete in-use query pool.");
12913
12914 ASSERT_NO_FATAL_FAILURE(InitState());
12915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12916
12917 VkQueryPool query_pool;
12918 VkQueryPoolCreateInfo query_pool_ci{};
12919 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12920 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12921 query_pool_ci.queryCount = 1;
12922 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12923 BeginCommandBuffer();
12924 // Reset query pool to create binding with cmd buffer
12925 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12926
12927 EndCommandBuffer();
12928
12929 VkSubmitInfo submit_info = {};
12930 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12931 submit_info.commandBufferCount = 1;
12932 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12933 // Submit cmd buffer and then destroy query pool while in-flight
12934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012937 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12938 m_errorMonitor->VerifyFound();
12939
12940 vkQueueWaitIdle(m_device->m_queue);
12941 // Now that cmd buffer done we can safely destroy query_pool
12942 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12943}
12944
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012945TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12946 TEST_DESCRIPTION("Delete in-use pipeline.");
12947
12948 ASSERT_NO_FATAL_FAILURE(InitState());
12949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12950
12951 // Empty pipeline layout used for binding PSO
12952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12954 pipeline_layout_ci.setLayoutCount = 0;
12955 pipeline_layout_ci.pSetLayouts = NULL;
12956
12957 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012959 ASSERT_VK_SUCCESS(err);
12960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012962 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12964 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012965 // Store pipeline handle so we can actually delete it before test finishes
12966 VkPipeline delete_this_pipeline;
12967 { // Scope pipeline so it will be auto-deleted
12968 VkPipelineObj pipe(m_device);
12969 pipe.AddShader(&vs);
12970 pipe.AddShader(&fs);
12971 pipe.AddColorAttachment();
12972 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12973 delete_this_pipeline = pipe.handle();
12974
12975 BeginCommandBuffer();
12976 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012978
12979 EndCommandBuffer();
12980
12981 VkSubmitInfo submit_info = {};
12982 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12983 submit_info.commandBufferCount = 1;
12984 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12985 // Submit cmd buffer and then pipeline destroyed while in-flight
12986 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12987 } // Pipeline deletion triggered here
12988 m_errorMonitor->VerifyFound();
12989 // Make sure queue finished and then actually delete pipeline
12990 vkQueueWaitIdle(m_device->m_queue);
12991 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12992 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12993}
12994
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012995TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12996 TEST_DESCRIPTION("Delete in-use imageView.");
12997
12998 ASSERT_NO_FATAL_FAILURE(InitState());
12999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13000
13001 VkDescriptorPoolSize ds_type_count;
13002 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13003 ds_type_count.descriptorCount = 1;
13004
13005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13007 ds_pool_ci.maxSets = 1;
13008 ds_pool_ci.poolSizeCount = 1;
13009 ds_pool_ci.pPoolSizes = &ds_type_count;
13010
13011 VkDescriptorPool ds_pool;
13012 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13013 ASSERT_VK_SUCCESS(err);
13014
13015 VkSamplerCreateInfo sampler_ci = {};
13016 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13017 sampler_ci.pNext = NULL;
13018 sampler_ci.magFilter = VK_FILTER_NEAREST;
13019 sampler_ci.minFilter = VK_FILTER_NEAREST;
13020 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13021 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13022 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13023 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13024 sampler_ci.mipLodBias = 1.0;
13025 sampler_ci.anisotropyEnable = VK_FALSE;
13026 sampler_ci.maxAnisotropy = 1;
13027 sampler_ci.compareEnable = VK_FALSE;
13028 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13029 sampler_ci.minLod = 1.0;
13030 sampler_ci.maxLod = 1.0;
13031 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13032 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13033 VkSampler sampler;
13034
13035 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13036 ASSERT_VK_SUCCESS(err);
13037
13038 VkDescriptorSetLayoutBinding layout_binding;
13039 layout_binding.binding = 0;
13040 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13041 layout_binding.descriptorCount = 1;
13042 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13043 layout_binding.pImmutableSamplers = NULL;
13044
13045 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13046 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13047 ds_layout_ci.bindingCount = 1;
13048 ds_layout_ci.pBindings = &layout_binding;
13049 VkDescriptorSetLayout ds_layout;
13050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13051 ASSERT_VK_SUCCESS(err);
13052
13053 VkDescriptorSetAllocateInfo alloc_info = {};
13054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13055 alloc_info.descriptorSetCount = 1;
13056 alloc_info.descriptorPool = ds_pool;
13057 alloc_info.pSetLayouts = &ds_layout;
13058 VkDescriptorSet descriptor_set;
13059 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13060 ASSERT_VK_SUCCESS(err);
13061
13062 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13063 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13064 pipeline_layout_ci.pNext = NULL;
13065 pipeline_layout_ci.setLayoutCount = 1;
13066 pipeline_layout_ci.pSetLayouts = &ds_layout;
13067
13068 VkPipelineLayout pipeline_layout;
13069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13070 ASSERT_VK_SUCCESS(err);
13071
13072 VkImageObj image(m_device);
13073 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
13074 ASSERT_TRUE(image.initialized());
13075
13076 VkImageView view;
13077 VkImageViewCreateInfo ivci = {};
13078 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13079 ivci.image = image.handle();
13080 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13081 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13082 ivci.subresourceRange.layerCount = 1;
13083 ivci.subresourceRange.baseMipLevel = 0;
13084 ivci.subresourceRange.levelCount = 1;
13085 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13086
13087 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13088 ASSERT_VK_SUCCESS(err);
13089
13090 VkDescriptorImageInfo image_info{};
13091 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13092 image_info.imageView = view;
13093 image_info.sampler = sampler;
13094
13095 VkWriteDescriptorSet descriptor_write = {};
13096 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13097 descriptor_write.dstSet = descriptor_set;
13098 descriptor_write.dstBinding = 0;
13099 descriptor_write.descriptorCount = 1;
13100 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13101 descriptor_write.pImageInfo = &image_info;
13102
13103 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13104
13105 // Create PSO to use the sampler
13106 char const *vsSource = "#version 450\n"
13107 "\n"
13108 "out gl_PerVertex { \n"
13109 " vec4 gl_Position;\n"
13110 "};\n"
13111 "void main(){\n"
13112 " gl_Position = vec4(1);\n"
13113 "}\n";
13114 char const *fsSource = "#version 450\n"
13115 "\n"
13116 "layout(set=0, binding=0) uniform sampler2D s;\n"
13117 "layout(location=0) out vec4 x;\n"
13118 "void main(){\n"
13119 " x = texture(s, vec2(1));\n"
13120 "}\n";
13121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13123 VkPipelineObj pipe(m_device);
13124 pipe.AddShader(&vs);
13125 pipe.AddShader(&fs);
13126 pipe.AddColorAttachment();
13127 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13128
13129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
13130
13131 BeginCommandBuffer();
13132 // Bind pipeline to cmd buffer
13133 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13134 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13135 &descriptor_set, 0, nullptr);
13136 Draw(1, 0, 0, 0);
13137 EndCommandBuffer();
13138 // Submit cmd buffer then destroy sampler
13139 VkSubmitInfo submit_info = {};
13140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13141 submit_info.commandBufferCount = 1;
13142 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13143 // Submit cmd buffer and then destroy imageView while in-flight
13144 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13145
13146 vkDestroyImageView(m_device->device(), view, nullptr);
13147 m_errorMonitor->VerifyFound();
13148 vkQueueWaitIdle(m_device->m_queue);
13149 // Now we can actually destroy imageView
13150 vkDestroyImageView(m_device->device(), view, NULL);
13151 vkDestroySampler(m_device->device(), sampler, nullptr);
13152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13155}
13156
Tobin Ehlis209532e2016-09-07 13:52:18 -060013157TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13158 TEST_DESCRIPTION("Delete in-use sampler.");
13159
13160 ASSERT_NO_FATAL_FAILURE(InitState());
13161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13162
13163 VkDescriptorPoolSize ds_type_count;
13164 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13165 ds_type_count.descriptorCount = 1;
13166
13167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13169 ds_pool_ci.maxSets = 1;
13170 ds_pool_ci.poolSizeCount = 1;
13171 ds_pool_ci.pPoolSizes = &ds_type_count;
13172
13173 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013174 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013175 ASSERT_VK_SUCCESS(err);
13176
13177 VkSamplerCreateInfo sampler_ci = {};
13178 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13179 sampler_ci.pNext = NULL;
13180 sampler_ci.magFilter = VK_FILTER_NEAREST;
13181 sampler_ci.minFilter = VK_FILTER_NEAREST;
13182 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13183 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13184 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13185 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13186 sampler_ci.mipLodBias = 1.0;
13187 sampler_ci.anisotropyEnable = VK_FALSE;
13188 sampler_ci.maxAnisotropy = 1;
13189 sampler_ci.compareEnable = VK_FALSE;
13190 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13191 sampler_ci.minLod = 1.0;
13192 sampler_ci.maxLod = 1.0;
13193 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13194 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13195 VkSampler sampler;
13196
13197 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13198 ASSERT_VK_SUCCESS(err);
13199
13200 VkDescriptorSetLayoutBinding layout_binding;
13201 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013202 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013203 layout_binding.descriptorCount = 1;
13204 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13205 layout_binding.pImmutableSamplers = NULL;
13206
13207 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13208 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13209 ds_layout_ci.bindingCount = 1;
13210 ds_layout_ci.pBindings = &layout_binding;
13211 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013212 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013213 ASSERT_VK_SUCCESS(err);
13214
13215 VkDescriptorSetAllocateInfo alloc_info = {};
13216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13217 alloc_info.descriptorSetCount = 1;
13218 alloc_info.descriptorPool = ds_pool;
13219 alloc_info.pSetLayouts = &ds_layout;
13220 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013221 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013222 ASSERT_VK_SUCCESS(err);
13223
13224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13226 pipeline_layout_ci.pNext = NULL;
13227 pipeline_layout_ci.setLayoutCount = 1;
13228 pipeline_layout_ci.pSetLayouts = &ds_layout;
13229
13230 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013232 ASSERT_VK_SUCCESS(err);
13233
13234 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013235 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 -060013236 ASSERT_TRUE(image.initialized());
13237
13238 VkImageView view;
13239 VkImageViewCreateInfo ivci = {};
13240 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13241 ivci.image = image.handle();
13242 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13243 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13244 ivci.subresourceRange.layerCount = 1;
13245 ivci.subresourceRange.baseMipLevel = 0;
13246 ivci.subresourceRange.levelCount = 1;
13247 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13248
13249 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13250 ASSERT_VK_SUCCESS(err);
13251
13252 VkDescriptorImageInfo image_info{};
13253 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13254 image_info.imageView = view;
13255 image_info.sampler = sampler;
13256
13257 VkWriteDescriptorSet descriptor_write = {};
13258 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13259 descriptor_write.dstSet = descriptor_set;
13260 descriptor_write.dstBinding = 0;
13261 descriptor_write.descriptorCount = 1;
13262 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13263 descriptor_write.pImageInfo = &image_info;
13264
13265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13266
13267 // Create PSO to use the sampler
13268 char const *vsSource = "#version 450\n"
13269 "\n"
13270 "out gl_PerVertex { \n"
13271 " vec4 gl_Position;\n"
13272 "};\n"
13273 "void main(){\n"
13274 " gl_Position = vec4(1);\n"
13275 "}\n";
13276 char const *fsSource = "#version 450\n"
13277 "\n"
13278 "layout(set=0, binding=0) uniform sampler2D s;\n"
13279 "layout(location=0) out vec4 x;\n"
13280 "void main(){\n"
13281 " x = texture(s, vec2(1));\n"
13282 "}\n";
13283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13285 VkPipelineObj pipe(m_device);
13286 pipe.AddShader(&vs);
13287 pipe.AddShader(&fs);
13288 pipe.AddColorAttachment();
13289 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060013292
13293 BeginCommandBuffer();
13294 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013295 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13296 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13297 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013298 Draw(1, 0, 0, 0);
13299 EndCommandBuffer();
13300 // Submit cmd buffer then destroy sampler
13301 VkSubmitInfo submit_info = {};
13302 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13303 submit_info.commandBufferCount = 1;
13304 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13305 // Submit cmd buffer and then destroy sampler while in-flight
13306 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13307
13308 vkDestroySampler(m_device->device(), sampler, nullptr);
13309 m_errorMonitor->VerifyFound();
13310 vkQueueWaitIdle(m_device->m_queue);
13311 // Now we can actually destroy sampler
13312 vkDestroySampler(m_device->device(), sampler, nullptr);
13313 vkDestroyImageView(m_device->device(), view, NULL);
13314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13315 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13317}
13318
Mark Mueller1cd9f412016-08-25 13:23:52 -060013319TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060013320 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060013321 "signaled but not waited on by the queue. Wait on a "
13322 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013323
13324 ASSERT_NO_FATAL_FAILURE(InitState());
13325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013327 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
13328 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
13329 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013330
13331 BeginCommandBuffer();
13332 EndCommandBuffer();
13333
13334 VkSemaphoreCreateInfo semaphore_create_info = {};
13335 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13336 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013337 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013338 VkSubmitInfo submit_info = {};
13339 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13340 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013341 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013342 submit_info.signalSemaphoreCount = 1;
13343 submit_info.pSignalSemaphores = &semaphore;
13344 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13345 m_errorMonitor->SetDesiredFailureMsg(0, "");
13346 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
13347 BeginCommandBuffer();
13348 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013350 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13351 m_errorMonitor->VerifyFound();
13352
Mark Mueller1cd9f412016-08-25 13:23:52 -060013353 VkFenceCreateInfo fence_create_info = {};
13354 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13355 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013356 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013359 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13360 m_errorMonitor->VerifyFound();
13361
Mark Mueller4042b652016-09-05 22:52:21 -060013362 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013363 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013364 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13365}
13366
Tobin Ehlis4af23302016-07-19 10:50:30 -060013367TEST_F(VkLayerTest, FramebufferIncompatible) {
13368 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
13369 "that does not match the framebuffer for the active "
13370 "renderpass.");
13371 ASSERT_NO_FATAL_FAILURE(InitState());
13372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13373
13374 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013375 VkAttachmentDescription attachment = {0,
13376 VK_FORMAT_B8G8R8A8_UNORM,
13377 VK_SAMPLE_COUNT_1_BIT,
13378 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13379 VK_ATTACHMENT_STORE_OP_STORE,
13380 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13381 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13382 VK_IMAGE_LAYOUT_UNDEFINED,
13383 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013385 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013387 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013389 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013390
13391 VkRenderPass rp;
13392 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13393 ASSERT_VK_SUCCESS(err);
13394
13395 // A compatible framebuffer.
13396 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013397 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 -060013398 ASSERT_TRUE(image.initialized());
13399
13400 VkImageViewCreateInfo ivci = {
13401 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13402 nullptr,
13403 0,
13404 image.handle(),
13405 VK_IMAGE_VIEW_TYPE_2D,
13406 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013407 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13408 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013409 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13410 };
13411 VkImageView view;
13412 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13413 ASSERT_VK_SUCCESS(err);
13414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013415 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013416 VkFramebuffer fb;
13417 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13418 ASSERT_VK_SUCCESS(err);
13419
13420 VkCommandBufferAllocateInfo cbai = {};
13421 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13422 cbai.commandPool = m_commandPool;
13423 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13424 cbai.commandBufferCount = 1;
13425
13426 VkCommandBuffer sec_cb;
13427 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13428 ASSERT_VK_SUCCESS(err);
13429 VkCommandBufferBeginInfo cbbi = {};
13430 VkCommandBufferInheritanceInfo cbii = {};
13431 cbii.renderPass = renderPass();
13432 cbii.framebuffer = fb;
13433 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13434 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013435 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 -060013436 cbbi.pInheritanceInfo = &cbii;
13437 vkBeginCommandBuffer(sec_cb, &cbbi);
13438 vkEndCommandBuffer(sec_cb);
13439
Chris Forbes3400bc52016-09-13 18:10:34 +120013440 VkCommandBufferBeginInfo cbbi2 = {
13441 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13442 0, nullptr
13443 };
13444 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13445 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13448 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013449 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13450 m_errorMonitor->VerifyFound();
13451 // Cleanup
13452 vkDestroyImageView(m_device->device(), view, NULL);
13453 vkDestroyRenderPass(m_device->device(), rp, NULL);
13454 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13455}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013456
13457TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13458 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13459 "invalid value. If logicOp is not available, attempt to "
13460 "use it and verify that we see the correct error.");
13461 ASSERT_NO_FATAL_FAILURE(InitState());
13462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13463
13464 auto features = m_device->phy().features();
13465 // Set the expected error depending on whether or not logicOp available
13466 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13468 "enabled, logicOpEnable must be "
13469 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013470 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013472 }
13473 // Create a pipeline using logicOp
13474 VkResult err;
13475
13476 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13477 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13478
13479 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013480 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013481 ASSERT_VK_SUCCESS(err);
13482
13483 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13484 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13485 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013486 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013487 vp_state_ci.pViewports = &vp;
13488 vp_state_ci.scissorCount = 1;
13489 VkRect2D scissors = {}; // Dummy scissors to point to
13490 vp_state_ci.pScissors = &scissors;
13491 // No dynamic state
13492 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13493 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13494
13495 VkPipelineShaderStageCreateInfo shaderStages[2];
13496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013500 shaderStages[0] = vs.GetStageCreateInfo();
13501 shaderStages[1] = fs.GetStageCreateInfo();
13502
13503 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13504 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13505
13506 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13507 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13508 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13509
13510 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13511 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13512
13513 VkPipelineColorBlendAttachmentState att = {};
13514 att.blendEnable = VK_FALSE;
13515 att.colorWriteMask = 0xf;
13516
13517 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13518 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13519 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13520 cb_ci.logicOpEnable = VK_TRUE;
13521 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13522 cb_ci.attachmentCount = 1;
13523 cb_ci.pAttachments = &att;
13524
13525 VkGraphicsPipelineCreateInfo gp_ci = {};
13526 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13527 gp_ci.stageCount = 2;
13528 gp_ci.pStages = shaderStages;
13529 gp_ci.pVertexInputState = &vi_ci;
13530 gp_ci.pInputAssemblyState = &ia_ci;
13531 gp_ci.pViewportState = &vp_state_ci;
13532 gp_ci.pRasterizationState = &rs_ci;
13533 gp_ci.pColorBlendState = &cb_ci;
13534 gp_ci.pDynamicState = &dyn_state_ci;
13535 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13536 gp_ci.layout = pipeline_layout;
13537 gp_ci.renderPass = renderPass();
13538
13539 VkPipelineCacheCreateInfo pc_ci = {};
13540 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13541
13542 VkPipeline pipeline;
13543 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013544 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013545 ASSERT_VK_SUCCESS(err);
13546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013547 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013548 m_errorMonitor->VerifyFound();
13549 if (VK_SUCCESS == err) {
13550 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13551 }
13552 m_errorMonitor->VerifyFound();
13553 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13554 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13555}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013556#endif // DRAW_STATE_TESTS
13557
Tobin Ehlis0788f522015-05-26 16:11:58 -060013558#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013559#if GTEST_IS_THREADSAFE
13560struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013561 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013562 VkEvent event;
13563 bool bailout;
13564};
13565
Karl Schultz6addd812016-02-02 17:17:23 -070013566extern "C" void *AddToCommandBuffer(void *arg) {
13567 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013568
Mike Stroyana6d14942016-07-13 15:10:05 -060013569 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013570 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013571 if (data->bailout) {
13572 break;
13573 }
13574 }
13575 return NULL;
13576}
13577
Karl Schultz6addd812016-02-02 17:17:23 -070013578TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013579 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013582
Mike Stroyanaccf7692015-05-12 16:00:45 -060013583 ASSERT_NO_FATAL_FAILURE(InitState());
13584 ASSERT_NO_FATAL_FAILURE(InitViewport());
13585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13586
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013587 // Calls AllocateCommandBuffers
13588 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013589
13590 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013591 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013592
13593 VkEventCreateInfo event_info;
13594 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013595 VkResult err;
13596
13597 memset(&event_info, 0, sizeof(event_info));
13598 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13599
Chia-I Wuf7458c52015-10-26 21:10:41 +080013600 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013601 ASSERT_VK_SUCCESS(err);
13602
Mike Stroyanaccf7692015-05-12 16:00:45 -060013603 err = vkResetEvent(device(), event);
13604 ASSERT_VK_SUCCESS(err);
13605
13606 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013607 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013608 data.event = event;
13609 data.bailout = false;
13610 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013611
13612 // First do some correct operations using multiple threads.
13613 // Add many entries to command buffer from another thread.
13614 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13615 // Make non-conflicting calls from this thread at the same time.
13616 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013617 uint32_t count;
13618 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013619 }
13620 test_platform_thread_join(thread, NULL);
13621
13622 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013623 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013624 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013625 // Add many entries to command buffer from this thread at the same time.
13626 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013627
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013628 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013629 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013630
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013631 m_errorMonitor->SetBailout(NULL);
13632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013633 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013634
Chia-I Wuf7458c52015-10-26 21:10:41 +080013635 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013636}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013637#endif // GTEST_IS_THREADSAFE
13638#endif // THREADING_TESTS
13639
Chris Forbes9f7ff632015-05-25 11:13:08 +120013640#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013641TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013642 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13643 "with an impossible code size");
13644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013646
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013647 ASSERT_NO_FATAL_FAILURE(InitState());
13648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13649
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013650 VkShaderModule module;
13651 VkShaderModuleCreateInfo moduleCreateInfo;
13652 struct icd_spv_header spv;
13653
13654 spv.magic = ICD_SPV_MAGIC;
13655 spv.version = ICD_SPV_VERSION;
13656 spv.gen_magic = 0;
13657
13658 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13659 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013660 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013661 moduleCreateInfo.codeSize = 4;
13662 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013663 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013665 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013666}
13667
Karl Schultz6addd812016-02-02 17:17:23 -070013668TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013669 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13670 "with a bad magic number");
13671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013673
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013674 ASSERT_NO_FATAL_FAILURE(InitState());
13675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13676
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013677 VkShaderModule module;
13678 VkShaderModuleCreateInfo moduleCreateInfo;
13679 struct icd_spv_header spv;
13680
13681 spv.magic = ~ICD_SPV_MAGIC;
13682 spv.version = ICD_SPV_VERSION;
13683 spv.gen_magic = 0;
13684
13685 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13686 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013687 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013688 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13689 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013690 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013691
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013692 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013693}
13694
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013695#if 0
13696// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013697TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013699 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013700
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013701 ASSERT_NO_FATAL_FAILURE(InitState());
13702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13703
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013704 VkShaderModule module;
13705 VkShaderModuleCreateInfo moduleCreateInfo;
13706 struct icd_spv_header spv;
13707
13708 spv.magic = ICD_SPV_MAGIC;
13709 spv.version = ~ICD_SPV_VERSION;
13710 spv.gen_magic = 0;
13711
13712 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13713 moduleCreateInfo.pNext = NULL;
13714
Karl Schultz6addd812016-02-02 17:17:23 -070013715 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013716 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13717 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013718 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013719
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013720 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013721}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013722#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013723
Karl Schultz6addd812016-02-02 17:17:23 -070013724TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013725 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13726 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013728
Chris Forbes9f7ff632015-05-25 11:13:08 +120013729 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013732 char const *vsSource = "#version 450\n"
13733 "\n"
13734 "layout(location=0) out float x;\n"
13735 "out gl_PerVertex {\n"
13736 " vec4 gl_Position;\n"
13737 "};\n"
13738 "void main(){\n"
13739 " gl_Position = vec4(1);\n"
13740 " x = 0;\n"
13741 "}\n";
13742 char const *fsSource = "#version 450\n"
13743 "\n"
13744 "layout(location=0) out vec4 color;\n"
13745 "void main(){\n"
13746 " color = vec4(1);\n"
13747 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013748
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013749 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13750 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013751
13752 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013753 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013754 pipe.AddShader(&vs);
13755 pipe.AddShader(&fs);
13756
Chris Forbes9f7ff632015-05-25 11:13:08 +120013757 VkDescriptorSetObj descriptorSet(m_device);
13758 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013759 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013760
Tony Barbour5781e8f2015-08-04 16:23:11 -060013761 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013762
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013763 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013764}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013765
Karl Schultz6addd812016-02-02 17:17:23 -070013766TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013767 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13768 "which is not present in the outputs of the previous stage");
13769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013771
Chris Forbes59cb88d2015-05-25 11:13:13 +120013772 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013774
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013775 char const *vsSource = "#version 450\n"
13776 "\n"
13777 "out gl_PerVertex {\n"
13778 " vec4 gl_Position;\n"
13779 "};\n"
13780 "void main(){\n"
13781 " gl_Position = vec4(1);\n"
13782 "}\n";
13783 char const *fsSource = "#version 450\n"
13784 "\n"
13785 "layout(location=0) in float x;\n"
13786 "layout(location=0) out vec4 color;\n"
13787 "void main(){\n"
13788 " color = vec4(x);\n"
13789 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013790
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013791 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13792 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013793
13794 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013795 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013796 pipe.AddShader(&vs);
13797 pipe.AddShader(&fs);
13798
Chris Forbes59cb88d2015-05-25 11:13:13 +120013799 VkDescriptorSetObj descriptorSet(m_device);
13800 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013801 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013802
Tony Barbour5781e8f2015-08-04 16:23:11 -060013803 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013804
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013805 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013806}
13807
Karl Schultz6addd812016-02-02 17:17:23 -070013808TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013809 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13810 "within an interace block, which is not present in the outputs "
13811 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013813
13814 ASSERT_NO_FATAL_FAILURE(InitState());
13815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013817 char const *vsSource = "#version 450\n"
13818 "\n"
13819 "out gl_PerVertex {\n"
13820 " vec4 gl_Position;\n"
13821 "};\n"
13822 "void main(){\n"
13823 " gl_Position = vec4(1);\n"
13824 "}\n";
13825 char const *fsSource = "#version 450\n"
13826 "\n"
13827 "in block { layout(location=0) float x; } ins;\n"
13828 "layout(location=0) out vec4 color;\n"
13829 "void main(){\n"
13830 " color = vec4(ins.x);\n"
13831 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013832
13833 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13834 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13835
13836 VkPipelineObj pipe(m_device);
13837 pipe.AddColorAttachment();
13838 pipe.AddShader(&vs);
13839 pipe.AddShader(&fs);
13840
13841 VkDescriptorSetObj descriptorSet(m_device);
13842 descriptorSet.AppendDummy();
13843 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13844
13845 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13846
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013847 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013848}
13849
Karl Schultz6addd812016-02-02 17:17:23 -070013850TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013851 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13852 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13854 "output arr[2] of float32' vs 'ptr to "
13855 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013856
13857 ASSERT_NO_FATAL_FAILURE(InitState());
13858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013860 char const *vsSource = "#version 450\n"
13861 "\n"
13862 "layout(location=0) out float x[2];\n"
13863 "out gl_PerVertex {\n"
13864 " vec4 gl_Position;\n"
13865 "};\n"
13866 "void main(){\n"
13867 " x[0] = 0; x[1] = 0;\n"
13868 " gl_Position = vec4(1);\n"
13869 "}\n";
13870 char const *fsSource = "#version 450\n"
13871 "\n"
13872 "layout(location=0) in float x[3];\n"
13873 "layout(location=0) out vec4 color;\n"
13874 "void main(){\n"
13875 " color = vec4(x[0] + x[1] + x[2]);\n"
13876 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013877
13878 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13879 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13880
13881 VkPipelineObj pipe(m_device);
13882 pipe.AddColorAttachment();
13883 pipe.AddShader(&vs);
13884 pipe.AddShader(&fs);
13885
13886 VkDescriptorSetObj descriptorSet(m_device);
13887 descriptorSet.AppendDummy();
13888 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13889
13890 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13891
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013892 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013893}
13894
Karl Schultz6addd812016-02-02 17:17:23 -070013895TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013896 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13897 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013899
Chris Forbesb56af562015-05-25 11:13:17 +120013900 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013903 char const *vsSource = "#version 450\n"
13904 "\n"
13905 "layout(location=0) out int x;\n"
13906 "out gl_PerVertex {\n"
13907 " vec4 gl_Position;\n"
13908 "};\n"
13909 "void main(){\n"
13910 " x = 0;\n"
13911 " gl_Position = vec4(1);\n"
13912 "}\n";
13913 char const *fsSource = "#version 450\n"
13914 "\n"
13915 "layout(location=0) in float x;\n" /* VS writes int */
13916 "layout(location=0) out vec4 color;\n"
13917 "void main(){\n"
13918 " color = vec4(x);\n"
13919 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013920
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013921 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13922 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013923
13924 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013925 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013926 pipe.AddShader(&vs);
13927 pipe.AddShader(&fs);
13928
Chris Forbesb56af562015-05-25 11:13:17 +120013929 VkDescriptorSetObj descriptorSet(m_device);
13930 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013931 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013932
Tony Barbour5781e8f2015-08-04 16:23:11 -060013933 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013934
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013935 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013936}
13937
Karl Schultz6addd812016-02-02 17:17:23 -070013938TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013939 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13940 "the VS->FS interface, when the variable is contained within "
13941 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013943
13944 ASSERT_NO_FATAL_FAILURE(InitState());
13945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013947 char const *vsSource = "#version 450\n"
13948 "\n"
13949 "out block { layout(location=0) int x; } outs;\n"
13950 "out gl_PerVertex {\n"
13951 " vec4 gl_Position;\n"
13952 "};\n"
13953 "void main(){\n"
13954 " outs.x = 0;\n"
13955 " gl_Position = vec4(1);\n"
13956 "}\n";
13957 char const *fsSource = "#version 450\n"
13958 "\n"
13959 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13960 "layout(location=0) out vec4 color;\n"
13961 "void main(){\n"
13962 " color = vec4(ins.x);\n"
13963 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013964
13965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13967
13968 VkPipelineObj pipe(m_device);
13969 pipe.AddColorAttachment();
13970 pipe.AddShader(&vs);
13971 pipe.AddShader(&fs);
13972
13973 VkDescriptorSetObj descriptorSet(m_device);
13974 descriptorSet.AppendDummy();
13975 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13976
13977 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13978
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013979 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013980}
13981
13982TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013983 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13984 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13985 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013986 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 +130013987
13988 ASSERT_NO_FATAL_FAILURE(InitState());
13989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 char const *vsSource = "#version 450\n"
13992 "\n"
13993 "out block { layout(location=1) float x; } outs;\n"
13994 "out gl_PerVertex {\n"
13995 " vec4 gl_Position;\n"
13996 "};\n"
13997 "void main(){\n"
13998 " outs.x = 0;\n"
13999 " gl_Position = vec4(1);\n"
14000 "}\n";
14001 char const *fsSource = "#version 450\n"
14002 "\n"
14003 "in block { layout(location=0) float x; } ins;\n"
14004 "layout(location=0) out vec4 color;\n"
14005 "void main(){\n"
14006 " color = vec4(ins.x);\n"
14007 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014008
14009 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14010 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14011
14012 VkPipelineObj pipe(m_device);
14013 pipe.AddColorAttachment();
14014 pipe.AddShader(&vs);
14015 pipe.AddShader(&fs);
14016
14017 VkDescriptorSetObj descriptorSet(m_device);
14018 descriptorSet.AppendDummy();
14019 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14020
14021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014023 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014024}
14025
14026TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014027 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
14028 "VS->FS interface. It's not enough to have the same set of locations in "
14029 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 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 +130014031
14032 ASSERT_NO_FATAL_FAILURE(InitState());
14033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014035 char const *vsSource = "#version 450\n"
14036 "\n"
14037 "out block { layout(location=0, component=0) float x; } outs;\n"
14038 "out gl_PerVertex {\n"
14039 " vec4 gl_Position;\n"
14040 "};\n"
14041 "void main(){\n"
14042 " outs.x = 0;\n"
14043 " gl_Position = vec4(1);\n"
14044 "}\n";
14045 char const *fsSource = "#version 450\n"
14046 "\n"
14047 "in block { layout(location=0, component=1) float x; } ins;\n"
14048 "layout(location=0) out vec4 color;\n"
14049 "void main(){\n"
14050 " color = vec4(ins.x);\n"
14051 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014052
14053 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14054 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14055
14056 VkPipelineObj pipe(m_device);
14057 pipe.AddColorAttachment();
14058 pipe.AddShader(&vs);
14059 pipe.AddShader(&fs);
14060
14061 VkDescriptorSetObj descriptorSet(m_device);
14062 descriptorSet.AppendDummy();
14063 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14064
14065 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14066
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014067 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014068}
14069
Karl Schultz6addd812016-02-02 17:17:23 -070014070TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014071 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
14072 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014074
Chris Forbesde136e02015-05-25 11:13:28 +120014075 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014077
14078 VkVertexInputBindingDescription input_binding;
14079 memset(&input_binding, 0, sizeof(input_binding));
14080
14081 VkVertexInputAttributeDescription input_attrib;
14082 memset(&input_attrib, 0, sizeof(input_attrib));
14083 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014085 char const *vsSource = "#version 450\n"
14086 "\n"
14087 "out gl_PerVertex {\n"
14088 " vec4 gl_Position;\n"
14089 "};\n"
14090 "void main(){\n"
14091 " gl_Position = vec4(1);\n"
14092 "}\n";
14093 char const *fsSource = "#version 450\n"
14094 "\n"
14095 "layout(location=0) out vec4 color;\n"
14096 "void main(){\n"
14097 " color = vec4(1);\n"
14098 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014099
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014100 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14101 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014102
14103 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014104 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014105 pipe.AddShader(&vs);
14106 pipe.AddShader(&fs);
14107
14108 pipe.AddVertexInputBindings(&input_binding, 1);
14109 pipe.AddVertexInputAttribs(&input_attrib, 1);
14110
Chris Forbesde136e02015-05-25 11:13:28 +120014111 VkDescriptorSetObj descriptorSet(m_device);
14112 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014114
Tony Barbour5781e8f2015-08-04 16:23:11 -060014115 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014116
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014117 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014118}
14119
Karl Schultz6addd812016-02-02 17:17:23 -070014120TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014121 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
14122 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014124
14125 ASSERT_NO_FATAL_FAILURE(InitState());
14126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14127
14128 VkVertexInputBindingDescription input_binding;
14129 memset(&input_binding, 0, sizeof(input_binding));
14130
14131 VkVertexInputAttributeDescription input_attrib;
14132 memset(&input_attrib, 0, sizeof(input_attrib));
14133 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014135 char const *vsSource = "#version 450\n"
14136 "\n"
14137 "layout(location=1) in float x;\n"
14138 "out gl_PerVertex {\n"
14139 " vec4 gl_Position;\n"
14140 "};\n"
14141 "void main(){\n"
14142 " gl_Position = vec4(x);\n"
14143 "}\n";
14144 char const *fsSource = "#version 450\n"
14145 "\n"
14146 "layout(location=0) out vec4 color;\n"
14147 "void main(){\n"
14148 " color = vec4(1);\n"
14149 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014150
14151 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14152 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14153
14154 VkPipelineObj pipe(m_device);
14155 pipe.AddColorAttachment();
14156 pipe.AddShader(&vs);
14157 pipe.AddShader(&fs);
14158
14159 pipe.AddVertexInputBindings(&input_binding, 1);
14160 pipe.AddVertexInputAttribs(&input_attrib, 1);
14161
14162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
14164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14165
14166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014168 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014169}
14170
Karl Schultz6addd812016-02-02 17:17:23 -070014171TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014172 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
14173 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014174 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 -060014175
Chris Forbes62e8e502015-05-25 11:13:29 +120014176 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014179 char const *vsSource = "#version 450\n"
14180 "\n"
14181 "layout(location=0) in vec4 x;\n" /* not provided */
14182 "out gl_PerVertex {\n"
14183 " vec4 gl_Position;\n"
14184 "};\n"
14185 "void main(){\n"
14186 " gl_Position = x;\n"
14187 "}\n";
14188 char const *fsSource = "#version 450\n"
14189 "\n"
14190 "layout(location=0) out vec4 color;\n"
14191 "void main(){\n"
14192 " color = vec4(1);\n"
14193 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014194
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014195 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14196 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014197
14198 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014199 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014200 pipe.AddShader(&vs);
14201 pipe.AddShader(&fs);
14202
Chris Forbes62e8e502015-05-25 11:13:29 +120014203 VkDescriptorSetObj descriptorSet(m_device);
14204 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014205 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014206
Tony Barbour5781e8f2015-08-04 16:23:11 -060014207 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014208
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014209 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014210}
14211
Karl Schultz6addd812016-02-02 17:17:23 -070014212TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014213 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
14214 "fundamental type (float/int/uint) of an attribute and the "
14215 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014217
Chris Forbesc97d98e2015-05-25 11:13:31 +120014218 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014219 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014220
14221 VkVertexInputBindingDescription input_binding;
14222 memset(&input_binding, 0, sizeof(input_binding));
14223
14224 VkVertexInputAttributeDescription input_attrib;
14225 memset(&input_attrib, 0, sizeof(input_attrib));
14226 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 char const *vsSource = "#version 450\n"
14229 "\n"
14230 "layout(location=0) in int x;\n" /* attrib provided float */
14231 "out gl_PerVertex {\n"
14232 " vec4 gl_Position;\n"
14233 "};\n"
14234 "void main(){\n"
14235 " gl_Position = vec4(x);\n"
14236 "}\n";
14237 char const *fsSource = "#version 450\n"
14238 "\n"
14239 "layout(location=0) out vec4 color;\n"
14240 "void main(){\n"
14241 " color = vec4(1);\n"
14242 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014243
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014246
14247 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014248 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014249 pipe.AddShader(&vs);
14250 pipe.AddShader(&fs);
14251
14252 pipe.AddVertexInputBindings(&input_binding, 1);
14253 pipe.AddVertexInputAttribs(&input_attrib, 1);
14254
Chris Forbesc97d98e2015-05-25 11:13:31 +120014255 VkDescriptorSetObj descriptorSet(m_device);
14256 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014257 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014258
Tony Barbour5781e8f2015-08-04 16:23:11 -060014259 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014260
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014261 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014262}
14263
Chris Forbesc68b43c2016-04-06 11:18:47 +120014264TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014265 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
14266 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14268 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014269
14270 ASSERT_NO_FATAL_FAILURE(InitState());
14271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014273 char const *vsSource = "#version 450\n"
14274 "\n"
14275 "out gl_PerVertex {\n"
14276 " vec4 gl_Position;\n"
14277 "};\n"
14278 "void main(){\n"
14279 " gl_Position = vec4(1);\n"
14280 "}\n";
14281 char const *fsSource = "#version 450\n"
14282 "\n"
14283 "layout(location=0) out vec4 color;\n"
14284 "void main(){\n"
14285 " color = vec4(1);\n"
14286 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014287
14288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14290
14291 VkPipelineObj pipe(m_device);
14292 pipe.AddColorAttachment();
14293 pipe.AddShader(&vs);
14294 pipe.AddShader(&vs);
14295 pipe.AddShader(&fs);
14296
14297 VkDescriptorSetObj descriptorSet(m_device);
14298 descriptorSet.AppendDummy();
14299 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14300
14301 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14302
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014303 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014304}
14305
Karl Schultz6addd812016-02-02 17:17:23 -070014306TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014307 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
14308 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014309 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014310
14311 ASSERT_NO_FATAL_FAILURE(InitState());
14312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14313
14314 VkVertexInputBindingDescription input_binding;
14315 memset(&input_binding, 0, sizeof(input_binding));
14316
14317 VkVertexInputAttributeDescription input_attribs[2];
14318 memset(input_attribs, 0, sizeof(input_attribs));
14319
14320 for (int i = 0; i < 2; i++) {
14321 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14322 input_attribs[i].location = i;
14323 }
14324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014325 char const *vsSource = "#version 450\n"
14326 "\n"
14327 "layout(location=0) in mat2x4 x;\n"
14328 "out gl_PerVertex {\n"
14329 " vec4 gl_Position;\n"
14330 "};\n"
14331 "void main(){\n"
14332 " gl_Position = x[0] + x[1];\n"
14333 "}\n";
14334 char const *fsSource = "#version 450\n"
14335 "\n"
14336 "layout(location=0) out vec4 color;\n"
14337 "void main(){\n"
14338 " color = vec4(1);\n"
14339 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014340
14341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14343
14344 VkPipelineObj pipe(m_device);
14345 pipe.AddColorAttachment();
14346 pipe.AddShader(&vs);
14347 pipe.AddShader(&fs);
14348
14349 pipe.AddVertexInputBindings(&input_binding, 1);
14350 pipe.AddVertexInputAttribs(input_attribs, 2);
14351
14352 VkDescriptorSetObj descriptorSet(m_device);
14353 descriptorSet.AppendDummy();
14354 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14355
14356 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14357
14358 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014359 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014360}
14361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014362TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014363 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014364
14365 ASSERT_NO_FATAL_FAILURE(InitState());
14366 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14367
14368 VkVertexInputBindingDescription input_binding;
14369 memset(&input_binding, 0, sizeof(input_binding));
14370
14371 VkVertexInputAttributeDescription input_attribs[2];
14372 memset(input_attribs, 0, sizeof(input_attribs));
14373
14374 for (int i = 0; i < 2; i++) {
14375 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14376 input_attribs[i].location = i;
14377 }
14378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014379 char const *vsSource = "#version 450\n"
14380 "\n"
14381 "layout(location=0) in vec4 x[2];\n"
14382 "out gl_PerVertex {\n"
14383 " vec4 gl_Position;\n"
14384 "};\n"
14385 "void main(){\n"
14386 " gl_Position = x[0] + x[1];\n"
14387 "}\n";
14388 char const *fsSource = "#version 450\n"
14389 "\n"
14390 "layout(location=0) out vec4 color;\n"
14391 "void main(){\n"
14392 " color = vec4(1);\n"
14393 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014394
14395 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14396 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14397
14398 VkPipelineObj pipe(m_device);
14399 pipe.AddColorAttachment();
14400 pipe.AddShader(&vs);
14401 pipe.AddShader(&fs);
14402
14403 pipe.AddVertexInputBindings(&input_binding, 1);
14404 pipe.AddVertexInputAttribs(input_attribs, 2);
14405
14406 VkDescriptorSetObj descriptorSet(m_device);
14407 descriptorSet.AppendDummy();
14408 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14409
14410 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14411
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014412 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014413}
Chris Forbes2682b242015-11-24 11:13:14 +130014414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014415TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014416 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14417 "through multiple VS inputs, each consuming a different subset of the "
14418 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014419 m_errorMonitor->ExpectSuccess();
14420
14421 ASSERT_NO_FATAL_FAILURE(InitState());
14422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14423
14424 VkVertexInputBindingDescription input_binding;
14425 memset(&input_binding, 0, sizeof(input_binding));
14426
14427 VkVertexInputAttributeDescription input_attribs[3];
14428 memset(input_attribs, 0, sizeof(input_attribs));
14429
14430 for (int i = 0; i < 3; i++) {
14431 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14432 input_attribs[i].location = i;
14433 }
14434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014435 char const *vsSource = "#version 450\n"
14436 "\n"
14437 "layout(location=0) in vec4 x;\n"
14438 "layout(location=1) in vec3 y1;\n"
14439 "layout(location=1, component=3) in float y2;\n"
14440 "layout(location=2) in vec4 z;\n"
14441 "out gl_PerVertex {\n"
14442 " vec4 gl_Position;\n"
14443 "};\n"
14444 "void main(){\n"
14445 " gl_Position = x + vec4(y1, y2) + z;\n"
14446 "}\n";
14447 char const *fsSource = "#version 450\n"
14448 "\n"
14449 "layout(location=0) out vec4 color;\n"
14450 "void main(){\n"
14451 " color = vec4(1);\n"
14452 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014453
14454 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14455 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14456
14457 VkPipelineObj pipe(m_device);
14458 pipe.AddColorAttachment();
14459 pipe.AddShader(&vs);
14460 pipe.AddShader(&fs);
14461
14462 pipe.AddVertexInputBindings(&input_binding, 1);
14463 pipe.AddVertexInputAttribs(input_attribs, 3);
14464
14465 VkDescriptorSetObj descriptorSet(m_device);
14466 descriptorSet.AppendDummy();
14467 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14468
14469 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14470
14471 m_errorMonitor->VerifyNotFound();
14472}
14473
Chris Forbes82ff92a2016-09-09 10:50:24 +120014474TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14476 "No entrypoint found named `foo`");
14477
14478 ASSERT_NO_FATAL_FAILURE(InitState());
14479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14480
14481 char const *vsSource = "#version 450\n"
14482 "out gl_PerVertex {\n"
14483 " vec4 gl_Position;\n"
14484 "};\n"
14485 "void main(){\n"
14486 " gl_Position = vec4(0);\n"
14487 "}\n";
14488 char const *fsSource = "#version 450\n"
14489 "\n"
14490 "layout(location=0) out vec4 color;\n"
14491 "void main(){\n"
14492 " color = vec4(1);\n"
14493 "}\n";
14494
14495 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14497
14498 VkPipelineObj pipe(m_device);
14499 pipe.AddColorAttachment();
14500 pipe.AddShader(&vs);
14501 pipe.AddShader(&fs);
14502
14503 VkDescriptorSetObj descriptorSet(m_device);
14504 descriptorSet.AppendDummy();
14505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14506
14507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14508
14509 m_errorMonitor->VerifyFound();
14510}
14511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014512TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014513 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014514
14515 ASSERT_NO_FATAL_FAILURE(InitState());
14516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014518 char const *vsSource = "#version 450\n"
14519 "out gl_PerVertex {\n"
14520 " vec4 gl_Position;\n"
14521 "};\n"
14522 "void main(){\n"
14523 " gl_Position = vec4(0);\n"
14524 "}\n";
14525 char const *fsSource = "#version 450\n"
14526 "\n"
14527 "layout(location=0) out vec4 color;\n"
14528 "void main(){\n"
14529 " color = vec4(1);\n"
14530 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014531
14532 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14533 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14534
14535 VkPipelineObj pipe(m_device);
14536 pipe.AddColorAttachment();
14537 pipe.AddShader(&vs);
14538 pipe.AddShader(&fs);
14539
14540 VkDescriptorSetObj descriptorSet(m_device);
14541 descriptorSet.AppendDummy();
14542 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14543
14544 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14545
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014546 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014547}
14548
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014549TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14550 m_errorMonitor->SetDesiredFailureMsg(
14551 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14552 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14553 "uses a depth/stencil attachment");
14554
14555 ASSERT_NO_FATAL_FAILURE(InitState());
14556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14557
14558 char const *vsSource = "#version 450\n"
14559 "void main(){ gl_Position = vec4(0); }\n";
14560 char const *fsSource = "#version 450\n"
14561 "\n"
14562 "layout(location=0) out vec4 color;\n"
14563 "void main(){\n"
14564 " color = vec4(1);\n"
14565 "}\n";
14566
14567 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14568 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14569
14570 VkPipelineObj pipe(m_device);
14571 pipe.AddColorAttachment();
14572 pipe.AddShader(&vs);
14573 pipe.AddShader(&fs);
14574
14575 VkDescriptorSetObj descriptorSet(m_device);
14576 descriptorSet.AppendDummy();
14577 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14578
14579 VkAttachmentDescription attachments[] = {
14580 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14581 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14582 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14583 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14584 },
14585 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14586 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14587 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14588 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14589 },
14590 };
14591 VkAttachmentReference refs[] = {
14592 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14593 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14594 };
14595 VkSubpassDescription subpass = {
14596 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14597 1, &refs[0], nullptr, &refs[1],
14598 0, nullptr
14599 };
14600 VkRenderPassCreateInfo rpci = {
14601 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14602 0, 2, attachments, 1, &subpass, 0, nullptr
14603 };
14604 VkRenderPass rp;
14605 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14606 ASSERT_VK_SUCCESS(err);
14607
14608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14609
14610 m_errorMonitor->VerifyFound();
14611
14612 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14613}
14614
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014615TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014616 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14617 "set out in 14.1.3: fundamental type must match, and producer side must "
14618 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014619 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014620
14621 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14622
14623 ASSERT_NO_FATAL_FAILURE(InitState());
14624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014626 char const *vsSource = "#version 450\n"
14627 "out gl_PerVertex {\n"
14628 " vec4 gl_Position;\n"
14629 "};\n"
14630 "layout(location=0) out vec3 x;\n"
14631 "layout(location=1) out ivec3 y;\n"
14632 "layout(location=2) out vec3 z;\n"
14633 "void main(){\n"
14634 " gl_Position = vec4(0);\n"
14635 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14636 "}\n";
14637 char const *fsSource = "#version 450\n"
14638 "\n"
14639 "layout(location=0) out vec4 color;\n"
14640 "layout(location=0) in float x;\n"
14641 "layout(location=1) flat in int y;\n"
14642 "layout(location=2) in vec2 z;\n"
14643 "void main(){\n"
14644 " color = vec4(1 + x + y + z.x);\n"
14645 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014646
14647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14648 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14649
14650 VkPipelineObj pipe(m_device);
14651 pipe.AddColorAttachment();
14652 pipe.AddShader(&vs);
14653 pipe.AddShader(&fs);
14654
14655 VkDescriptorSetObj descriptorSet(m_device);
14656 descriptorSet.AppendDummy();
14657 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14658
Mike Stroyan255e9582016-06-24 09:49:32 -060014659 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014661 ASSERT_VK_SUCCESS(err);
14662
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014663 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014664}
14665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014666TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014667 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14668 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014669 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014670
14671 ASSERT_NO_FATAL_FAILURE(InitState());
14672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14673
Chris Forbesc1e852d2016-04-04 19:26:42 +120014674 if (!m_device->phy().features().tessellationShader) {
14675 printf("Device does not support tessellation shaders; skipped.\n");
14676 return;
14677 }
14678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014679 char const *vsSource = "#version 450\n"
14680 "void main(){}\n";
14681 char const *tcsSource = "#version 450\n"
14682 "layout(location=0) out int x[];\n"
14683 "layout(vertices=3) out;\n"
14684 "void main(){\n"
14685 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14686 " gl_TessLevelInner[0] = 1;\n"
14687 " x[gl_InvocationID] = gl_InvocationID;\n"
14688 "}\n";
14689 char const *tesSource = "#version 450\n"
14690 "layout(triangles, equal_spacing, cw) in;\n"
14691 "layout(location=0) in int x[];\n"
14692 "out gl_PerVertex { vec4 gl_Position; };\n"
14693 "void main(){\n"
14694 " gl_Position.xyz = gl_TessCoord;\n"
14695 " gl_Position.w = x[0] + x[1] + x[2];\n"
14696 "}\n";
14697 char const *fsSource = "#version 450\n"
14698 "layout(location=0) out vec4 color;\n"
14699 "void main(){\n"
14700 " color = vec4(1);\n"
14701 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014702
14703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14704 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14705 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014708 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14709 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014711 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014712
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014713 VkPipelineObj pipe(m_device);
14714 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014715 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014716 pipe.AddColorAttachment();
14717 pipe.AddShader(&vs);
14718 pipe.AddShader(&tcs);
14719 pipe.AddShader(&tes);
14720 pipe.AddShader(&fs);
14721
14722 VkDescriptorSetObj descriptorSet(m_device);
14723 descriptorSet.AppendDummy();
14724 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14725
14726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14727
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014728 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014729}
14730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014731TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014732 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14733 "interface block passed into the geometry shader. This "
14734 "is interesting because the 'extra' array level is not "
14735 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014736 m_errorMonitor->ExpectSuccess();
14737
14738 ASSERT_NO_FATAL_FAILURE(InitState());
14739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14740
14741 if (!m_device->phy().features().geometryShader) {
14742 printf("Device does not support geometry shaders; skipped.\n");
14743 return;
14744 }
14745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014746 char const *vsSource = "#version 450\n"
14747 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14748 "void main(){\n"
14749 " vs_out.x = vec4(1);\n"
14750 "}\n";
14751 char const *gsSource = "#version 450\n"
14752 "layout(triangles) in;\n"
14753 "layout(triangle_strip, max_vertices=3) out;\n"
14754 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14755 "out gl_PerVertex { vec4 gl_Position; };\n"
14756 "void main() {\n"
14757 " gl_Position = gs_in[0].x;\n"
14758 " EmitVertex();\n"
14759 "}\n";
14760 char const *fsSource = "#version 450\n"
14761 "layout(location=0) out vec4 color;\n"
14762 "void main(){\n"
14763 " color = vec4(1);\n"
14764 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014765
14766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14767 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14769
14770 VkPipelineObj pipe(m_device);
14771 pipe.AddColorAttachment();
14772 pipe.AddShader(&vs);
14773 pipe.AddShader(&gs);
14774 pipe.AddShader(&fs);
14775
14776 VkDescriptorSetObj descriptorSet(m_device);
14777 descriptorSet.AppendDummy();
14778 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14779
14780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14781
14782 m_errorMonitor->VerifyNotFound();
14783}
14784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014785TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014786 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14787 "the TCS without the patch decoration, but consumed in the TES "
14788 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14790 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014791
14792 ASSERT_NO_FATAL_FAILURE(InitState());
14793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14794
Chris Forbesc1e852d2016-04-04 19:26:42 +120014795 if (!m_device->phy().features().tessellationShader) {
14796 printf("Device does not support tessellation shaders; skipped.\n");
14797 return;
14798 }
14799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014800 char const *vsSource = "#version 450\n"
14801 "void main(){}\n";
14802 char const *tcsSource = "#version 450\n"
14803 "layout(location=0) out int x[];\n"
14804 "layout(vertices=3) out;\n"
14805 "void main(){\n"
14806 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14807 " gl_TessLevelInner[0] = 1;\n"
14808 " x[gl_InvocationID] = gl_InvocationID;\n"
14809 "}\n";
14810 char const *tesSource = "#version 450\n"
14811 "layout(triangles, equal_spacing, cw) in;\n"
14812 "layout(location=0) patch in int x;\n"
14813 "out gl_PerVertex { vec4 gl_Position; };\n"
14814 "void main(){\n"
14815 " gl_Position.xyz = gl_TessCoord;\n"
14816 " gl_Position.w = x;\n"
14817 "}\n";
14818 char const *fsSource = "#version 450\n"
14819 "layout(location=0) out vec4 color;\n"
14820 "void main(){\n"
14821 " color = vec4(1);\n"
14822 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014823
14824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14825 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14826 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14827 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014829 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14830 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014832 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014833
14834 VkPipelineObj pipe(m_device);
14835 pipe.SetInputAssembly(&iasci);
14836 pipe.SetTessellation(&tsci);
14837 pipe.AddColorAttachment();
14838 pipe.AddShader(&vs);
14839 pipe.AddShader(&tcs);
14840 pipe.AddShader(&tes);
14841 pipe.AddShader(&fs);
14842
14843 VkDescriptorSetObj descriptorSet(m_device);
14844 descriptorSet.AppendDummy();
14845 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14846
14847 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14848
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014849 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014850}
14851
Karl Schultz6addd812016-02-02 17:17:23 -070014852TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014853 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14854 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14856 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014857
Chris Forbes280ba2c2015-06-12 11:16:41 +120014858 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014860
14861 /* Two binding descriptions for binding 0 */
14862 VkVertexInputBindingDescription input_bindings[2];
14863 memset(input_bindings, 0, sizeof(input_bindings));
14864
14865 VkVertexInputAttributeDescription input_attrib;
14866 memset(&input_attrib, 0, sizeof(input_attrib));
14867 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014869 char const *vsSource = "#version 450\n"
14870 "\n"
14871 "layout(location=0) in float x;\n" /* attrib provided float */
14872 "out gl_PerVertex {\n"
14873 " vec4 gl_Position;\n"
14874 "};\n"
14875 "void main(){\n"
14876 " gl_Position = vec4(x);\n"
14877 "}\n";
14878 char const *fsSource = "#version 450\n"
14879 "\n"
14880 "layout(location=0) out vec4 color;\n"
14881 "void main(){\n"
14882 " color = vec4(1);\n"
14883 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014884
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014887
14888 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014889 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014890 pipe.AddShader(&vs);
14891 pipe.AddShader(&fs);
14892
14893 pipe.AddVertexInputBindings(input_bindings, 2);
14894 pipe.AddVertexInputAttribs(&input_attrib, 1);
14895
Chris Forbes280ba2c2015-06-12 11:16:41 +120014896 VkDescriptorSetObj descriptorSet(m_device);
14897 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014898 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014899
Tony Barbour5781e8f2015-08-04 16:23:11 -060014900 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014902 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014903}
Chris Forbes8f68b562015-05-25 11:13:32 +120014904
Chris Forbes35efec72016-04-21 14:32:08 +120014905TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014906 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14907 "attributes. This is interesting because they consume multiple "
14908 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014909 m_errorMonitor->ExpectSuccess();
14910
14911 ASSERT_NO_FATAL_FAILURE(InitState());
14912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14913
Chris Forbes91cf3a82016-06-28 17:51:35 +120014914 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014915 printf("Device does not support 64bit vertex attributes; skipped.\n");
14916 return;
14917 }
14918
14919 VkVertexInputBindingDescription input_bindings[1];
14920 memset(input_bindings, 0, sizeof(input_bindings));
14921
14922 VkVertexInputAttributeDescription input_attribs[4];
14923 memset(input_attribs, 0, sizeof(input_attribs));
14924 input_attribs[0].location = 0;
14925 input_attribs[0].offset = 0;
14926 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14927 input_attribs[1].location = 2;
14928 input_attribs[1].offset = 32;
14929 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14930 input_attribs[2].location = 4;
14931 input_attribs[2].offset = 64;
14932 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14933 input_attribs[3].location = 6;
14934 input_attribs[3].offset = 96;
14935 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014937 char const *vsSource = "#version 450\n"
14938 "\n"
14939 "layout(location=0) in dmat4 x;\n"
14940 "out gl_PerVertex {\n"
14941 " vec4 gl_Position;\n"
14942 "};\n"
14943 "void main(){\n"
14944 " gl_Position = vec4(x[0][0]);\n"
14945 "}\n";
14946 char const *fsSource = "#version 450\n"
14947 "\n"
14948 "layout(location=0) out vec4 color;\n"
14949 "void main(){\n"
14950 " color = vec4(1);\n"
14951 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014952
14953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14955
14956 VkPipelineObj pipe(m_device);
14957 pipe.AddColorAttachment();
14958 pipe.AddShader(&vs);
14959 pipe.AddShader(&fs);
14960
14961 pipe.AddVertexInputBindings(input_bindings, 1);
14962 pipe.AddVertexInputAttribs(input_attribs, 4);
14963
14964 VkDescriptorSetObj descriptorSet(m_device);
14965 descriptorSet.AppendDummy();
14966 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14967
14968 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14969
14970 m_errorMonitor->VerifyNotFound();
14971}
14972
Karl Schultz6addd812016-02-02 17:17:23 -070014973TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014974 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14975 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014977
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014978 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014980 char const *vsSource = "#version 450\n"
14981 "\n"
14982 "out gl_PerVertex {\n"
14983 " vec4 gl_Position;\n"
14984 "};\n"
14985 "void main(){\n"
14986 " gl_Position = vec4(1);\n"
14987 "}\n";
14988 char const *fsSource = "#version 450\n"
14989 "\n"
14990 "void main(){\n"
14991 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014992
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014993 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14994 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014995
14996 VkPipelineObj pipe(m_device);
14997 pipe.AddShader(&vs);
14998 pipe.AddShader(&fs);
14999
Chia-I Wu08accc62015-07-07 11:50:03 +080015000 /* set up CB 0, not written */
15001 pipe.AddColorAttachment();
15002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015003
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015004 VkDescriptorSetObj descriptorSet(m_device);
15005 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015006 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015007
Tony Barbour5781e8f2015-08-04 16:23:11 -060015008 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015010 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015011}
15012
Karl Schultz6addd812016-02-02 17:17:23 -070015013TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015014 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
15015 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
15017 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015018
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015019 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015020
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015021 char const *vsSource = "#version 450\n"
15022 "\n"
15023 "out gl_PerVertex {\n"
15024 " vec4 gl_Position;\n"
15025 "};\n"
15026 "void main(){\n"
15027 " gl_Position = vec4(1);\n"
15028 "}\n";
15029 char const *fsSource = "#version 450\n"
15030 "\n"
15031 "layout(location=0) out vec4 x;\n"
15032 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15033 "void main(){\n"
15034 " x = vec4(1);\n"
15035 " y = vec4(1);\n"
15036 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015037
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015038 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015040
15041 VkPipelineObj pipe(m_device);
15042 pipe.AddShader(&vs);
15043 pipe.AddShader(&fs);
15044
Chia-I Wu08accc62015-07-07 11:50:03 +080015045 /* set up CB 0, not written */
15046 pipe.AddColorAttachment();
15047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015048 /* FS writes CB 1, but we don't configure it */
15049
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015050 VkDescriptorSetObj descriptorSet(m_device);
15051 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015052 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015053
Tony Barbour5781e8f2015-08-04 16:23:11 -060015054 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015055
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015056 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015057}
15058
Karl Schultz6addd812016-02-02 17:17:23 -070015059TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015060 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
15061 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015063
Chris Forbesa36d69e2015-05-25 11:13:44 +120015064 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 char const *vsSource = "#version 450\n"
15067 "\n"
15068 "out gl_PerVertex {\n"
15069 " vec4 gl_Position;\n"
15070 "};\n"
15071 "void main(){\n"
15072 " gl_Position = vec4(1);\n"
15073 "}\n";
15074 char const *fsSource = "#version 450\n"
15075 "\n"
15076 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15077 "void main(){\n"
15078 " x = ivec4(1);\n"
15079 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015080
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015081 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15082 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015083
15084 VkPipelineObj pipe(m_device);
15085 pipe.AddShader(&vs);
15086 pipe.AddShader(&fs);
15087
Chia-I Wu08accc62015-07-07 11:50:03 +080015088 /* set up CB 0; type is UNORM by default */
15089 pipe.AddColorAttachment();
15090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015091
Chris Forbesa36d69e2015-05-25 11:13:44 +120015092 VkDescriptorSetObj descriptorSet(m_device);
15093 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015094 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015095
Tony Barbour5781e8f2015-08-04 16:23:11 -060015096 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015097
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015098 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015099}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015100
Karl Schultz6addd812016-02-02 17:17:23 -070015101TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015102 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
15103 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015105
Chris Forbes556c76c2015-08-14 12:04:59 +120015106 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 char const *vsSource = "#version 450\n"
15109 "\n"
15110 "out gl_PerVertex {\n"
15111 " vec4 gl_Position;\n"
15112 "};\n"
15113 "void main(){\n"
15114 " gl_Position = vec4(1);\n"
15115 "}\n";
15116 char const *fsSource = "#version 450\n"
15117 "\n"
15118 "layout(location=0) out vec4 x;\n"
15119 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15120 "void main(){\n"
15121 " x = vec4(bar.y);\n"
15122 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015123
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015124 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15125 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015126
Chris Forbes556c76c2015-08-14 12:04:59 +120015127 VkPipelineObj pipe(m_device);
15128 pipe.AddShader(&vs);
15129 pipe.AddShader(&fs);
15130
15131 /* set up CB 0; type is UNORM by default */
15132 pipe.AddColorAttachment();
15133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15134
15135 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015136 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015137
15138 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15139
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015140 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015141}
15142
Chris Forbes5c59e902016-02-26 16:56:09 +130015143TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015144 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
15145 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015147
15148 ASSERT_NO_FATAL_FAILURE(InitState());
15149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015150 char const *vsSource = "#version 450\n"
15151 "\n"
15152 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15153 "out gl_PerVertex {\n"
15154 " vec4 gl_Position;\n"
15155 "};\n"
15156 "void main(){\n"
15157 " gl_Position = vec4(consts.x);\n"
15158 "}\n";
15159 char const *fsSource = "#version 450\n"
15160 "\n"
15161 "layout(location=0) out vec4 x;\n"
15162 "void main(){\n"
15163 " x = vec4(1);\n"
15164 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015165
15166 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15167 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15168
15169 VkPipelineObj pipe(m_device);
15170 pipe.AddShader(&vs);
15171 pipe.AddShader(&fs);
15172
15173 /* set up CB 0; type is UNORM by default */
15174 pipe.AddColorAttachment();
15175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15176
15177 VkDescriptorSetObj descriptorSet(m_device);
15178 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15179
15180 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15181
15182 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015183 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015184}
15185
Chris Forbes3fb17902016-08-22 14:57:55 +120015186TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
15187 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15188 "which is not included in the subpass description");
15189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15190 "consumes input attachment index 0 but not provided in subpass");
15191
15192 ASSERT_NO_FATAL_FAILURE(InitState());
15193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 char const *vsSource = "#version 450\n"
15195 "\n"
15196 "out gl_PerVertex {\n"
15197 " vec4 gl_Position;\n"
15198 "};\n"
15199 "void main(){\n"
15200 " gl_Position = vec4(1);\n"
15201 "}\n";
15202 char const *fsSource = "#version 450\n"
15203 "\n"
15204 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15205 "layout(location=0) out vec4 color;\n"
15206 "void main() {\n"
15207 " color = subpassLoad(x);\n"
15208 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015209
15210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15212
15213 VkPipelineObj pipe(m_device);
15214 pipe.AddShader(&vs);
15215 pipe.AddShader(&fs);
15216 pipe.AddColorAttachment();
15217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015219 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15220 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015221 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015222 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015223 ASSERT_VK_SUCCESS(err);
15224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015225 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015226 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015227 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015228 ASSERT_VK_SUCCESS(err);
15229
15230 // error here.
15231 pipe.CreateVKPipeline(pl, renderPass());
15232
15233 m_errorMonitor->VerifyFound();
15234
15235 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15236 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15237}
15238
Chris Forbes663b5a82016-08-22 16:14:06 +120015239TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
15240 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
15241 m_errorMonitor->ExpectSuccess();
15242
15243 ASSERT_NO_FATAL_FAILURE(InitState());
15244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 char const *vsSource = "#version 450\n"
15246 "\n"
15247 "out gl_PerVertex {\n"
15248 " vec4 gl_Position;\n"
15249 "};\n"
15250 "void main(){\n"
15251 " gl_Position = vec4(1);\n"
15252 "}\n";
15253 char const *fsSource = "#version 450\n"
15254 "\n"
15255 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15256 "layout(location=0) out vec4 color;\n"
15257 "void main() {\n"
15258 " color = subpassLoad(x);\n"
15259 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120015260
15261 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15262 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15263
15264 VkPipelineObj pipe(m_device);
15265 pipe.AddShader(&vs);
15266 pipe.AddShader(&fs);
15267 pipe.AddColorAttachment();
15268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15271 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120015272 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015274 ASSERT_VK_SUCCESS(err);
15275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015276 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015277 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015278 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015279 ASSERT_VK_SUCCESS(err);
15280
15281 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015282 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15283 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15284 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15285 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15286 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 +120015287 };
15288 VkAttachmentReference color = {
15289 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15290 };
15291 VkAttachmentReference input = {
15292 1, VK_IMAGE_LAYOUT_GENERAL,
15293 };
15294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015295 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015297 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015298 VkRenderPass rp;
15299 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15300 ASSERT_VK_SUCCESS(err);
15301
15302 // should be OK. would go wrong here if it's going to...
15303 pipe.CreateVKPipeline(pl, rp);
15304
15305 m_errorMonitor->VerifyNotFound();
15306
15307 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15308 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15309 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15310}
15311
Chris Forbes5a9a0472016-08-22 16:02:09 +120015312TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
15313 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15314 "with a format having a different fundamental type");
15315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15316 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15317
15318 ASSERT_NO_FATAL_FAILURE(InitState());
15319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015320 char const *vsSource = "#version 450\n"
15321 "\n"
15322 "out gl_PerVertex {\n"
15323 " vec4 gl_Position;\n"
15324 "};\n"
15325 "void main(){\n"
15326 " gl_Position = vec4(1);\n"
15327 "}\n";
15328 char const *fsSource = "#version 450\n"
15329 "\n"
15330 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15331 "layout(location=0) out vec4 color;\n"
15332 "void main() {\n"
15333 " color = subpassLoad(x);\n"
15334 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015335
15336 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15337 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15338
15339 VkPipelineObj pipe(m_device);
15340 pipe.AddShader(&vs);
15341 pipe.AddShader(&fs);
15342 pipe.AddColorAttachment();
15343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015345 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15346 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015347 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015348 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015349 ASSERT_VK_SUCCESS(err);
15350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015351 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015352 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015354 ASSERT_VK_SUCCESS(err);
15355
15356 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15358 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15359 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15360 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15361 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 +120015362 };
15363 VkAttachmentReference color = {
15364 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15365 };
15366 VkAttachmentReference input = {
15367 1, VK_IMAGE_LAYOUT_GENERAL,
15368 };
15369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015372 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015373 VkRenderPass rp;
15374 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15375 ASSERT_VK_SUCCESS(err);
15376
15377 // error here.
15378 pipe.CreateVKPipeline(pl, rp);
15379
15380 m_errorMonitor->VerifyFound();
15381
15382 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15383 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15384 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15385}
15386
Chris Forbes541f7b02016-08-22 15:30:27 +120015387TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
15388 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15389 "which is not included in the subpass description -- array case");
15390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15391 "consumes input attachment index 1 but not provided in subpass");
15392
15393 ASSERT_NO_FATAL_FAILURE(InitState());
15394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015395 char const *vsSource = "#version 450\n"
15396 "\n"
15397 "out gl_PerVertex {\n"
15398 " vec4 gl_Position;\n"
15399 "};\n"
15400 "void main(){\n"
15401 " gl_Position = vec4(1);\n"
15402 "}\n";
15403 char const *fsSource = "#version 450\n"
15404 "\n"
15405 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15406 "layout(location=0) out vec4 color;\n"
15407 "void main() {\n"
15408 " color = subpassLoad(xs[1]);\n"
15409 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015410
15411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15413
15414 VkPipelineObj pipe(m_device);
15415 pipe.AddShader(&vs);
15416 pipe.AddShader(&fs);
15417 pipe.AddColorAttachment();
15418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015420 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15421 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015422 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015423 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015424 ASSERT_VK_SUCCESS(err);
15425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015427 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015429 ASSERT_VK_SUCCESS(err);
15430
15431 // error here.
15432 pipe.CreateVKPipeline(pl, renderPass());
15433
15434 m_errorMonitor->VerifyFound();
15435
15436 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15437 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15438}
15439
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015440TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015441 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15442 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015444
15445 ASSERT_NO_FATAL_FAILURE(InitState());
15446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015447 char const *csSource = "#version 450\n"
15448 "\n"
15449 "layout(local_size_x=1) in;\n"
15450 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15451 "void main(){\n"
15452 " x = vec4(1);\n"
15453 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015454
15455 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15456
15457 VkDescriptorSetObj descriptorSet(m_device);
15458 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015460 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15461 nullptr,
15462 0,
15463 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15464 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15465 descriptorSet.GetPipelineLayout(),
15466 VK_NULL_HANDLE,
15467 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015468
15469 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015470 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015471
15472 m_errorMonitor->VerifyFound();
15473
15474 if (err == VK_SUCCESS) {
15475 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15476 }
15477}
15478
15479TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015480 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15481 "descriptor-backed resource which is not provided, but the shader does not "
15482 "statically use it. This is interesting because it requires compute pipelines "
15483 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015484 m_errorMonitor->ExpectSuccess();
15485
15486 ASSERT_NO_FATAL_FAILURE(InitState());
15487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 char const *csSource = "#version 450\n"
15489 "\n"
15490 "layout(local_size_x=1) in;\n"
15491 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15492 "void main(){\n"
15493 " // x is not used.\n"
15494 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015495
15496 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15497
15498 VkDescriptorSetObj descriptorSet(m_device);
15499 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015501 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15502 nullptr,
15503 0,
15504 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15505 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15506 descriptorSet.GetPipelineLayout(),
15507 VK_NULL_HANDLE,
15508 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015509
15510 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015511 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015512
15513 m_errorMonitor->VerifyNotFound();
15514
15515 if (err == VK_SUCCESS) {
15516 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15517 }
15518}
15519
Chris Forbes22a9b092016-07-19 14:34:05 +120015520TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015521 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15522 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15524 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015525
15526 ASSERT_NO_FATAL_FAILURE(InitState());
15527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015528 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15529 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015530 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015531 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015532 ASSERT_VK_SUCCESS(err);
15533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015534 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015535 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015536 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015537 ASSERT_VK_SUCCESS(err);
15538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015539 char const *csSource = "#version 450\n"
15540 "\n"
15541 "layout(local_size_x=1) in;\n"
15542 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15543 "void main() {\n"
15544 " x.x = 1.0f;\n"
15545 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015546 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015548 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15549 nullptr,
15550 0,
15551 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15552 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15553 pl,
15554 VK_NULL_HANDLE,
15555 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015556
15557 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015558 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015559
15560 m_errorMonitor->VerifyFound();
15561
15562 if (err == VK_SUCCESS) {
15563 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15564 }
15565
15566 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15567 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15568}
15569
Chris Forbese10a51f2016-07-19 14:42:51 +120015570TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015571 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15572 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015573 m_errorMonitor->ExpectSuccess();
15574
15575 ASSERT_NO_FATAL_FAILURE(InitState());
15576
15577 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015578 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15579 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15580 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015581 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015583 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015584 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015585 ASSERT_VK_SUCCESS(err);
15586
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015587 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015588 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015589 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015590 ASSERT_VK_SUCCESS(err);
15591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 char const *csSource = "#version 450\n"
15593 "\n"
15594 "layout(local_size_x=1) in;\n"
15595 "layout(set=0, binding=0) uniform sampler s;\n"
15596 "layout(set=0, binding=1) uniform texture2D t;\n"
15597 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15598 "void main() {\n"
15599 " x = texture(sampler2D(t, s), vec2(0));\n"
15600 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015601 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015603 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15604 nullptr,
15605 0,
15606 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15607 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15608 pl,
15609 VK_NULL_HANDLE,
15610 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015611
15612 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015613 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015614
15615 m_errorMonitor->VerifyNotFound();
15616
15617 if (err == VK_SUCCESS) {
15618 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15619 }
15620
15621 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15622 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15623}
15624
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015625TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015626 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15627 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015628 m_errorMonitor->ExpectSuccess();
15629
15630 ASSERT_NO_FATAL_FAILURE(InitState());
15631
15632 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015633 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15634 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15635 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015636 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015637 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015638 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015639 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015640 ASSERT_VK_SUCCESS(err);
15641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015642 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015643 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015644 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015645 ASSERT_VK_SUCCESS(err);
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) uniform texture2D t;\n"
15651 "layout(set=0, binding=1) uniform sampler s;\n"
15652 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15653 "void main() {\n"
15654 " x = texture(sampler2D(t, s), vec2(0));\n"
15655 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015656 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015658 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15659 nullptr,
15660 0,
15661 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15662 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15663 pl,
15664 VK_NULL_HANDLE,
15665 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015666
15667 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015668 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015669
15670 m_errorMonitor->VerifyNotFound();
15671
15672 if (err == VK_SUCCESS) {
15673 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15674 }
15675
15676 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15677 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15678}
15679
Chris Forbes6a4991a2016-07-19 15:07:32 +120015680TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015681 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15682 "both the sampler and the image of a combined image+sampler "
15683 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015684 m_errorMonitor->ExpectSuccess();
15685
15686 ASSERT_NO_FATAL_FAILURE(InitState());
15687
15688 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015689 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15690 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015691 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015693 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015694 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015695 ASSERT_VK_SUCCESS(err);
15696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015697 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015698 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015699 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015700 ASSERT_VK_SUCCESS(err);
15701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015702 char const *csSource = "#version 450\n"
15703 "\n"
15704 "layout(local_size_x=1) in;\n"
15705 "layout(set=0, binding=0) uniform texture2D t;\n"
15706 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15707 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15708 "void main() {\n"
15709 " x = texture(sampler2D(t, s), vec2(0));\n"
15710 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015711 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15712
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015713 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15714 nullptr,
15715 0,
15716 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15717 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15718 pl,
15719 VK_NULL_HANDLE,
15720 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015721
15722 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015724
15725 m_errorMonitor->VerifyNotFound();
15726
15727 if (err == VK_SUCCESS) {
15728 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15729 }
15730
15731 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15732 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15733}
15734
Chris Forbes50020592016-07-27 13:52:41 +120015735TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15736 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15737 "does not match the dimensionality declared in the shader");
15738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015739 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 +120015740
15741 ASSERT_NO_FATAL_FAILURE(InitState());
15742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15743
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015744 char const *vsSource = "#version 450\n"
15745 "\n"
15746 "out gl_PerVertex { vec4 gl_Position; };\n"
15747 "void main() { gl_Position = vec4(0); }\n";
15748 char const *fsSource = "#version 450\n"
15749 "\n"
15750 "layout(set=0, binding=0) uniform sampler3D s;\n"
15751 "layout(location=0) out vec4 color;\n"
15752 "void main() {\n"
15753 " color = texture(s, vec3(0));\n"
15754 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15757
15758 VkPipelineObj pipe(m_device);
15759 pipe.AddShader(&vs);
15760 pipe.AddShader(&fs);
15761 pipe.AddColorAttachment();
15762
15763 VkTextureObj texture(m_device, nullptr);
15764 VkSamplerObj sampler(m_device);
15765
15766 VkDescriptorSetObj descriptorSet(m_device);
15767 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15768 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15769
15770 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15771 ASSERT_VK_SUCCESS(err);
15772
15773 BeginCommandBuffer();
15774
15775 m_commandBuffer->BindPipeline(pipe);
15776 m_commandBuffer->BindDescriptorSet(descriptorSet);
15777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015778 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015779 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015780 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015781 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15782
15783 // error produced here.
15784 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15785
15786 m_errorMonitor->VerifyFound();
15787
15788 EndCommandBuffer();
15789}
15790
Chris Forbes5533bfc2016-07-27 14:12:34 +120015791TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15792 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15793 "are consumed via singlesample images types in the shader, or vice versa.");
15794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015796
15797 ASSERT_NO_FATAL_FAILURE(InitState());
15798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015800 char const *vsSource = "#version 450\n"
15801 "\n"
15802 "out gl_PerVertex { vec4 gl_Position; };\n"
15803 "void main() { gl_Position = vec4(0); }\n";
15804 char const *fsSource = "#version 450\n"
15805 "\n"
15806 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15807 "layout(location=0) out vec4 color;\n"
15808 "void main() {\n"
15809 " color = texelFetch(s, ivec2(0), 0);\n"
15810 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015811 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15812 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15813
15814 VkPipelineObj pipe(m_device);
15815 pipe.AddShader(&vs);
15816 pipe.AddShader(&fs);
15817 pipe.AddColorAttachment();
15818
15819 VkTextureObj texture(m_device, nullptr);
15820 VkSamplerObj sampler(m_device);
15821
15822 VkDescriptorSetObj descriptorSet(m_device);
15823 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15824 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15825
15826 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15827 ASSERT_VK_SUCCESS(err);
15828
15829 BeginCommandBuffer();
15830
15831 m_commandBuffer->BindPipeline(pipe);
15832 m_commandBuffer->BindDescriptorSet(descriptorSet);
15833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015834 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015835 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015836 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015837 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15838
15839 // error produced here.
15840 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15841
15842 m_errorMonitor->VerifyFound();
15843
15844 EndCommandBuffer();
15845}
15846
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015847#endif // SHADER_CHECKER_TESTS
15848
15849#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015850TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015852
15853 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015854
15855 // Create an image
15856 VkImage image;
15857
Karl Schultz6addd812016-02-02 17:17:23 -070015858 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15859 const int32_t tex_width = 32;
15860 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015861
15862 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015863 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15864 image_create_info.pNext = NULL;
15865 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15866 image_create_info.format = tex_format;
15867 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015868 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015869 image_create_info.extent.depth = 1;
15870 image_create_info.mipLevels = 1;
15871 image_create_info.arrayLayers = 1;
15872 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15873 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15874 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15875 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015876
15877 // Introduce error by sending down a bogus width extent
15878 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015879 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015880
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015881 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015882}
15883
Mark Youngc48c4c12016-04-11 14:26:49 -060015884TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15886 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015887
15888 ASSERT_NO_FATAL_FAILURE(InitState());
15889
15890 // Create an image
15891 VkImage image;
15892
15893 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15894 const int32_t tex_width = 32;
15895 const int32_t tex_height = 32;
15896
15897 VkImageCreateInfo image_create_info = {};
15898 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15899 image_create_info.pNext = NULL;
15900 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15901 image_create_info.format = tex_format;
15902 image_create_info.extent.width = tex_width;
15903 image_create_info.extent.height = tex_height;
15904 image_create_info.extent.depth = 1;
15905 image_create_info.mipLevels = 1;
15906 image_create_info.arrayLayers = 1;
15907 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15908 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15909 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15910 image_create_info.flags = 0;
15911
15912 // Introduce error by sending down a bogus width extent
15913 image_create_info.extent.width = 0;
15914 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15915
15916 m_errorMonitor->VerifyFound();
15917}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015918#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015919
Tobin Ehliscde08892015-09-22 10:11:37 -060015920#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015921TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15922 TEST_DESCRIPTION("Create a render pass with an attachment description "
15923 "format set to VK_FORMAT_UNDEFINED");
15924
15925 ASSERT_NO_FATAL_FAILURE(InitState());
15926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015929
15930 VkAttachmentReference color_attach = {};
15931 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15932 color_attach.attachment = 0;
15933 VkSubpassDescription subpass = {};
15934 subpass.colorAttachmentCount = 1;
15935 subpass.pColorAttachments = &color_attach;
15936
15937 VkRenderPassCreateInfo rpci = {};
15938 rpci.subpassCount = 1;
15939 rpci.pSubpasses = &subpass;
15940 rpci.attachmentCount = 1;
15941 VkAttachmentDescription attach_desc = {};
15942 attach_desc.format = VK_FORMAT_UNDEFINED;
15943 rpci.pAttachments = &attach_desc;
15944 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15945 VkRenderPass rp;
15946 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15947
15948 m_errorMonitor->VerifyFound();
15949
15950 if (result == VK_SUCCESS) {
15951 vkDestroyRenderPass(m_device->device(), rp, NULL);
15952 }
15953}
15954
Karl Schultz6addd812016-02-02 17:17:23 -070015955TEST_F(VkLayerTest, InvalidImageView) {
15956 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015959
Tobin Ehliscde08892015-09-22 10:11:37 -060015960 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015961
Mike Stroyana3082432015-09-25 13:39:21 -060015962 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015963 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015964
Karl Schultz6addd812016-02-02 17:17:23 -070015965 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15966 const int32_t tex_width = 32;
15967 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015968
15969 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15971 image_create_info.pNext = NULL;
15972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15973 image_create_info.format = tex_format;
15974 image_create_info.extent.width = tex_width;
15975 image_create_info.extent.height = tex_height;
15976 image_create_info.extent.depth = 1;
15977 image_create_info.mipLevels = 1;
15978 image_create_info.arrayLayers = 1;
15979 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15982 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015983
Chia-I Wuf7458c52015-10-26 21:10:41 +080015984 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015985 ASSERT_VK_SUCCESS(err);
15986
15987 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015988 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15989 image_view_create_info.image = image;
15990 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15991 image_view_create_info.format = tex_format;
15992 image_view_create_info.subresourceRange.layerCount = 1;
15993 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15994 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015995 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015996
15997 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015998 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015999
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016000 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060016001 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016002}
Mike Stroyana3082432015-09-25 13:39:21 -060016003
Mark Youngd339ba32016-05-30 13:28:35 -060016004TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16005 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16007 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Youngd339ba32016-05-30 13:28:35 -060016008
16009 ASSERT_NO_FATAL_FAILURE(InitState());
16010
16011 // Create an image and try to create a view with no memory backing the image
16012 VkImage image;
16013
16014 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16015 const int32_t tex_width = 32;
16016 const int32_t tex_height = 32;
16017
16018 VkImageCreateInfo image_create_info = {};
16019 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16020 image_create_info.pNext = NULL;
16021 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16022 image_create_info.format = tex_format;
16023 image_create_info.extent.width = tex_width;
16024 image_create_info.extent.height = tex_height;
16025 image_create_info.extent.depth = 1;
16026 image_create_info.mipLevels = 1;
16027 image_create_info.arrayLayers = 1;
16028 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16029 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16030 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16031 image_create_info.flags = 0;
16032
16033 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16034 ASSERT_VK_SUCCESS(err);
16035
16036 VkImageViewCreateInfo image_view_create_info = {};
16037 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16038 image_view_create_info.image = image;
16039 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16040 image_view_create_info.format = tex_format;
16041 image_view_create_info.subresourceRange.layerCount = 1;
16042 image_view_create_info.subresourceRange.baseMipLevel = 0;
16043 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016045
16046 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016047 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016048
16049 m_errorMonitor->VerifyFound();
16050 vkDestroyImage(m_device->device(), image, NULL);
16051 // If last error is success, it still created the view, so delete it.
16052 if (err == VK_SUCCESS) {
16053 vkDestroyImageView(m_device->device(), view, NULL);
16054 }
Mark Youngd339ba32016-05-30 13:28:35 -060016055}
16056
Karl Schultz6addd812016-02-02 17:17:23 -070016057TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016058 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
16059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
16060 "formats must have ONLY the "
16061 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016062
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016063 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016064
Karl Schultz6addd812016-02-02 17:17:23 -070016065 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016066 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016067 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016068 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016069
16070 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016071 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016072 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016073 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16074 image_view_create_info.format = tex_format;
16075 image_view_create_info.subresourceRange.baseMipLevel = 0;
16076 image_view_create_info.subresourceRange.levelCount = 1;
16077 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016078 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016079
16080 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016081 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016082
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016083 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016084}
16085
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016086TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016087 VkResult err;
16088 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16091 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016092
Mike Stroyana3082432015-09-25 13:39:21 -060016093 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016094
16095 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016096 VkImage srcImage;
16097 VkImage dstImage;
16098 VkDeviceMemory srcMem;
16099 VkDeviceMemory destMem;
16100 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016101
16102 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16104 image_create_info.pNext = NULL;
16105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16106 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16107 image_create_info.extent.width = 32;
16108 image_create_info.extent.height = 32;
16109 image_create_info.extent.depth = 1;
16110 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016111 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016112 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16113 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16114 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16115 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016118 ASSERT_VK_SUCCESS(err);
16119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016121 ASSERT_VK_SUCCESS(err);
16122
16123 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016124 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016125 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16126 memAlloc.pNext = NULL;
16127 memAlloc.allocationSize = 0;
16128 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016129
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016130 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016131 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016132 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016133 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016134 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016135 ASSERT_VK_SUCCESS(err);
16136
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016137 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016138 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016139 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016140 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016141 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016142 ASSERT_VK_SUCCESS(err);
16143
16144 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16145 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016146 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016147 ASSERT_VK_SUCCESS(err);
16148
16149 BeginCommandBuffer();
16150 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016151 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016152 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016153 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016154 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016155 copyRegion.srcOffset.x = 0;
16156 copyRegion.srcOffset.y = 0;
16157 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016158 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016159 copyRegion.dstSubresource.mipLevel = 0;
16160 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016161 // Introduce failure by forcing the dst layerCount to differ from src
16162 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016163 copyRegion.dstOffset.x = 0;
16164 copyRegion.dstOffset.y = 0;
16165 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016166 copyRegion.extent.width = 1;
16167 copyRegion.extent.height = 1;
16168 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016169 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016170 EndCommandBuffer();
16171
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016172 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016173
Chia-I Wuf7458c52015-10-26 21:10:41 +080016174 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016175 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016176 vkFreeMemory(m_device->device(), srcMem, NULL);
16177 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016178}
16179
Tony Barbourd6673642016-05-05 14:46:39 -060016180TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
16181
16182 TEST_DESCRIPTION("Creating images with unsuported formats ");
16183
16184 ASSERT_NO_FATAL_FAILURE(InitState());
16185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16186 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016187 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 -060016188 VK_IMAGE_TILING_OPTIMAL, 0);
16189 ASSERT_TRUE(image.initialized());
16190
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016191 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
16192 VkImageCreateInfo image_create_info;
16193 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16194 image_create_info.pNext = NULL;
16195 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16196 image_create_info.format = VK_FORMAT_UNDEFINED;
16197 image_create_info.extent.width = 32;
16198 image_create_info.extent.height = 32;
16199 image_create_info.extent.depth = 1;
16200 image_create_info.mipLevels = 1;
16201 image_create_info.arrayLayers = 1;
16202 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16203 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16205 image_create_info.flags = 0;
16206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16208 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016209
16210 VkImage localImage;
16211 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
16212 m_errorMonitor->VerifyFound();
16213
Tony Barbourd6673642016-05-05 14:46:39 -060016214 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016215 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060016216 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16217 VkFormat format = static_cast<VkFormat>(f);
16218 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016219 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016220 unsupported = format;
16221 break;
16222 }
16223 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016224
Tony Barbourd6673642016-05-05 14:46:39 -060016225 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016226 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016228
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016229 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016230 m_errorMonitor->VerifyFound();
16231 }
16232}
16233
16234TEST_F(VkLayerTest, ImageLayerViewTests) {
16235 VkResult ret;
16236 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16237
16238 ASSERT_NO_FATAL_FAILURE(InitState());
16239
16240 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016241 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 -060016242 VK_IMAGE_TILING_OPTIMAL, 0);
16243 ASSERT_TRUE(image.initialized());
16244
16245 VkImageView imgView;
16246 VkImageViewCreateInfo imgViewInfo = {};
16247 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16248 imgViewInfo.image = image.handle();
16249 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16250 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16251 imgViewInfo.subresourceRange.layerCount = 1;
16252 imgViewInfo.subresourceRange.baseMipLevel = 0;
16253 imgViewInfo.subresourceRange.levelCount = 1;
16254 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060016257 // View can't have baseMipLevel >= image's mipLevels - Expect
16258 // VIEW_CREATE_ERROR
16259 imgViewInfo.subresourceRange.baseMipLevel = 1;
16260 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16261 m_errorMonitor->VerifyFound();
16262 imgViewInfo.subresourceRange.baseMipLevel = 0;
16263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060016265 // View can't have baseArrayLayer >= image's arraySize - Expect
16266 // VIEW_CREATE_ERROR
16267 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16268 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16269 m_errorMonitor->VerifyFound();
16270 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16273 "pCreateInfo->subresourceRange."
16274 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016275 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16276 imgViewInfo.subresourceRange.levelCount = 0;
16277 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16278 m_errorMonitor->VerifyFound();
16279 imgViewInfo.subresourceRange.levelCount = 1;
16280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16282 "pCreateInfo->subresourceRange."
16283 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016284 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16285 imgViewInfo.subresourceRange.layerCount = 0;
16286 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16287 m_errorMonitor->VerifyFound();
16288 imgViewInfo.subresourceRange.layerCount = 1;
16289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060016291 // Can't use depth format for view into color image - Expect INVALID_FORMAT
16292 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
16293 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16294 m_errorMonitor->VerifyFound();
16295 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
16298 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16299 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016300 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16301 // VIEW_CREATE_ERROR
16302 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16303 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16304 m_errorMonitor->VerifyFound();
16305 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
16308 "differing formats but they must be "
16309 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060016310 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16311 // VIEW_CREATE_ERROR
16312 VkImageCreateInfo mutImgInfo = image.create_info();
16313 VkImage mutImage;
16314 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016315 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016316 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16317 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16318 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16319 ASSERT_VK_SUCCESS(ret);
16320 imgViewInfo.image = mutImage;
16321 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16322 m_errorMonitor->VerifyFound();
16323 imgViewInfo.image = image.handle();
16324 vkDestroyImage(m_device->handle(), mutImage, NULL);
16325}
16326
16327TEST_F(VkLayerTest, MiscImageLayerTests) {
16328
16329 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16330
16331 ASSERT_NO_FATAL_FAILURE(InitState());
16332
16333 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016334 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 -060016335 VK_IMAGE_TILING_OPTIMAL, 0);
16336 ASSERT_TRUE(image.initialized());
16337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060016339 vk_testing::Buffer buffer;
16340 VkMemoryPropertyFlags reqs = 0;
16341 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
16342 VkBufferImageCopy region = {};
16343 region.bufferRowLength = 128;
16344 region.bufferImageHeight = 128;
16345 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16346 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16347 region.imageSubresource.layerCount = 0;
16348 region.imageExtent.height = 4;
16349 region.imageExtent.width = 4;
16350 region.imageExtent.depth = 1;
16351 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016352 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16353 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016354 m_errorMonitor->VerifyFound();
16355 region.imageSubresource.layerCount = 1;
16356
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016357 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16358 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
16359 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
16361 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16362 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016363 m_errorMonitor->VerifyFound();
16364
16365 // BufferOffset must be a multiple of 4
16366 // Introduce failure by setting bufferOffset to a value not divisible by 4
16367 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
16369 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16370 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016371 m_errorMonitor->VerifyFound();
16372
16373 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16374 region.bufferOffset = 0;
16375 region.imageExtent.height = 128;
16376 region.imageExtent.width = 128;
16377 // Introduce failure by setting bufferRowLength > 0 but less than width
16378 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16380 "must be zero or greater-than-or-equal-to imageExtent.width");
16381 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16382 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016383 m_errorMonitor->VerifyFound();
16384
16385 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16386 region.bufferRowLength = 128;
16387 // Introduce failure by setting bufferRowHeight > 0 but less than height
16388 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16390 "must be zero or greater-than-or-equal-to imageExtent.height");
16391 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16392 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016393 m_errorMonitor->VerifyFound();
16394
16395 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
16397 "specify only COLOR or DEPTH or "
16398 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060016399 // Expect MISMATCHED_IMAGE_ASPECT
16400 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016401 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16402 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016403 m_errorMonitor->VerifyFound();
16404 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16407 "If the format of srcImage is a depth, stencil, depth stencil or "
16408 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016409 // Expect INVALID_FILTER
16410 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016411 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 -060016412 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016413 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 -060016414 VkImageBlit blitRegion = {};
16415 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16416 blitRegion.srcSubresource.baseArrayLayer = 0;
16417 blitRegion.srcSubresource.layerCount = 1;
16418 blitRegion.srcSubresource.mipLevel = 0;
16419 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16420 blitRegion.dstSubresource.baseArrayLayer = 0;
16421 blitRegion.dstSubresource.layerCount = 1;
16422 blitRegion.dstSubresource.mipLevel = 0;
16423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016424 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16425 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016426 m_errorMonitor->VerifyFound();
16427
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016428 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16430 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16431 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016432 m_errorMonitor->VerifyFound();
16433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016435 VkImageMemoryBarrier img_barrier;
16436 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16437 img_barrier.pNext = NULL;
16438 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16439 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16440 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16441 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16442 img_barrier.image = image.handle();
16443 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16444 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16445 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16446 img_barrier.subresourceRange.baseArrayLayer = 0;
16447 img_barrier.subresourceRange.baseMipLevel = 0;
16448 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16449 img_barrier.subresourceRange.layerCount = 0;
16450 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016451 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16452 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016453 m_errorMonitor->VerifyFound();
16454 img_barrier.subresourceRange.layerCount = 1;
16455}
16456
16457TEST_F(VkLayerTest, ImageFormatLimits) {
16458
16459 TEST_DESCRIPTION("Exceed the limits of image format ");
16460
Cody Northropc31a84f2016-08-22 10:41:47 -060016461 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016463 VkImageCreateInfo image_create_info = {};
16464 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16465 image_create_info.pNext = NULL;
16466 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16467 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16468 image_create_info.extent.width = 32;
16469 image_create_info.extent.height = 32;
16470 image_create_info.extent.depth = 1;
16471 image_create_info.mipLevels = 1;
16472 image_create_info.arrayLayers = 1;
16473 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16474 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16475 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16476 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16477 image_create_info.flags = 0;
16478
16479 VkImage nullImg;
16480 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016481 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16482 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016483 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16484 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16485 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16486 m_errorMonitor->VerifyFound();
16487 image_create_info.extent.depth = 1;
16488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016490 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16491 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16492 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16493 m_errorMonitor->VerifyFound();
16494 image_create_info.mipLevels = 1;
16495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016497 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16498 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16499 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16500 m_errorMonitor->VerifyFound();
16501 image_create_info.arrayLayers = 1;
16502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016504 int samples = imgFmtProps.sampleCounts >> 1;
16505 image_create_info.samples = (VkSampleCountFlagBits)samples;
16506 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16507 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16508 m_errorMonitor->VerifyFound();
16509 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16512 "VK_IMAGE_LAYOUT_UNDEFINED or "
16513 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016514 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16515 // Expect INVALID_LAYOUT
16516 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16517 m_errorMonitor->VerifyFound();
16518 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16519}
16520
Karl Schultz6addd812016-02-02 17:17:23 -070016521TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016522 VkResult err;
16523 bool pass;
16524
16525 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16527 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016528
16529 ASSERT_NO_FATAL_FAILURE(InitState());
16530
16531 // Create two images of different types and try to copy between them
16532 VkImage srcImage;
16533 VkImage dstImage;
16534 VkDeviceMemory srcMem;
16535 VkDeviceMemory destMem;
16536 VkMemoryRequirements memReqs;
16537
16538 VkImageCreateInfo image_create_info = {};
16539 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16540 image_create_info.pNext = NULL;
16541 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16542 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16543 image_create_info.extent.width = 32;
16544 image_create_info.extent.height = 32;
16545 image_create_info.extent.depth = 1;
16546 image_create_info.mipLevels = 1;
16547 image_create_info.arrayLayers = 1;
16548 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16549 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16550 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16551 image_create_info.flags = 0;
16552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016554 ASSERT_VK_SUCCESS(err);
16555
16556 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16557 // Introduce failure by creating second image with a different-sized format.
16558 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016560 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016561 ASSERT_VK_SUCCESS(err);
16562
16563 // Allocate memory
16564 VkMemoryAllocateInfo memAlloc = {};
16565 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16566 memAlloc.pNext = NULL;
16567 memAlloc.allocationSize = 0;
16568 memAlloc.memoryTypeIndex = 0;
16569
16570 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16571 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016572 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016573 ASSERT_TRUE(pass);
16574 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16575 ASSERT_VK_SUCCESS(err);
16576
16577 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16578 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016579 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016580 ASSERT_TRUE(pass);
16581 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16582 ASSERT_VK_SUCCESS(err);
16583
16584 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16585 ASSERT_VK_SUCCESS(err);
16586 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16587 ASSERT_VK_SUCCESS(err);
16588
16589 BeginCommandBuffer();
16590 VkImageCopy copyRegion;
16591 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16592 copyRegion.srcSubresource.mipLevel = 0;
16593 copyRegion.srcSubresource.baseArrayLayer = 0;
16594 copyRegion.srcSubresource.layerCount = 0;
16595 copyRegion.srcOffset.x = 0;
16596 copyRegion.srcOffset.y = 0;
16597 copyRegion.srcOffset.z = 0;
16598 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16599 copyRegion.dstSubresource.mipLevel = 0;
16600 copyRegion.dstSubresource.baseArrayLayer = 0;
16601 copyRegion.dstSubresource.layerCount = 0;
16602 copyRegion.dstOffset.x = 0;
16603 copyRegion.dstOffset.y = 0;
16604 copyRegion.dstOffset.z = 0;
16605 copyRegion.extent.width = 1;
16606 copyRegion.extent.height = 1;
16607 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016608 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016609 EndCommandBuffer();
16610
16611 m_errorMonitor->VerifyFound();
16612
16613 vkDestroyImage(m_device->device(), srcImage, NULL);
16614 vkDestroyImage(m_device->device(), dstImage, NULL);
16615 vkFreeMemory(m_device->device(), srcMem, NULL);
16616 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016617}
16618
Karl Schultz6addd812016-02-02 17:17:23 -070016619TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16620 VkResult err;
16621 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016622
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016623 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16625 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016626
Mike Stroyana3082432015-09-25 13:39:21 -060016627 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016628
16629 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016630 VkImage srcImage;
16631 VkImage dstImage;
16632 VkDeviceMemory srcMem;
16633 VkDeviceMemory destMem;
16634 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016635
16636 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016637 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16638 image_create_info.pNext = NULL;
16639 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16640 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16641 image_create_info.extent.width = 32;
16642 image_create_info.extent.height = 32;
16643 image_create_info.extent.depth = 1;
16644 image_create_info.mipLevels = 1;
16645 image_create_info.arrayLayers = 1;
16646 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16647 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16648 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16649 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016651 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016652 ASSERT_VK_SUCCESS(err);
16653
Karl Schultzbdb75952016-04-19 11:36:49 -060016654 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16655
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016656 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016657 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016658 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16659 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016661 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016662 ASSERT_VK_SUCCESS(err);
16663
16664 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016665 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016666 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16667 memAlloc.pNext = NULL;
16668 memAlloc.allocationSize = 0;
16669 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016670
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016671 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016672 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016673 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016674 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016675 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016676 ASSERT_VK_SUCCESS(err);
16677
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016678 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016679 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016680 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016681 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016682 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016683 ASSERT_VK_SUCCESS(err);
16684
16685 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16686 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016687 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016688 ASSERT_VK_SUCCESS(err);
16689
16690 BeginCommandBuffer();
16691 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016692 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016693 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016694 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016695 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016696 copyRegion.srcOffset.x = 0;
16697 copyRegion.srcOffset.y = 0;
16698 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016699 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016700 copyRegion.dstSubresource.mipLevel = 0;
16701 copyRegion.dstSubresource.baseArrayLayer = 0;
16702 copyRegion.dstSubresource.layerCount = 0;
16703 copyRegion.dstOffset.x = 0;
16704 copyRegion.dstOffset.y = 0;
16705 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016706 copyRegion.extent.width = 1;
16707 copyRegion.extent.height = 1;
16708 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016709 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016710 EndCommandBuffer();
16711
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016712 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016713
Chia-I Wuf7458c52015-10-26 21:10:41 +080016714 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016715 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016716 vkFreeMemory(m_device->device(), srcMem, NULL);
16717 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016718}
16719
Karl Schultz6addd812016-02-02 17:17:23 -070016720TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16721 VkResult err;
16722 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16725 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016726
Mike Stroyana3082432015-09-25 13:39:21 -060016727 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016728
16729 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016730 VkImage srcImage;
16731 VkImage dstImage;
16732 VkDeviceMemory srcMem;
16733 VkDeviceMemory destMem;
16734 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016735
16736 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016737 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16738 image_create_info.pNext = NULL;
16739 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16740 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16741 image_create_info.extent.width = 32;
16742 image_create_info.extent.height = 1;
16743 image_create_info.extent.depth = 1;
16744 image_create_info.mipLevels = 1;
16745 image_create_info.arrayLayers = 1;
16746 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16747 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16748 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16749 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016751 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016752 ASSERT_VK_SUCCESS(err);
16753
Karl Schultz6addd812016-02-02 17:17:23 -070016754 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016755
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016756 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016757 ASSERT_VK_SUCCESS(err);
16758
16759 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016760 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016761 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16762 memAlloc.pNext = NULL;
16763 memAlloc.allocationSize = 0;
16764 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016765
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016766 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016767 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016768 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016769 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016770 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016771 ASSERT_VK_SUCCESS(err);
16772
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016773 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016774 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016775 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016776 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016777 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016778 ASSERT_VK_SUCCESS(err);
16779
16780 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16781 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016782 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016783 ASSERT_VK_SUCCESS(err);
16784
16785 BeginCommandBuffer();
16786 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016787 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16788 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016789 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016790 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016791 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016792 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016793 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016794 resolveRegion.srcOffset.x = 0;
16795 resolveRegion.srcOffset.y = 0;
16796 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016797 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016798 resolveRegion.dstSubresource.mipLevel = 0;
16799 resolveRegion.dstSubresource.baseArrayLayer = 0;
16800 resolveRegion.dstSubresource.layerCount = 0;
16801 resolveRegion.dstOffset.x = 0;
16802 resolveRegion.dstOffset.y = 0;
16803 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016804 resolveRegion.extent.width = 1;
16805 resolveRegion.extent.height = 1;
16806 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016807 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016808 EndCommandBuffer();
16809
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016810 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016811
Chia-I Wuf7458c52015-10-26 21:10:41 +080016812 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016813 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016814 vkFreeMemory(m_device->device(), srcMem, NULL);
16815 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016816}
16817
Karl Schultz6addd812016-02-02 17:17:23 -070016818TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16819 VkResult err;
16820 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016821
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16823 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016824
Mike Stroyana3082432015-09-25 13:39:21 -060016825 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016826
Chris Forbesa7530692016-05-08 12:35:39 +120016827 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016828 VkImage srcImage;
16829 VkImage dstImage;
16830 VkDeviceMemory srcMem;
16831 VkDeviceMemory destMem;
16832 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016833
16834 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016835 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16836 image_create_info.pNext = NULL;
16837 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16838 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16839 image_create_info.extent.width = 32;
16840 image_create_info.extent.height = 1;
16841 image_create_info.extent.depth = 1;
16842 image_create_info.mipLevels = 1;
16843 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016844 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016845 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16846 // Note: Some implementations expect color attachment usage for any
16847 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016849 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016851 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016852 ASSERT_VK_SUCCESS(err);
16853
Karl Schultz6addd812016-02-02 17:17:23 -070016854 // Note: Some implementations expect color attachment usage for any
16855 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016856 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016858 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016859 ASSERT_VK_SUCCESS(err);
16860
16861 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016862 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016863 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16864 memAlloc.pNext = NULL;
16865 memAlloc.allocationSize = 0;
16866 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016867
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016868 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016869 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016870 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016871 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016872 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016873 ASSERT_VK_SUCCESS(err);
16874
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016875 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016876 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016877 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016878 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016879 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016880 ASSERT_VK_SUCCESS(err);
16881
16882 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16883 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016884 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016885 ASSERT_VK_SUCCESS(err);
16886
16887 BeginCommandBuffer();
16888 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016889 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16890 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016891 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016892 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016893 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016894 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016895 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016896 resolveRegion.srcOffset.x = 0;
16897 resolveRegion.srcOffset.y = 0;
16898 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016899 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016900 resolveRegion.dstSubresource.mipLevel = 0;
16901 resolveRegion.dstSubresource.baseArrayLayer = 0;
16902 resolveRegion.dstSubresource.layerCount = 0;
16903 resolveRegion.dstOffset.x = 0;
16904 resolveRegion.dstOffset.y = 0;
16905 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016906 resolveRegion.extent.width = 1;
16907 resolveRegion.extent.height = 1;
16908 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016909 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016910 EndCommandBuffer();
16911
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016912 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016913
Chia-I Wuf7458c52015-10-26 21:10:41 +080016914 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016915 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016916 vkFreeMemory(m_device->device(), srcMem, NULL);
16917 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016918}
16919
Karl Schultz6addd812016-02-02 17:17:23 -070016920TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16921 VkResult err;
16922 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16925 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016926
Mike Stroyana3082432015-09-25 13:39:21 -060016927 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016928
16929 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016930 VkImage srcImage;
16931 VkImage dstImage;
16932 VkDeviceMemory srcMem;
16933 VkDeviceMemory destMem;
16934 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016935
16936 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016937 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16938 image_create_info.pNext = NULL;
16939 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16940 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16941 image_create_info.extent.width = 32;
16942 image_create_info.extent.height = 1;
16943 image_create_info.extent.depth = 1;
16944 image_create_info.mipLevels = 1;
16945 image_create_info.arrayLayers = 1;
16946 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16947 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16948 // Note: Some implementations expect color attachment usage for any
16949 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016950 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016951 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016953 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016954 ASSERT_VK_SUCCESS(err);
16955
Karl Schultz6addd812016-02-02 17:17:23 -070016956 // Set format to something other than source image
16957 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16958 // Note: Some implementations expect color attachment usage for any
16959 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016960 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016961 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016963 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016964 ASSERT_VK_SUCCESS(err);
16965
16966 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016967 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016968 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16969 memAlloc.pNext = NULL;
16970 memAlloc.allocationSize = 0;
16971 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016972
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016973 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016974 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016975 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016976 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016977 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016978 ASSERT_VK_SUCCESS(err);
16979
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016980 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016981 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016982 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016983 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016984 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016985 ASSERT_VK_SUCCESS(err);
16986
16987 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16988 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016989 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016990 ASSERT_VK_SUCCESS(err);
16991
16992 BeginCommandBuffer();
16993 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016994 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16995 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016996 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016997 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016998 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016999 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017000 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017001 resolveRegion.srcOffset.x = 0;
17002 resolveRegion.srcOffset.y = 0;
17003 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017004 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017005 resolveRegion.dstSubresource.mipLevel = 0;
17006 resolveRegion.dstSubresource.baseArrayLayer = 0;
17007 resolveRegion.dstSubresource.layerCount = 0;
17008 resolveRegion.dstOffset.x = 0;
17009 resolveRegion.dstOffset.y = 0;
17010 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017011 resolveRegion.extent.width = 1;
17012 resolveRegion.extent.height = 1;
17013 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017014 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017015 EndCommandBuffer();
17016
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017017 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017018
Chia-I Wuf7458c52015-10-26 21:10:41 +080017019 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017020 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017021 vkFreeMemory(m_device->device(), srcMem, NULL);
17022 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017023}
17024
Karl Schultz6addd812016-02-02 17:17:23 -070017025TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17026 VkResult err;
17027 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17030 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017031
Mike Stroyana3082432015-09-25 13:39:21 -060017032 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017033
17034 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017035 VkImage srcImage;
17036 VkImage dstImage;
17037 VkDeviceMemory srcMem;
17038 VkDeviceMemory destMem;
17039 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017040
17041 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017042 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17043 image_create_info.pNext = NULL;
17044 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17045 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17046 image_create_info.extent.width = 32;
17047 image_create_info.extent.height = 1;
17048 image_create_info.extent.depth = 1;
17049 image_create_info.mipLevels = 1;
17050 image_create_info.arrayLayers = 1;
17051 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17052 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17053 // Note: Some implementations expect color attachment usage for any
17054 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017055 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017056 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017058 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017059 ASSERT_VK_SUCCESS(err);
17060
Karl Schultz6addd812016-02-02 17:17:23 -070017061 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17062 // Note: Some implementations expect color attachment usage for any
17063 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017064 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017065 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017067 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017068 ASSERT_VK_SUCCESS(err);
17069
17070 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017071 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017072 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17073 memAlloc.pNext = NULL;
17074 memAlloc.allocationSize = 0;
17075 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017076
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017077 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017078 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017079 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017080 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017081 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017082 ASSERT_VK_SUCCESS(err);
17083
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017084 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017085 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017086 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017087 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017088 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017089 ASSERT_VK_SUCCESS(err);
17090
17091 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17092 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017093 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017094 ASSERT_VK_SUCCESS(err);
17095
17096 BeginCommandBuffer();
17097 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017098 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17099 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017100 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017101 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017102 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017103 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017104 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017105 resolveRegion.srcOffset.x = 0;
17106 resolveRegion.srcOffset.y = 0;
17107 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017108 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017109 resolveRegion.dstSubresource.mipLevel = 0;
17110 resolveRegion.dstSubresource.baseArrayLayer = 0;
17111 resolveRegion.dstSubresource.layerCount = 0;
17112 resolveRegion.dstOffset.x = 0;
17113 resolveRegion.dstOffset.y = 0;
17114 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017115 resolveRegion.extent.width = 1;
17116 resolveRegion.extent.height = 1;
17117 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017118 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017119 EndCommandBuffer();
17120
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017121 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017122
Chia-I Wuf7458c52015-10-26 21:10:41 +080017123 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017124 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017125 vkFreeMemory(m_device->device(), srcMem, NULL);
17126 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017127}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017128
Karl Schultz6addd812016-02-02 17:17:23 -070017129TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017130 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017131 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17132 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017133 // The image format check comes 2nd in validation so we trigger it first,
17134 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017135 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17138 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017139
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017140 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017141
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017143 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17144 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017145
17146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17148 ds_pool_ci.pNext = NULL;
17149 ds_pool_ci.maxSets = 1;
17150 ds_pool_ci.poolSizeCount = 1;
17151 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017152
17153 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017155 ASSERT_VK_SUCCESS(err);
17156
17157 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017158 dsl_binding.binding = 0;
17159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17160 dsl_binding.descriptorCount = 1;
17161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17162 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017163
17164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17166 ds_layout_ci.pNext = NULL;
17167 ds_layout_ci.bindingCount = 1;
17168 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017169 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017171 ASSERT_VK_SUCCESS(err);
17172
17173 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017174 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017176 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017177 alloc_info.descriptorPool = ds_pool;
17178 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017180 ASSERT_VK_SUCCESS(err);
17181
Karl Schultz6addd812016-02-02 17:17:23 -070017182 VkImage image_bad;
17183 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017184 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017185 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017186 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017187 const int32_t tex_width = 32;
17188 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017189
17190 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017191 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17192 image_create_info.pNext = NULL;
17193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17194 image_create_info.format = tex_format_bad;
17195 image_create_info.extent.width = tex_width;
17196 image_create_info.extent.height = tex_height;
17197 image_create_info.extent.depth = 1;
17198 image_create_info.mipLevels = 1;
17199 image_create_info.arrayLayers = 1;
17200 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17201 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017202 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017203 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017205 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017206 ASSERT_VK_SUCCESS(err);
17207 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017208 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17209 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017210 ASSERT_VK_SUCCESS(err);
17211
17212 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017213 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17214 image_view_create_info.image = image_bad;
17215 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17216 image_view_create_info.format = tex_format_bad;
17217 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17218 image_view_create_info.subresourceRange.baseMipLevel = 0;
17219 image_view_create_info.subresourceRange.layerCount = 1;
17220 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017221 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017222
17223 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017224 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017226 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017227
Chia-I Wuf7458c52015-10-26 21:10:41 +080017228 vkDestroyImage(m_device->device(), image_bad, NULL);
17229 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017230 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17231 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017232}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017233
17234TEST_F(VkLayerTest, ClearImageErrors) {
17235 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
17236 "ClearDepthStencilImage with a color image.");
17237
17238 ASSERT_NO_FATAL_FAILURE(InitState());
17239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17240
17241 // Renderpass is started here so end it as Clear cmds can't be in renderpass
17242 BeginCommandBuffer();
17243 m_commandBuffer->EndRenderPass();
17244
17245 // Color image
17246 VkClearColorValue clear_color;
17247 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17248 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17249 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17250 const int32_t img_width = 32;
17251 const int32_t img_height = 32;
17252 VkImageCreateInfo image_create_info = {};
17253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17254 image_create_info.pNext = NULL;
17255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17256 image_create_info.format = color_format;
17257 image_create_info.extent.width = img_width;
17258 image_create_info.extent.height = img_height;
17259 image_create_info.extent.depth = 1;
17260 image_create_info.mipLevels = 1;
17261 image_create_info.arrayLayers = 1;
17262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17263 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17264 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17265
17266 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017267 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017269 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017270
17271 // Depth/Stencil image
17272 VkClearDepthStencilValue clear_value = {0};
17273 reqs = 0; // don't need HOST_VISIBLE DS image
17274 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17275 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17276 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17277 ds_image_create_info.extent.width = 64;
17278 ds_image_create_info.extent.height = 64;
17279 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17280 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
17281
17282 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017283 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017285 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 -060017286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017289 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017290 &color_range);
17291
17292 m_errorMonitor->VerifyFound();
17293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
17295 "image created without "
17296 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017298 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017299 &color_range);
17300
17301 m_errorMonitor->VerifyFound();
17302
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017303 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17305 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017307 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
17308 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017309
17310 m_errorMonitor->VerifyFound();
17311}
Tobin Ehliscde08892015-09-22 10:11:37 -060017312#endif // IMAGE_TESTS
17313
Cody Northrop1242dfd2016-07-13 17:24:59 -060017314#if defined(ANDROID) && defined(VALIDATION_APK)
17315static bool initialized = false;
17316static bool active = false;
17317
17318// Convert Intents to argv
17319// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017320std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017321 std::vector<std::string> args;
17322 JavaVM &vm = *app.activity->vm;
17323 JNIEnv *p_env;
17324 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
17325 return args;
17326
17327 JNIEnv &env = *p_env;
17328 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017329 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017330 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017331 jmethodID get_string_extra_method =
17332 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017333 jvalue get_string_extra_args;
17334 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017335 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060017336
17337 std::string args_str;
17338 if (extra_str) {
17339 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
17340 args_str = extra_utf;
17341 env.ReleaseStringUTFChars(extra_str, extra_utf);
17342 env.DeleteLocalRef(extra_str);
17343 }
17344
17345 env.DeleteLocalRef(get_string_extra_args.l);
17346 env.DeleteLocalRef(intent);
17347 vm.DetachCurrentThread();
17348
17349 // split args_str
17350 std::stringstream ss(args_str);
17351 std::string arg;
17352 while (std::getline(ss, arg, ' ')) {
17353 if (!arg.empty())
17354 args.push_back(arg);
17355 }
17356
17357 return args;
17358}
17359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017360static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017362static void processCommand(struct android_app *app, int32_t cmd) {
17363 switch (cmd) {
17364 case APP_CMD_INIT_WINDOW: {
17365 if (app->window) {
17366 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017368 break;
17369 }
17370 case APP_CMD_GAINED_FOCUS: {
17371 active = true;
17372 break;
17373 }
17374 case APP_CMD_LOST_FOCUS: {
17375 active = false;
17376 break;
17377 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017378 }
17379}
17380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017381void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017382 app_dummy();
17383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017384 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060017385
17386 int vulkanSupport = InitVulkan();
17387 if (vulkanSupport == 0) {
17388 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
17389 return;
17390 }
17391
17392 app->onAppCmd = processCommand;
17393 app->onInputEvent = processInput;
17394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017395 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017396 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017397 struct android_poll_source *source;
17398 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017399 if (source) {
17400 source->process(app, source);
17401 }
17402
17403 if (app->destroyRequested != 0) {
17404 VkTestFramework::Finish();
17405 return;
17406 }
17407 }
17408
17409 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017410 // Use the following key to send arguments to gtest, i.e.
17411 // --es args "--gtest_filter=-VkLayerTest.foo"
17412 const char key[] = "args";
17413 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017415 std::string filter = "";
17416 if (args.size() > 0) {
17417 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17418 filter += args[0];
17419 } else {
17420 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17421 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017423 int argc = 2;
17424 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17425 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017427 // Route output to files until we can override the gtest output
17428 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17429 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017431 ::testing::InitGoogleTest(&argc, argv);
17432 VkTestFramework::InitArgs(&argc, argv);
17433 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017435 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017437 if (result != 0) {
17438 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17439 } else {
17440 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17441 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017443 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017445 fclose(stdout);
17446 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017448 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017450 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017451 }
17452 }
17453}
17454#endif
17455
Tony Barbour300a6082015-04-07 13:44:53 -060017456int main(int argc, char **argv) {
17457 int result;
17458
Cody Northrop8e54a402016-03-08 22:25:52 -070017459#ifdef ANDROID
17460 int vulkanSupport = InitVulkan();
17461 if (vulkanSupport == 0)
17462 return 1;
17463#endif
17464
Tony Barbour300a6082015-04-07 13:44:53 -060017465 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017466 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017467
17468 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17469
17470 result = RUN_ALL_TESTS();
17471
Tony Barbour6918cd52015-04-09 12:58:51 -060017472 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017473 return result;
17474}