blob: a9fa83e8edd1cd485f52834a87c11081bbf149ea [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;
1815 VkDeviceMemory mem; // buffer will be bound first
1816 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001817 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001818
1819 VkBufferCreateInfo buf_info = {};
1820 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1821 buf_info.pNext = NULL;
1822 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1823 buf_info.size = 256;
1824 buf_info.queueFamilyIndexCount = 0;
1825 buf_info.pQueueFamilyIndices = NULL;
1826 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1827 buf_info.flags = 0;
1828 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1829 ASSERT_VK_SUCCESS(err);
1830
Tobin Ehlis077ded32016-05-12 17:39:13 -06001831 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001832
1833 VkImageCreateInfo image_create_info = {};
1834 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1835 image_create_info.pNext = NULL;
1836 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1837 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1838 image_create_info.extent.width = 64;
1839 image_create_info.extent.height = 64;
1840 image_create_info.extent.depth = 1;
1841 image_create_info.mipLevels = 1;
1842 image_create_info.arrayLayers = 1;
1843 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001844 // Image tiling must be optimal to trigger error when aliasing linear buffer
1845 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001846 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1847 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1848 image_create_info.queueFamilyIndexCount = 0;
1849 image_create_info.pQueueFamilyIndices = NULL;
1850 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1851 image_create_info.flags = 0;
1852
Tobin Ehlisf11be982016-05-11 13:52:53 -06001853 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1854 ASSERT_VK_SUCCESS(err);
1855
Tobin Ehlis077ded32016-05-12 17:39:13 -06001856 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1857
1858 VkMemoryAllocateInfo alloc_info = {};
1859 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1860 alloc_info.pNext = NULL;
1861 alloc_info.memoryTypeIndex = 0;
1862 // Ensure memory is big enough for both bindings
1863 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001864 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1865 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001866 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001867 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001868 vkDestroyImage(m_device->device(), image, NULL);
1869 return;
1870 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001871 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1872 ASSERT_VK_SUCCESS(err);
1873 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1874 ASSERT_VK_SUCCESS(err);
1875
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001877 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001878 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1879 m_errorMonitor->VerifyFound();
1880
1881 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001882 // aliasing buffer2
1883 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1884 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001885 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1886 ASSERT_VK_SUCCESS(err);
1887 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1888 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001890 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001891 m_errorMonitor->VerifyFound();
1892
1893 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001894 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001895 vkDestroyImage(m_device->device(), image, NULL);
1896 vkFreeMemory(m_device->device(), mem, NULL);
1897 vkFreeMemory(m_device->device(), mem_img, NULL);
1898}
1899
Tobin Ehlis35372522016-05-12 08:32:31 -06001900TEST_F(VkLayerTest, InvalidMemoryMapping) {
1901 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1902 VkResult err;
1903 bool pass;
1904 ASSERT_NO_FATAL_FAILURE(InitState());
1905
1906 VkBuffer buffer;
1907 VkDeviceMemory mem;
1908 VkMemoryRequirements mem_reqs;
1909
1910 VkBufferCreateInfo buf_info = {};
1911 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1912 buf_info.pNext = NULL;
1913 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1914 buf_info.size = 256;
1915 buf_info.queueFamilyIndexCount = 0;
1916 buf_info.pQueueFamilyIndices = NULL;
1917 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1918 buf_info.flags = 0;
1919 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1920 ASSERT_VK_SUCCESS(err);
1921
1922 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1923 VkMemoryAllocateInfo alloc_info = {};
1924 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1925 alloc_info.pNext = NULL;
1926 alloc_info.memoryTypeIndex = 0;
1927
1928 // Ensure memory is big enough for both bindings
1929 static const VkDeviceSize allocation_size = 0x10000;
1930 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001931 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 -06001932 if (!pass) {
1933 vkDestroyBuffer(m_device->device(), buffer, NULL);
1934 return;
1935 }
1936 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1937 ASSERT_VK_SUCCESS(err);
1938
1939 uint8_t *pData;
1940 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001941 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 -06001942 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1943 m_errorMonitor->VerifyFound();
1944 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001946 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1948 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1949 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001950 m_errorMonitor->VerifyFound();
1951
1952 // Unmap the memory to avoid re-map error
1953 vkUnmapMemory(m_device->device(), mem);
1954 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1956 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1957 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001958 m_errorMonitor->VerifyFound();
1959 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1961 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 m_errorMonitor->VerifyFound();
1963 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001965 vkUnmapMemory(m_device->device(), mem);
1966 m_errorMonitor->VerifyFound();
1967 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001969 ASSERT_VK_SUCCESS(err);
1970 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001971 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001972 mmr.memory = mem;
1973 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001975 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1976 m_errorMonitor->VerifyFound();
1977 // Now flush range that oversteps mapped range
1978 vkUnmapMemory(m_device->device(), mem);
1979 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1980 ASSERT_VK_SUCCESS(err);
1981 mmr.offset = 16;
1982 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001984 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1985 m_errorMonitor->VerifyFound();
1986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001987 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1988 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001989 if (!pass) {
1990 vkFreeMemory(m_device->device(), mem, NULL);
1991 vkDestroyBuffer(m_device->device(), buffer, NULL);
1992 return;
1993 }
1994 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1995 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1996
1997 vkDestroyBuffer(m_device->device(), buffer, NULL);
1998 vkFreeMemory(m_device->device(), mem, NULL);
1999}
2000
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002001TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
2002
2003 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
2004 "mapping while using VK_WHOLE_SIZE does not cause access "
2005 "violations");
2006 VkResult err;
2007 uint8_t *pData;
2008 ASSERT_NO_FATAL_FAILURE(InitState());
2009
2010 VkDeviceMemory mem;
2011 VkMemoryRequirements mem_reqs;
2012 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2013 VkMemoryAllocateInfo alloc_info = {};
2014 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2015 alloc_info.pNext = NULL;
2016 alloc_info.memoryTypeIndex = 0;
2017
2018 static const VkDeviceSize allocation_size = 0x1000;
2019 alloc_info.allocationSize = allocation_size;
2020
2021 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002022 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2023 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002024 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002025 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2026 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_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_CACHED_BIT,
2032 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002033 if (!pass) {
2034 return;
2035 }
2036 }
2037 }
2038
2039 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2040 ASSERT_VK_SUCCESS(err);
2041
2042 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2043 // mapped range
2044 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002045 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002046 ASSERT_VK_SUCCESS(err);
2047 VkMappedMemoryRange mmr = {};
2048 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2049 mmr.memory = mem;
2050 mmr.offset = 0;
2051 mmr.size = VK_WHOLE_SIZE;
2052 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2053 ASSERT_VK_SUCCESS(err);
2054 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2055 ASSERT_VK_SUCCESS(err);
2056 m_errorMonitor->VerifyNotFound();
2057 vkUnmapMemory(m_device->device(), mem);
2058
2059 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2060 // mapped range
2061 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002062 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002063 ASSERT_VK_SUCCESS(err);
2064 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2065 mmr.memory = mem;
2066 mmr.offset = 13;
2067 mmr.size = VK_WHOLE_SIZE;
2068 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2069 ASSERT_VK_SUCCESS(err);
2070 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2071 ASSERT_VK_SUCCESS(err);
2072 m_errorMonitor->VerifyNotFound();
2073 vkUnmapMemory(m_device->device(), mem);
2074
2075 // Map with prime offset and size
2076 // Flush/Invalidate subrange of mapped area with prime offset and size
2077 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002079 ASSERT_VK_SUCCESS(err);
2080 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2081 mmr.memory = mem;
2082 mmr.offset = allocation_size - 107;
2083 mmr.size = 61;
2084 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2085 ASSERT_VK_SUCCESS(err);
2086 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2087 ASSERT_VK_SUCCESS(err);
2088 m_errorMonitor->VerifyNotFound();
2089 vkUnmapMemory(m_device->device(), mem);
2090
2091 vkFreeMemory(m_device->device(), mem, NULL);
2092}
2093
Ian Elliott1c32c772016-04-28 14:47:13 -06002094TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2095 VkResult err;
2096 bool pass;
2097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002098 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2099 // following declaration (which is temporarily being moved below):
2100 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002101 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2102 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2103 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002105 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002106 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002107
2108 ASSERT_NO_FATAL_FAILURE(InitState());
2109
Ian Elliott3f06ce52016-04-29 14:46:21 -06002110#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2111#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2112 // Use the functions from the VK_KHR_android_surface extension without
2113 // enabling that extension:
2114
2115 // Create a surface:
2116 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2118 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002119 pass = (err != VK_SUCCESS);
2120 ASSERT_TRUE(pass);
2121 m_errorMonitor->VerifyFound();
2122#endif // VK_USE_PLATFORM_ANDROID_KHR
2123
Ian Elliott3f06ce52016-04-29 14:46:21 -06002124#if defined(VK_USE_PLATFORM_MIR_KHR)
2125 // Use the functions from the VK_KHR_mir_surface extension without enabling
2126 // that extension:
2127
2128 // Create a surface:
2129 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002131 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2132 pass = (err != VK_SUCCESS);
2133 ASSERT_TRUE(pass);
2134 m_errorMonitor->VerifyFound();
2135
2136 // Tell whether an mir_connection supports presentation:
2137 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2139 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002140 m_errorMonitor->VerifyFound();
2141#endif // VK_USE_PLATFORM_MIR_KHR
2142
Ian Elliott3f06ce52016-04-29 14:46:21 -06002143#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2144 // Use the functions from the VK_KHR_wayland_surface extension without
2145 // enabling that extension:
2146
2147 // Create a surface:
2148 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2150 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002151 pass = (err != VK_SUCCESS);
2152 ASSERT_TRUE(pass);
2153 m_errorMonitor->VerifyFound();
2154
2155 // Tell whether an wayland_display supports presentation:
2156 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2158 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002159 m_errorMonitor->VerifyFound();
2160#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002161#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002162
Ian Elliott3f06ce52016-04-29 14:46:21 -06002163#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002164 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2165 // TO NON-LINUX PLATFORMS:
2166 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167 // Use the functions from the VK_KHR_win32_surface extension without
2168 // enabling that extension:
2169
2170 // Create a surface:
2171 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2173 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002174 pass = (err != VK_SUCCESS);
2175 ASSERT_TRUE(pass);
2176 m_errorMonitor->VerifyFound();
2177
2178 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002180 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002181 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002182// Set this (for now, until all platforms are supported and tested):
2183#define NEED_TO_TEST_THIS_ON_PLATFORM
2184#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002185
Ian Elliott1c32c772016-04-28 14:47:13 -06002186#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002187 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2188 // TO NON-LINUX PLATFORMS:
2189 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002190 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2191 // that extension:
2192
2193 // Create a surface:
2194 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002196 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2197 pass = (err != VK_SUCCESS);
2198 ASSERT_TRUE(pass);
2199 m_errorMonitor->VerifyFound();
2200
2201 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002202 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002203 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2205 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002206 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002207// Set this (for now, until all platforms are supported and tested):
2208#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002209#endif // VK_USE_PLATFORM_XCB_KHR
2210
Ian Elliott12630812016-04-29 14:35:43 -06002211#if defined(VK_USE_PLATFORM_XLIB_KHR)
2212 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2213 // that extension:
2214
2215 // Create a surface:
2216 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002218 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2219 pass = (err != VK_SUCCESS);
2220 ASSERT_TRUE(pass);
2221 m_errorMonitor->VerifyFound();
2222
2223 // Tell whether an Xlib VisualID supports presentation:
2224 Display *dpy = NULL;
2225 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002227 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2228 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002229// Set this (for now, until all platforms are supported and tested):
2230#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002231#endif // VK_USE_PLATFORM_XLIB_KHR
2232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002233// Use the functions from the VK_KHR_surface extension without enabling
2234// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002235
Ian Elliott489eec02016-05-05 14:12:44 -06002236#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002237 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002239 vkDestroySurfaceKHR(instance(), surface, NULL);
2240 m_errorMonitor->VerifyFound();
2241
2242 // Check if surface supports presentation:
2243 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002245 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2246 pass = (err != VK_SUCCESS);
2247 ASSERT_TRUE(pass);
2248 m_errorMonitor->VerifyFound();
2249
2250 // Check surface capabilities:
2251 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2253 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002254 pass = (err != VK_SUCCESS);
2255 ASSERT_TRUE(pass);
2256 m_errorMonitor->VerifyFound();
2257
2258 // Check surface formats:
2259 uint32_t format_count = 0;
2260 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2262 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002263 pass = (err != VK_SUCCESS);
2264 ASSERT_TRUE(pass);
2265 m_errorMonitor->VerifyFound();
2266
2267 // Check surface present modes:
2268 uint32_t present_mode_count = 0;
2269 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2271 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002272 pass = (err != VK_SUCCESS);
2273 ASSERT_TRUE(pass);
2274 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002275#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002276
Ian Elliott1c32c772016-04-28 14:47:13 -06002277 // Use the functions from the VK_KHR_swapchain extension without enabling
2278 // that extension:
2279
2280 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002282 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2283 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002285 pass = (err != VK_SUCCESS);
2286 ASSERT_TRUE(pass);
2287 m_errorMonitor->VerifyFound();
2288
2289 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2291 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002292 pass = (err != VK_SUCCESS);
2293 ASSERT_TRUE(pass);
2294 m_errorMonitor->VerifyFound();
2295
Chris Forbeseb7d5502016-09-13 18:19:21 +12002296 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2297 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2298 VkFence fence;
2299 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2300
Ian Elliott1c32c772016-04-28 14:47:13 -06002301 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002303 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002304 pass = (err != VK_SUCCESS);
2305 ASSERT_TRUE(pass);
2306 m_errorMonitor->VerifyFound();
2307
Chris Forbeseb7d5502016-09-13 18:19:21 +12002308 vkDestroyFence(m_device->device(), fence, nullptr);
2309
Ian Elliott1c32c772016-04-28 14:47:13 -06002310 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002311 //
2312 // NOTE: Currently can't test this because a real swapchain is needed (as
2313 // opposed to the fake one we created) in order for the layer to lookup the
2314 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002315
2316 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002318 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2319 m_errorMonitor->VerifyFound();
2320}
2321
Ian Elliott2c1daf52016-05-12 09:41:46 -06002322TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002323
Dustin Graves6c6d8982016-05-17 10:09:21 -06002324#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002325 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002326
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002327 VkResult err;
2328 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002329 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2330 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002331 // uint32_t swapchain_image_count = 0;
2332 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2333 // uint32_t image_index = 0;
2334 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002335
2336 ASSERT_NO_FATAL_FAILURE(InitState());
2337
2338 // Use the create function from one of the VK_KHR_*_surface extension in
2339 // order to create a surface, testing all known errors in the process,
2340 // before successfully creating a surface:
2341 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002343 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2344 pass = (err != VK_SUCCESS);
2345 ASSERT_TRUE(pass);
2346 m_errorMonitor->VerifyFound();
2347
2348 // Next, try to create a surface with the wrong
2349 // VkXcbSurfaceCreateInfoKHR::sType:
2350 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2351 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002353 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2354 pass = (err != VK_SUCCESS);
2355 ASSERT_TRUE(pass);
2356 m_errorMonitor->VerifyFound();
2357
Ian Elliott2c1daf52016-05-12 09:41:46 -06002358 // Create a native window, and then correctly create a surface:
2359 xcb_connection_t *connection;
2360 xcb_screen_t *screen;
2361 xcb_window_t xcb_window;
2362 xcb_intern_atom_reply_t *atom_wm_delete_window;
2363
2364 const xcb_setup_t *setup;
2365 xcb_screen_iterator_t iter;
2366 int scr;
2367 uint32_t value_mask, value_list[32];
2368 int width = 1;
2369 int height = 1;
2370
2371 connection = xcb_connect(NULL, &scr);
2372 ASSERT_TRUE(connection != NULL);
2373 setup = xcb_get_setup(connection);
2374 iter = xcb_setup_roots_iterator(setup);
2375 while (scr-- > 0)
2376 xcb_screen_next(&iter);
2377 screen = iter.data;
2378
2379 xcb_window = xcb_generate_id(connection);
2380
2381 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2382 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002383 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002385 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2386 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002387
2388 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2390 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002392 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002393 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002394 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 -06002395 free(reply);
2396
2397 xcb_map_window(connection, xcb_window);
2398
2399 // Force the x/y coordinates to 100,100 results are identical in consecutive
2400 // runs
2401 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002402 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002403
Ian Elliott2c1daf52016-05-12 09:41:46 -06002404 // Finally, try to correctly create a surface:
2405 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2406 xcb_create_info.pNext = NULL;
2407 xcb_create_info.flags = 0;
2408 xcb_create_info.connection = connection;
2409 xcb_create_info.window = xcb_window;
2410 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2411 pass = (err == VK_SUCCESS);
2412 ASSERT_TRUE(pass);
2413
Ian Elliott2c1daf52016-05-12 09:41:46 -06002414 // Check if surface supports presentation:
2415
2416 // 1st, do so without having queried the queue families:
2417 VkBool32 supported = false;
2418 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2420 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2421 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002422 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2423 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002424 // ASSERT_TRUE(pass);
2425 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002426
2427 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2429 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430 pass = (err != VK_SUCCESS);
2431 ASSERT_TRUE(pass);
2432 m_errorMonitor->VerifyFound();
2433
2434 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002435 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2436 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002437 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2438 pass = (err == VK_SUCCESS);
2439 ASSERT_TRUE(pass);
2440
Ian Elliott2c1daf52016-05-12 09:41:46 -06002441 // Before proceeding, try to create a swapchain without having called
2442 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2443 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2444 swapchain_create_info.pNext = NULL;
2445 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2447 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2448 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002449 pass = (err != VK_SUCCESS);
2450 ASSERT_TRUE(pass);
2451 m_errorMonitor->VerifyFound();
2452
Ian Elliott2c1daf52016-05-12 09:41:46 -06002453 // Get the surface capabilities:
2454 VkSurfaceCapabilitiesKHR surface_capabilities;
2455
2456 // Do so correctly (only error logged by this entrypoint is if the
2457 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002458 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002459 pass = (err == VK_SUCCESS);
2460 ASSERT_TRUE(pass);
2461
Ian Elliott2c1daf52016-05-12 09:41:46 -06002462 // Get the surface formats:
2463 uint32_t surface_format_count;
2464
2465 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2467 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002468 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2469 pass = (err == VK_SUCCESS);
2470 ASSERT_TRUE(pass);
2471 m_errorMonitor->VerifyFound();
2472
2473 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2474 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002475 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 -06002476 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002477 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002478 pass = (err == VK_SUCCESS);
2479 ASSERT_TRUE(pass);
2480 m_errorMonitor->VerifyFound();
2481
2482 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002483 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002484 pass = (err == VK_SUCCESS);
2485 ASSERT_TRUE(pass);
2486
2487 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002488 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002489
2490 // Next, do a 2nd try with surface_format_count being set too high:
2491 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2493 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002494 pass = (err == VK_SUCCESS);
2495 ASSERT_TRUE(pass);
2496 m_errorMonitor->VerifyFound();
2497
2498 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002499 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002500 pass = (err == VK_SUCCESS);
2501 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002502 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002503 pass = (err == VK_SUCCESS);
2504 ASSERT_TRUE(pass);
2505
Ian Elliott2c1daf52016-05-12 09:41:46 -06002506 // Get the surface present modes:
2507 uint32_t surface_present_mode_count;
2508
2509 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2511 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002512
Ian Elliott2c1daf52016-05-12 09:41:46 -06002513 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2514 pass = (err == VK_SUCCESS);
2515 ASSERT_TRUE(pass);
2516 m_errorMonitor->VerifyFound();
2517
2518 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2519 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002520 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 -06002521 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2523 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002524 pass = (err == VK_SUCCESS);
2525 ASSERT_TRUE(pass);
2526 m_errorMonitor->VerifyFound();
2527
2528 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002529 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002530 pass = (err == VK_SUCCESS);
2531 ASSERT_TRUE(pass);
2532
2533 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002534 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002535
2536 // Next, do a 2nd try with surface_format_count being set too high:
2537 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2539 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002540 pass = (err == VK_SUCCESS);
2541 ASSERT_TRUE(pass);
2542 m_errorMonitor->VerifyFound();
2543
2544 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002545 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002546 pass = (err == VK_SUCCESS);
2547 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002549 pass = (err == VK_SUCCESS);
2550 ASSERT_TRUE(pass);
2551
Ian Elliott2c1daf52016-05-12 09:41:46 -06002552 // Create a swapchain:
2553
2554 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2556 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002557
Ian Elliott2c1daf52016-05-12 09:41:46 -06002558 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2559 pass = (err != VK_SUCCESS);
2560 ASSERT_TRUE(pass);
2561 m_errorMonitor->VerifyFound();
2562
2563 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2564 // sType:
2565 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002567
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002568 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002569 pass = (err != VK_SUCCESS);
2570 ASSERT_TRUE(pass);
2571 m_errorMonitor->VerifyFound();
2572
2573 // Next, call with a NULL swapchain pointer:
2574 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2575 swapchain_create_info.pNext = NULL;
2576 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2578 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002580 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002581 pass = (err != VK_SUCCESS);
2582 ASSERT_TRUE(pass);
2583 m_errorMonitor->VerifyFound();
2584
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002585 // TODO: Enhance swapchain layer so that
2586 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002587
2588 // Next, call with a queue family index that's too large:
2589 uint32_t queueFamilyIndex[2] = {100000, 0};
2590 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2591 swapchain_create_info.queueFamilyIndexCount = 2;
2592 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2594 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002595 pass = (err != VK_SUCCESS);
2596 ASSERT_TRUE(pass);
2597 m_errorMonitor->VerifyFound();
2598
2599 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2600 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2601 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2603 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2604 "pCreateInfo->pQueueFamilyIndices).");
2605 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002606 pass = (err != VK_SUCCESS);
2607 ASSERT_TRUE(pass);
2608 m_errorMonitor->VerifyFound();
2609
2610 // Next, call with an invalid imageSharingMode:
2611 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2612 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2614 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2615 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002616 pass = (err != VK_SUCCESS);
2617 ASSERT_TRUE(pass);
2618 m_errorMonitor->VerifyFound();
2619 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002620 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2621 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002622 swapchain_create_info.queueFamilyIndexCount = 0;
2623 queueFamilyIndex[0] = 0;
2624 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2625
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002626 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002627 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002628 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002629 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002630 // Destroy the swapchain:
2631
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002632 // TODOs:
2633 //
2634 // - Try destroying the device without first destroying the swapchain
2635 //
2636 // - Try destroying the device without first destroying the surface
2637 //
2638 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002639
2640 // Destroy the surface:
2641 vkDestroySurfaceKHR(instance(), surface, NULL);
2642
Ian Elliott2c1daf52016-05-12 09:41:46 -06002643 // Tear down the window:
2644 xcb_destroy_window(connection, xcb_window);
2645 xcb_disconnect(connection);
2646
2647#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002648 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002649#endif // VK_USE_PLATFORM_XCB_KHR
2650}
2651
Karl Schultz6addd812016-02-02 17:17:23 -07002652TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2653 VkResult err;
2654 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002655
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2657 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002658
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002659 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002660
2661 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002662 VkImage image;
2663 VkDeviceMemory mem;
2664 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002665
Karl Schultz6addd812016-02-02 17:17:23 -07002666 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2667 const int32_t tex_width = 32;
2668 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002669
Tony Barboureb254902015-07-15 12:50:33 -06002670 VkImageCreateInfo image_create_info = {};
2671 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002672 image_create_info.pNext = NULL;
2673 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2674 image_create_info.format = tex_format;
2675 image_create_info.extent.width = tex_width;
2676 image_create_info.extent.height = tex_height;
2677 image_create_info.extent.depth = 1;
2678 image_create_info.mipLevels = 1;
2679 image_create_info.arrayLayers = 1;
2680 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2681 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2682 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2683 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002684 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002685
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002686 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002687 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002688 mem_alloc.pNext = NULL;
2689 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002690
Chia-I Wuf7458c52015-10-26 21:10:41 +08002691 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002692 ASSERT_VK_SUCCESS(err);
2693
Karl Schultz6addd812016-02-02 17:17:23 -07002694 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002695
Mark Lobodzinski23065352015-05-29 09:32:35 -05002696 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002698 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 -07002699 if (!pass) { // If we can't find any unmappable memory this test doesn't
2700 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002701 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002702 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002703 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002704
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002705 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002706 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002707 ASSERT_VK_SUCCESS(err);
2708
2709 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002710 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002711 ASSERT_VK_SUCCESS(err);
2712
2713 // Map memory as if to initialize the image
2714 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002715 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002717 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002718
Chia-I Wuf7458c52015-10-26 21:10:41 +08002719 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002720 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002721}
2722
Karl Schultz6addd812016-02-02 17:17:23 -07002723TEST_F(VkLayerTest, RebindMemory) {
2724 VkResult err;
2725 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002728
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002729 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002730
2731 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002732 VkImage image;
2733 VkDeviceMemory mem1;
2734 VkDeviceMemory mem2;
2735 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002736
Karl Schultz6addd812016-02-02 17:17:23 -07002737 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2738 const int32_t tex_width = 32;
2739 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002740
Tony Barboureb254902015-07-15 12:50:33 -06002741 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002742 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2743 image_create_info.pNext = NULL;
2744 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2745 image_create_info.format = tex_format;
2746 image_create_info.extent.width = tex_width;
2747 image_create_info.extent.height = tex_height;
2748 image_create_info.extent.depth = 1;
2749 image_create_info.mipLevels = 1;
2750 image_create_info.arrayLayers = 1;
2751 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2752 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2753 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2754 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002755
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002756 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002757 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2758 mem_alloc.pNext = NULL;
2759 mem_alloc.allocationSize = 0;
2760 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002761
Karl Schultz6addd812016-02-02 17:17:23 -07002762 // Introduce failure, do NOT set memProps to
2763 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002764 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002765 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002766 ASSERT_VK_SUCCESS(err);
2767
Karl Schultz6addd812016-02-02 17:17:23 -07002768 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002769
2770 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002771 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002772 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002773
2774 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002775 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002776 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002777 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002778 ASSERT_VK_SUCCESS(err);
2779
2780 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002781 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002782 ASSERT_VK_SUCCESS(err);
2783
Karl Schultz6addd812016-02-02 17:17:23 -07002784 // Introduce validation failure, try to bind a different memory object to
2785 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002786 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002787
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002788 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002789
Chia-I Wuf7458c52015-10-26 21:10:41 +08002790 vkDestroyImage(m_device->device(), image, NULL);
2791 vkFreeMemory(m_device->device(), mem1, NULL);
2792 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002793}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002794
Karl Schultz6addd812016-02-02 17:17:23 -07002795TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002796 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2799 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002800
2801 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002802 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2803 fenceInfo.pNext = NULL;
2804 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002805
Tony Barbour300a6082015-04-07 13:44:53 -06002806 ASSERT_NO_FATAL_FAILURE(InitState());
2807 ASSERT_NO_FATAL_FAILURE(InitViewport());
2808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2809
Tony Barbourfe3351b2015-07-28 10:17:20 -06002810 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002812 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002813
2814 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002815
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002816 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002817 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2818 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002819 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002820 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002821 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002822 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002823 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002824 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002825 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002826
2827 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002828 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002830 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002831}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002832// This is a positive test. We used to expect error in this case but spec now
2833// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002834TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002835 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002836 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002837 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002838 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2839 fenceInfo.pNext = NULL;
2840
Tony Barbour0b4d9562015-04-09 10:48:04 -06002841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002843 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002844 VkResult result = vkResetFences(m_device->device(), 1, fences);
2845 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002846
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002847 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002848}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002849#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002850TEST_F(VkLayerTest, LongFenceChain)
2851{
2852 m_errorMonitor->ExpectSuccess();
2853
2854 ASSERT_NO_FATAL_FAILURE(InitState());
2855 VkResult err;
2856
2857 std::vector<VkFence> fences;
2858
2859 const int chainLength = 32768;
2860
2861 for (int i = 0; i < chainLength; i++) {
2862 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2863 VkFence fence;
2864 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2865 ASSERT_VK_SUCCESS(err);
2866
2867 fences.push_back(fence);
2868
2869 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2870 0, nullptr, 0, nullptr };
2871 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2872 ASSERT_VK_SUCCESS(err);
2873
2874 }
2875
2876 // BOOM, stack overflow.
2877 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2878
2879 for (auto fence : fences)
2880 vkDestroyFence(m_device->device(), fence, nullptr);
2881
2882 m_errorMonitor->VerifyNotFound();
2883}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002884#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002885TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002886 m_errorMonitor->ExpectSuccess();
2887
2888 ASSERT_NO_FATAL_FAILURE(InitState());
2889 VkResult err;
2890
2891 // Record (empty!) command buffer that can be submitted multiple times
2892 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002893 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2894 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002895 m_commandBuffer->BeginCommandBuffer(&cbbi);
2896 m_commandBuffer->EndCommandBuffer();
2897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002898 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002899 VkFence fence;
2900 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2901 ASSERT_VK_SUCCESS(err);
2902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002903 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002904 VkSemaphore s1, s2;
2905 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2906 ASSERT_VK_SUCCESS(err);
2907 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2908 ASSERT_VK_SUCCESS(err);
2909
2910 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002911 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002912 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2913 ASSERT_VK_SUCCESS(err);
2914
2915 // Submit CB again, signaling s2.
2916 si.pSignalSemaphores = &s2;
2917 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2918 ASSERT_VK_SUCCESS(err);
2919
2920 // Wait for fence.
2921 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2922 ASSERT_VK_SUCCESS(err);
2923
2924 // CB is still in flight from second submission, but semaphore s1 is no
2925 // longer in flight. delete it.
2926 vkDestroySemaphore(m_device->device(), s1, nullptr);
2927
2928 m_errorMonitor->VerifyNotFound();
2929
2930 // Force device idle and clean up remaining objects
2931 vkDeviceWaitIdle(m_device->device());
2932 vkDestroySemaphore(m_device->device(), s2, nullptr);
2933 vkDestroyFence(m_device->device(), fence, nullptr);
2934}
2935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002936TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002937 m_errorMonitor->ExpectSuccess();
2938
2939 ASSERT_NO_FATAL_FAILURE(InitState());
2940 VkResult err;
2941
2942 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002943 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002944 VkFence f1;
2945 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002949 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002950 VkFence f2;
2951 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2952 ASSERT_VK_SUCCESS(err);
2953
2954 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002955 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002956 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2957
2958 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002959 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002960 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2961
2962 // Should have both retired!
2963 vkDestroyFence(m_device->device(), f1, nullptr);
2964 vkDestroyFence(m_device->device(), f2, nullptr);
2965
2966 m_errorMonitor->VerifyNotFound();
2967}
2968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002969TEST_F(VkLayerTest, InvalidUsageBits) {
2970 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2971 "Initialize buffer with wrong usage then perform copy expecting errors "
2972 "from both the image and the buffer (2 calls)");
2973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002974
2975 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002976 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002977 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002978 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 -06002979 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002980
Tony Barbourf92621a2016-05-02 14:28:12 -06002981 VkImageView dsv;
2982 VkImageViewCreateInfo dsvci = {};
2983 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2984 dsvci.image = image.handle();
2985 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2986 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2987 dsvci.subresourceRange.layerCount = 1;
2988 dsvci.subresourceRange.baseMipLevel = 0;
2989 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002990 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002991
Tony Barbourf92621a2016-05-02 14:28:12 -06002992 // Create a view with depth / stencil aspect for image with different usage
2993 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002995 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002996
2997 // Initialize buffer with TRANSFER_DST usage
2998 vk_testing::Buffer buffer;
2999 VkMemoryPropertyFlags reqs = 0;
3000 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3001 VkBufferImageCopy region = {};
3002 region.bufferRowLength = 128;
3003 region.bufferImageHeight = 128;
3004 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3005 region.imageSubresource.layerCount = 1;
3006 region.imageExtent.height = 16;
3007 region.imageExtent.width = 16;
3008 region.imageExtent.depth = 1;
3009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003011 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3012 // TRANSFER_DST
3013 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003014 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3015 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003016 m_errorMonitor->VerifyFound();
3017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3019 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3020 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003021 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003022}
Tony Barbour75d79f02016-08-30 09:39:07 -06003023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003024TEST_F(VkLayerTest, ValidUsage) {
3025 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3026 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003027
3028 ASSERT_NO_FATAL_FAILURE(InitState());
3029
3030 m_errorMonitor->ExpectSuccess();
3031 // Verify that we can create a view with usage INPUT_ATTACHMENT
3032 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003033 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 -06003034 ASSERT_TRUE(image.initialized());
3035 VkImageView imageView;
3036 VkImageViewCreateInfo ivci = {};
3037 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3038 ivci.image = image.handle();
3039 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3040 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3041 ivci.subresourceRange.layerCount = 1;
3042 ivci.subresourceRange.baseMipLevel = 0;
3043 ivci.subresourceRange.levelCount = 1;
3044 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3045
3046 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3047 m_errorMonitor->VerifyNotFound();
3048 vkDestroyImageView(m_device->device(), imageView, NULL);
3049}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003050#endif // MEM_TRACKER_TESTS
3051
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003052#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003053
3054TEST_F(VkLayerTest, LeakAnObject) {
3055 VkResult err;
3056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003057 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003058
3059 // Note that we have to create a new device since destroying the
3060 // framework's device causes Teardown() to fail and just calling Teardown
3061 // will destroy the errorMonitor.
3062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003064
3065 ASSERT_NO_FATAL_FAILURE(InitState());
3066
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003067 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003068 std::vector<VkDeviceQueueCreateInfo> queue_info;
3069 queue_info.reserve(queue_props.size());
3070 std::vector<std::vector<float>> queue_priorities;
3071 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3072 VkDeviceQueueCreateInfo qi = {};
3073 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3074 qi.pNext = NULL;
3075 qi.queueFamilyIndex = i;
3076 qi.queueCount = queue_props[i].queueCount;
3077 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3078 qi.pQueuePriorities = queue_priorities[i].data();
3079 queue_info.push_back(qi);
3080 }
3081
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003082 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003083
3084 // The sacrificial device object
3085 VkDevice testDevice;
3086 VkDeviceCreateInfo device_create_info = {};
3087 auto features = m_device->phy().features();
3088 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3089 device_create_info.pNext = NULL;
3090 device_create_info.queueCreateInfoCount = queue_info.size();
3091 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003092 device_create_info.enabledLayerCount = 0;
3093 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003094 device_create_info.pEnabledFeatures = &features;
3095 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3096 ASSERT_VK_SUCCESS(err);
3097
3098 VkFence fence;
3099 VkFenceCreateInfo fence_create_info = {};
3100 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3101 fence_create_info.pNext = NULL;
3102 fence_create_info.flags = 0;
3103 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3104 ASSERT_VK_SUCCESS(err);
3105
3106 // Induce failure by not calling vkDestroyFence
3107 vkDestroyDevice(testDevice, NULL);
3108 m_errorMonitor->VerifyFound();
3109}
3110
3111TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3112
3113 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3114 "attempt to delete them from another.");
3115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003117
Cody Northropc31a84f2016-08-22 10:41:47 -06003118 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003119 VkCommandPool command_pool_one;
3120 VkCommandPool command_pool_two;
3121
3122 VkCommandPoolCreateInfo pool_create_info{};
3123 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3124 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3125 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003130
3131 VkCommandBuffer command_buffer[9];
3132 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003133 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003134 command_buffer_allocate_info.commandPool = command_pool_one;
3135 command_buffer_allocate_info.commandBufferCount = 9;
3136 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003139 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003140
3141 m_errorMonitor->VerifyFound();
3142
3143 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3144 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3145}
3146
3147TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3148 VkResult err;
3149
3150 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003151 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003154
3155 ASSERT_NO_FATAL_FAILURE(InitState());
3156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3157
3158 VkDescriptorPoolSize ds_type_count = {};
3159 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3160 ds_type_count.descriptorCount = 1;
3161
3162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3164 ds_pool_ci.pNext = NULL;
3165 ds_pool_ci.flags = 0;
3166 ds_pool_ci.maxSets = 1;
3167 ds_pool_ci.poolSizeCount = 1;
3168 ds_pool_ci.pPoolSizes = &ds_type_count;
3169
3170 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003172 ASSERT_VK_SUCCESS(err);
3173
3174 // Create a second descriptor pool
3175 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003176 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003177 ASSERT_VK_SUCCESS(err);
3178
3179 VkDescriptorSetLayoutBinding dsl_binding = {};
3180 dsl_binding.binding = 0;
3181 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3182 dsl_binding.descriptorCount = 1;
3183 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3184 dsl_binding.pImmutableSamplers = NULL;
3185
3186 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3187 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3188 ds_layout_ci.pNext = NULL;
3189 ds_layout_ci.bindingCount = 1;
3190 ds_layout_ci.pBindings = &dsl_binding;
3191
3192 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003194 ASSERT_VK_SUCCESS(err);
3195
3196 VkDescriptorSet descriptorSet;
3197 VkDescriptorSetAllocateInfo alloc_info = {};
3198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3199 alloc_info.descriptorSetCount = 1;
3200 alloc_info.descriptorPool = ds_pool_one;
3201 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003203 ASSERT_VK_SUCCESS(err);
3204
3205 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3206
3207 m_errorMonitor->VerifyFound();
3208
3209 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3210 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3211 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3212}
3213
3214TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003217 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003218
3219 ASSERT_NO_FATAL_FAILURE(InitState());
3220
3221 // Pass bogus handle into GetImageMemoryRequirements
3222 VkMemoryRequirements mem_reqs;
3223 uint64_t fakeImageHandle = 0xCADECADE;
3224 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3225
3226 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3227
3228 m_errorMonitor->VerifyFound();
3229}
3230
Karl Schultz6addd812016-02-02 17:17:23 -07003231TEST_F(VkLayerTest, PipelineNotBound) {
3232 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003234 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003237
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003238 ASSERT_NO_FATAL_FAILURE(InitState());
3239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003240
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003241 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003242 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3243 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
3245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3247 ds_pool_ci.pNext = NULL;
3248 ds_pool_ci.maxSets = 1;
3249 ds_pool_ci.poolSizeCount = 1;
3250 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003251
3252 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003253 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003254 ASSERT_VK_SUCCESS(err);
3255
3256 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003257 dsl_binding.binding = 0;
3258 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3259 dsl_binding.descriptorCount = 1;
3260 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3261 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003262
3263 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003264 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3265 ds_layout_ci.pNext = NULL;
3266 ds_layout_ci.bindingCount = 1;
3267 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003268
3269 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003270 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003271 ASSERT_VK_SUCCESS(err);
3272
3273 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003274 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003275 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003276 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003277 alloc_info.descriptorPool = ds_pool;
3278 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003280 ASSERT_VK_SUCCESS(err);
3281
3282 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003283 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3284 pipeline_layout_ci.pNext = NULL;
3285 pipeline_layout_ci.setLayoutCount = 1;
3286 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003287
3288 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003289 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003290 ASSERT_VK_SUCCESS(err);
3291
Mark Youngad779052016-01-06 14:26:04 -07003292 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003293
3294 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003295 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003297 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003298
Chia-I Wuf7458c52015-10-26 21:10:41 +08003299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003302}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003303
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003304TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3305 VkResult err;
3306
3307 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3308 "during bind[Buffer|Image]Memory time");
3309
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003310 ASSERT_NO_FATAL_FAILURE(InitState());
3311
3312 // Create an image, allocate memory, set a bad typeIndex and then try to
3313 // bind it
3314 VkImage image;
3315 VkDeviceMemory mem;
3316 VkMemoryRequirements mem_reqs;
3317 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3318 const int32_t tex_width = 32;
3319 const int32_t tex_height = 32;
3320
3321 VkImageCreateInfo image_create_info = {};
3322 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3323 image_create_info.pNext = NULL;
3324 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3325 image_create_info.format = tex_format;
3326 image_create_info.extent.width = tex_width;
3327 image_create_info.extent.height = tex_height;
3328 image_create_info.extent.depth = 1;
3329 image_create_info.mipLevels = 1;
3330 image_create_info.arrayLayers = 1;
3331 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3332 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3333 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3334 image_create_info.flags = 0;
3335
3336 VkMemoryAllocateInfo mem_alloc = {};
3337 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3338 mem_alloc.pNext = NULL;
3339 mem_alloc.allocationSize = 0;
3340 mem_alloc.memoryTypeIndex = 0;
3341
3342 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3343 ASSERT_VK_SUCCESS(err);
3344
3345 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3346 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003347
3348 // Introduce Failure, select invalid TypeIndex
3349 VkPhysicalDeviceMemoryProperties memory_info;
3350
3351 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3352 unsigned int i;
3353 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3354 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3355 mem_alloc.memoryTypeIndex = i;
3356 break;
3357 }
3358 }
3359 if (i >= memory_info.memoryTypeCount) {
3360 printf("No invalid memory type index could be found; skipped.\n");
3361 vkDestroyImage(m_device->device(), image, NULL);
3362 return;
3363 }
3364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003365 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 -06003366
3367 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3368 ASSERT_VK_SUCCESS(err);
3369
3370 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3371 (void)err;
3372
3373 m_errorMonitor->VerifyFound();
3374
3375 vkDestroyImage(m_device->device(), image, NULL);
3376 vkFreeMemory(m_device->device(), mem, NULL);
3377}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003378
Karl Schultz6addd812016-02-02 17:17:23 -07003379TEST_F(VkLayerTest, BindInvalidMemory) {
3380 VkResult err;
3381 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003384
Tobin Ehlisec598302015-09-15 15:02:17 -06003385 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003386
3387 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003388 VkImage image;
3389 VkDeviceMemory mem;
3390 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003391
Karl Schultz6addd812016-02-02 17:17:23 -07003392 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3393 const int32_t tex_width = 32;
3394 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003395
3396 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003397 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3398 image_create_info.pNext = NULL;
3399 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3400 image_create_info.format = tex_format;
3401 image_create_info.extent.width = tex_width;
3402 image_create_info.extent.height = tex_height;
3403 image_create_info.extent.depth = 1;
3404 image_create_info.mipLevels = 1;
3405 image_create_info.arrayLayers = 1;
3406 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3407 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3408 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3409 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003410
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003411 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003412 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3413 mem_alloc.pNext = NULL;
3414 mem_alloc.allocationSize = 0;
3415 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003416
Chia-I Wuf7458c52015-10-26 21:10:41 +08003417 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003418 ASSERT_VK_SUCCESS(err);
3419
Karl Schultz6addd812016-02-02 17:17:23 -07003420 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003421
3422 mem_alloc.allocationSize = mem_reqs.size;
3423
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003424 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003425 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003426
3427 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003428 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003429 ASSERT_VK_SUCCESS(err);
3430
3431 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003432 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003433
3434 // Try to bind free memory that has been freed
3435 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3436 // This may very well return an error.
3437 (void)err;
3438
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003439 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003440
Chia-I Wuf7458c52015-10-26 21:10:41 +08003441 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003442}
3443
Karl Schultz6addd812016-02-02 17:17:23 -07003444TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3445 VkResult err;
3446 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003449
Tobin Ehlisec598302015-09-15 15:02:17 -06003450 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003451
Karl Schultz6addd812016-02-02 17:17:23 -07003452 // Create an image object, allocate memory, destroy the object and then try
3453 // to bind it
3454 VkImage image;
3455 VkDeviceMemory mem;
3456 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003457
Karl Schultz6addd812016-02-02 17:17:23 -07003458 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3459 const int32_t tex_width = 32;
3460 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003461
3462 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003463 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3464 image_create_info.pNext = NULL;
3465 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3466 image_create_info.format = tex_format;
3467 image_create_info.extent.width = tex_width;
3468 image_create_info.extent.height = tex_height;
3469 image_create_info.extent.depth = 1;
3470 image_create_info.mipLevels = 1;
3471 image_create_info.arrayLayers = 1;
3472 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3473 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3474 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3475 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003476
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003477 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003478 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3479 mem_alloc.pNext = NULL;
3480 mem_alloc.allocationSize = 0;
3481 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003482
Chia-I Wuf7458c52015-10-26 21:10:41 +08003483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003484 ASSERT_VK_SUCCESS(err);
3485
Karl Schultz6addd812016-02-02 17:17:23 -07003486 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003487
3488 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003489 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003490 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491
3492 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003493 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003494 ASSERT_VK_SUCCESS(err);
3495
3496 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003497 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003498 ASSERT_VK_SUCCESS(err);
3499
3500 // Now Try to bind memory to this destroyed object
3501 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3502 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003503 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003504
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003505 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003506
Chia-I Wuf7458c52015-10-26 21:10:41 +08003507 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003508}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003509
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003510#endif // OBJ_TRACKER_TESTS
3511
Tobin Ehlis0788f522015-05-26 16:11:58 -06003512#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003513
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003514TEST_F(VkLayerTest, ImageSampleCounts) {
3515
3516 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3517 "validation errors.");
3518 ASSERT_NO_FATAL_FAILURE(InitState());
3519
3520 VkMemoryPropertyFlags reqs = 0;
3521 VkImageCreateInfo image_create_info = {};
3522 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3523 image_create_info.pNext = NULL;
3524 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3525 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3526 image_create_info.extent.width = 256;
3527 image_create_info.extent.height = 256;
3528 image_create_info.extent.depth = 1;
3529 image_create_info.mipLevels = 1;
3530 image_create_info.arrayLayers = 1;
3531 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3532 image_create_info.flags = 0;
3533
3534 VkImageBlit blit_region = {};
3535 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3536 blit_region.srcSubresource.baseArrayLayer = 0;
3537 blit_region.srcSubresource.layerCount = 1;
3538 blit_region.srcSubresource.mipLevel = 0;
3539 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3540 blit_region.dstSubresource.baseArrayLayer = 0;
3541 blit_region.dstSubresource.layerCount = 1;
3542 blit_region.dstSubresource.mipLevel = 0;
3543
3544 // Create two images, the source with sampleCount = 2, and attempt to blit
3545 // between them
3546 {
3547 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003548 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003549 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003552 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003553 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003555 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3557 "of VK_SAMPLE_COUNT_2_BIT but "
3558 "must be VK_SAMPLE_COUNT_1_BIT");
3559 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3560 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003561 m_errorMonitor->VerifyFound();
3562 m_commandBuffer->EndCommandBuffer();
3563 }
3564
3565 // Create two images, the dest with sampleCount = 4, and attempt to blit
3566 // between them
3567 {
3568 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003570 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003572 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003574 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003576 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3578 "of VK_SAMPLE_COUNT_4_BIT but "
3579 "must be VK_SAMPLE_COUNT_1_BIT");
3580 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3581 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003582 m_errorMonitor->VerifyFound();
3583 m_commandBuffer->EndCommandBuffer();
3584 }
3585
3586 VkBufferImageCopy copy_region = {};
3587 copy_region.bufferRowLength = 128;
3588 copy_region.bufferImageHeight = 128;
3589 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3590 copy_region.imageSubresource.layerCount = 1;
3591 copy_region.imageExtent.height = 64;
3592 copy_region.imageExtent.width = 64;
3593 copy_region.imageExtent.depth = 1;
3594
3595 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3596 // buffer to image
3597 {
3598 vk_testing::Buffer src_buffer;
3599 VkMemoryPropertyFlags reqs = 0;
3600 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3601 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003602 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003603 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003604 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003605 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3607 "of VK_SAMPLE_COUNT_8_BIT but "
3608 "must be VK_SAMPLE_COUNT_1_BIT");
3609 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3610 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003611 m_errorMonitor->VerifyFound();
3612 m_commandBuffer->EndCommandBuffer();
3613 }
3614
3615 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3616 // image to buffer
3617 {
3618 vk_testing::Buffer dst_buffer;
3619 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3620 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003622 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003623 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003624 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3626 "of VK_SAMPLE_COUNT_2_BIT but "
3627 "must be VK_SAMPLE_COUNT_1_BIT");
3628 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003629 dst_buffer.handle(), 1, &copy_region);
3630 m_errorMonitor->VerifyFound();
3631 m_commandBuffer->EndCommandBuffer();
3632 }
3633}
3634
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003635TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3636 VkResult err;
3637 bool pass;
3638
3639 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3640 ASSERT_NO_FATAL_FAILURE(InitState());
3641
3642 // If w/d/h granularity is 1, test is not meaningful
3643 // TODO: When virtual device limits are available, create a set of limits for this test that
3644 // will always have a granularity of > 1 for w, h, and d
3645 auto index = m_device->graphics_queue_node_index_;
3646 auto queue_family_properties = m_device->phy().queue_properties();
3647
3648 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3649 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3650 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3651 return;
3652 }
3653
3654 // Create two images of different types and try to copy between them
3655 VkImage srcImage;
3656 VkImage dstImage;
3657 VkDeviceMemory srcMem;
3658 VkDeviceMemory destMem;
3659 VkMemoryRequirements memReqs;
3660
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003661 VkImageCreateInfo image_create_info = {};
3662 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3663 image_create_info.pNext = NULL;
3664 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3665 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3666 image_create_info.extent.width = 32;
3667 image_create_info.extent.height = 32;
3668 image_create_info.extent.depth = 1;
3669 image_create_info.mipLevels = 1;
3670 image_create_info.arrayLayers = 4;
3671 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3672 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3673 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3674 image_create_info.flags = 0;
3675
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003676 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003677 ASSERT_VK_SUCCESS(err);
3678
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003679 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003680 ASSERT_VK_SUCCESS(err);
3681
3682 // Allocate memory
3683 VkMemoryAllocateInfo memAlloc = {};
3684 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3685 memAlloc.pNext = NULL;
3686 memAlloc.allocationSize = 0;
3687 memAlloc.memoryTypeIndex = 0;
3688
3689 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3690 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003692 ASSERT_TRUE(pass);
3693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3694 ASSERT_VK_SUCCESS(err);
3695
3696 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3697 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003698 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003699 ASSERT_VK_SUCCESS(err);
3700 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3701 ASSERT_VK_SUCCESS(err);
3702
3703 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3704 ASSERT_VK_SUCCESS(err);
3705 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3706 ASSERT_VK_SUCCESS(err);
3707
3708 BeginCommandBuffer();
3709 VkImageCopy copyRegion;
3710 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3711 copyRegion.srcSubresource.mipLevel = 0;
3712 copyRegion.srcSubresource.baseArrayLayer = 0;
3713 copyRegion.srcSubresource.layerCount = 1;
3714 copyRegion.srcOffset.x = 0;
3715 copyRegion.srcOffset.y = 0;
3716 copyRegion.srcOffset.z = 0;
3717 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3718 copyRegion.dstSubresource.mipLevel = 0;
3719 copyRegion.dstSubresource.baseArrayLayer = 0;
3720 copyRegion.dstSubresource.layerCount = 1;
3721 copyRegion.dstOffset.x = 0;
3722 copyRegion.dstOffset.y = 0;
3723 copyRegion.dstOffset.z = 0;
3724 copyRegion.extent.width = 1;
3725 copyRegion.extent.height = 1;
3726 copyRegion.extent.depth = 1;
3727
3728 // Introduce failure by setting srcOffset to a bad granularity value
3729 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3731 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003732 m_errorMonitor->VerifyFound();
3733
3734 // Introduce failure by setting extent to a bad granularity value
3735 copyRegion.srcOffset.y = 0;
3736 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3738 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003739 m_errorMonitor->VerifyFound();
3740
3741 // Now do some buffer/image copies
3742 vk_testing::Buffer buffer;
3743 VkMemoryPropertyFlags reqs = 0;
3744 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3745 VkBufferImageCopy region = {};
3746 region.bufferOffset = 0;
3747 region.bufferRowLength = 3;
3748 region.bufferImageHeight = 128;
3749 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3750 region.imageSubresource.layerCount = 1;
3751 region.imageExtent.height = 16;
3752 region.imageExtent.width = 16;
3753 region.imageExtent.depth = 1;
3754 region.imageOffset.x = 0;
3755 region.imageOffset.y = 0;
3756 region.imageOffset.z = 0;
3757
3758 // Introduce failure by setting bufferRowLength to a bad granularity value
3759 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3761 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3762 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003763 m_errorMonitor->VerifyFound();
3764 region.bufferRowLength = 128;
3765
3766 // Introduce failure by setting bufferOffset to a bad granularity value
3767 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3769 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3770 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003771 m_errorMonitor->VerifyFound();
3772 region.bufferOffset = 0;
3773
3774 // Introduce failure by setting bufferImageHeight to a bad granularity value
3775 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3777 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3778 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003779 m_errorMonitor->VerifyFound();
3780 region.bufferImageHeight = 128;
3781
3782 // Introduce failure by setting imageExtent to a bad granularity value
3783 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3785 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3786 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003787 m_errorMonitor->VerifyFound();
3788 region.imageExtent.width = 16;
3789
3790 // Introduce failure by setting imageOffset to a bad granularity value
3791 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3793 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3794 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003795 m_errorMonitor->VerifyFound();
3796
3797 EndCommandBuffer();
3798
3799 vkDestroyImage(m_device->device(), srcImage, NULL);
3800 vkDestroyImage(m_device->device(), dstImage, NULL);
3801 vkFreeMemory(m_device->device(), srcMem, NULL);
3802 vkFreeMemory(m_device->device(), destMem, NULL);
3803}
3804
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003805TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003806 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3807 "attempt to submit them on a queue created in a different "
3808 "queue family.");
3809
Cody Northropc31a84f2016-08-22 10:41:47 -06003810 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003811 // This test is meaningless unless we have multiple queue families
3812 auto queue_family_properties = m_device->phy().queue_properties();
3813 if (queue_family_properties.size() < 2) {
3814 return;
3815 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003817 // Get safe index of another queue family
3818 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3819 ASSERT_NO_FATAL_FAILURE(InitState());
3820 // Create a second queue using a different queue family
3821 VkQueue other_queue;
3822 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3823
3824 // Record an empty cmd buffer
3825 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3826 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3827 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3828 vkEndCommandBuffer(m_commandBuffer->handle());
3829
3830 // And submit on the wrong queue
3831 VkSubmitInfo submit_info = {};
3832 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3833 submit_info.commandBufferCount = 1;
3834 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003835 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003836
3837 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003838}
3839
Chris Forbes48a53902016-06-30 11:46:27 +12003840TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3841 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3842 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3843 "the command buffer has prior knowledge of that "
3844 "attachment's layout.");
3845
3846 m_errorMonitor->ExpectSuccess();
3847
3848 ASSERT_NO_FATAL_FAILURE(InitState());
3849
3850 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003851 VkAttachmentDescription attachment = {0,
3852 VK_FORMAT_R8G8B8A8_UNORM,
3853 VK_SAMPLE_COUNT_1_BIT,
3854 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3855 VK_ATTACHMENT_STORE_OP_STORE,
3856 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3857 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3858 VK_IMAGE_LAYOUT_UNDEFINED,
3859 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003861 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003863 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003865 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003866
3867 VkRenderPass rp;
3868 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3869 ASSERT_VK_SUCCESS(err);
3870
3871 // A compatible framebuffer.
3872 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003873 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 +12003874 ASSERT_TRUE(image.initialized());
3875
3876 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003877 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3878 nullptr,
3879 0,
3880 image.handle(),
3881 VK_IMAGE_VIEW_TYPE_2D,
3882 VK_FORMAT_R8G8B8A8_UNORM,
3883 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3884 VK_COMPONENT_SWIZZLE_IDENTITY},
3885 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003886 };
3887 VkImageView view;
3888 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3889 ASSERT_VK_SUCCESS(err);
3890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003891 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003892 VkFramebuffer fb;
3893 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3894 ASSERT_VK_SUCCESS(err);
3895
3896 // Record a single command buffer which uses this renderpass twice. The
3897 // bug is triggered at the beginning of the second renderpass, when the
3898 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003899 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 +12003900 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003901 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003902 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003903 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003904
3905 m_errorMonitor->VerifyNotFound();
3906
3907 vkCmdEndRenderPass(m_commandBuffer->handle());
3908 EndCommandBuffer();
3909
3910 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3911 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3912 vkDestroyImageView(m_device->device(), view, nullptr);
3913}
3914
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003915TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3916 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3917 "command buffer, bind them together, then destroy "
3918 "command pool and framebuffer and verify there are no "
3919 "errors.");
3920
3921 m_errorMonitor->ExpectSuccess();
3922
3923 ASSERT_NO_FATAL_FAILURE(InitState());
3924
3925 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003926 VkAttachmentDescription attachment = {0,
3927 VK_FORMAT_R8G8B8A8_UNORM,
3928 VK_SAMPLE_COUNT_1_BIT,
3929 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3930 VK_ATTACHMENT_STORE_OP_STORE,
3931 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3932 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3933 VK_IMAGE_LAYOUT_UNDEFINED,
3934 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003936 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003940 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003941
3942 VkRenderPass rp;
3943 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3944 ASSERT_VK_SUCCESS(err);
3945
3946 // A compatible framebuffer.
3947 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003948 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 -06003949 ASSERT_TRUE(image.initialized());
3950
3951 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003952 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3953 nullptr,
3954 0,
3955 image.handle(),
3956 VK_IMAGE_VIEW_TYPE_2D,
3957 VK_FORMAT_R8G8B8A8_UNORM,
3958 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3959 VK_COMPONENT_SWIZZLE_IDENTITY},
3960 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003961 };
3962 VkImageView view;
3963 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3964 ASSERT_VK_SUCCESS(err);
3965
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003966 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003967 VkFramebuffer fb;
3968 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3969 ASSERT_VK_SUCCESS(err);
3970
3971 // Explicitly create a command buffer to bind the FB to so that we can then
3972 // destroy the command pool in order to implicitly free command buffer
3973 VkCommandPool command_pool;
3974 VkCommandPoolCreateInfo pool_create_info{};
3975 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3976 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3977 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003978 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003979
3980 VkCommandBuffer command_buffer;
3981 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003983 command_buffer_allocate_info.commandPool = command_pool;
3984 command_buffer_allocate_info.commandBufferCount = 1;
3985 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003986 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003987
3988 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003989 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 -06003990 VkCommandBufferBeginInfo begin_info{};
3991 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3992 vkBeginCommandBuffer(command_buffer, &begin_info);
3993
3994 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3995 vkCmdEndRenderPass(command_buffer);
3996 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06003997 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003998 // Destroy command pool to implicitly free command buffer
3999 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4000 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4001 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4002 m_errorMonitor->VerifyNotFound();
4003}
4004
Chris Forbes51bf7c92016-06-30 15:22:08 +12004005TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
4006 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4007 "transitions for the first subpass");
4008
4009 m_errorMonitor->ExpectSuccess();
4010
4011 ASSERT_NO_FATAL_FAILURE(InitState());
4012
4013 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004014 VkAttachmentDescription attachment = {0,
4015 VK_FORMAT_R8G8B8A8_UNORM,
4016 VK_SAMPLE_COUNT_1_BIT,
4017 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4018 VK_ATTACHMENT_STORE_OP_STORE,
4019 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4020 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4021 VK_IMAGE_LAYOUT_UNDEFINED,
4022 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004024 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004026 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004028 VkSubpassDependency dep = {0,
4029 0,
4030 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4031 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4032 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4033 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4034 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004035
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004036 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004037
4038 VkResult err;
4039 VkRenderPass rp;
4040 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4041 ASSERT_VK_SUCCESS(err);
4042
4043 // A compatible framebuffer.
4044 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004045 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 +12004046 ASSERT_TRUE(image.initialized());
4047
4048 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004049 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4050 nullptr,
4051 0,
4052 image.handle(),
4053 VK_IMAGE_VIEW_TYPE_2D,
4054 VK_FORMAT_R8G8B8A8_UNORM,
4055 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4056 VK_COMPONENT_SWIZZLE_IDENTITY},
4057 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004058 };
4059 VkImageView view;
4060 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4061 ASSERT_VK_SUCCESS(err);
4062
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004063 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004064 VkFramebuffer fb;
4065 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4066 ASSERT_VK_SUCCESS(err);
4067
4068 // Record a single command buffer which issues a pipeline barrier w/
4069 // image memory barrier for the attachment. This detects the previously
4070 // missing tracking of the subpass layout by throwing a validation error
4071 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004072 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 +12004073 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004074 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004076 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4077 nullptr,
4078 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4079 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4080 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4081 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4082 VK_QUEUE_FAMILY_IGNORED,
4083 VK_QUEUE_FAMILY_IGNORED,
4084 image.handle(),
4085 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4086 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4087 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4088 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004089
4090 vkCmdEndRenderPass(m_commandBuffer->handle());
4091 m_errorMonitor->VerifyNotFound();
4092 EndCommandBuffer();
4093
4094 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4095 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4096 vkDestroyImageView(m_device->device(), view, nullptr);
4097}
4098
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004099TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4100 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4101 "is used as a depth/stencil framebuffer attachment, the "
4102 "aspectMask is ignored and both depth and stencil image "
4103 "subresources are used.");
4104
4105 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004106 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4107 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004108 return;
4109 }
4110
4111 m_errorMonitor->ExpectSuccess();
4112
4113 ASSERT_NO_FATAL_FAILURE(InitState());
4114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004115 VkAttachmentDescription attachment = {0,
4116 VK_FORMAT_D32_SFLOAT_S8_UINT,
4117 VK_SAMPLE_COUNT_1_BIT,
4118 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4119 VK_ATTACHMENT_STORE_OP_STORE,
4120 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4121 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4122 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4123 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004125 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004127 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004128
4129 VkSubpassDependency dep = {0,
4130 0,
4131 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4132 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4133 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4134 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4135 VK_DEPENDENCY_BY_REGION_BIT};
4136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004137 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004138
4139 VkResult err;
4140 VkRenderPass rp;
4141 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4142 ASSERT_VK_SUCCESS(err);
4143
4144 VkImageObj image(m_device);
4145 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4146 0x26, // usage
4147 VK_IMAGE_TILING_OPTIMAL, 0);
4148 ASSERT_TRUE(image.initialized());
4149 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4150
4151 VkImageViewCreateInfo ivci = {
4152 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4153 nullptr,
4154 0,
4155 image.handle(),
4156 VK_IMAGE_VIEW_TYPE_2D,
4157 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004159 {0x2, 0, 1, 0, 1},
4160 };
4161 VkImageView view;
4162 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4163 ASSERT_VK_SUCCESS(err);
4164
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004166 VkFramebuffer fb;
4167 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4168 ASSERT_VK_SUCCESS(err);
4169
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004170 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 -06004171 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004172 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004173
4174 VkImageMemoryBarrier imb = {};
4175 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4176 imb.pNext = nullptr;
4177 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4178 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4179 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4180 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4181 imb.srcQueueFamilyIndex = 0;
4182 imb.dstQueueFamilyIndex = 0;
4183 imb.image = image.handle();
4184 imb.subresourceRange.aspectMask = 0x6;
4185 imb.subresourceRange.baseMipLevel = 0;
4186 imb.subresourceRange.levelCount = 0x1;
4187 imb.subresourceRange.baseArrayLayer = 0;
4188 imb.subresourceRange.layerCount = 0x1;
4189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4191 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004192 &imb);
4193
4194 vkCmdEndRenderPass(m_commandBuffer->handle());
4195 EndCommandBuffer();
4196 QueueCommandBuffer(false);
4197 m_errorMonitor->VerifyNotFound();
4198
4199 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4200 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4201 vkDestroyImageView(m_device->device(), view, nullptr);
4202}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004203
Tony Barbour4e919972016-08-09 13:27:40 -06004204TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4205 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4206 "with extent outside of framebuffer");
4207 ASSERT_NO_FATAL_FAILURE(InitState());
4208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4211 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004212
4213 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4214 m_renderPassBeginInfo.renderArea.extent.width = 257;
4215 m_renderPassBeginInfo.renderArea.extent.height = 257;
4216 BeginCommandBuffer();
4217 m_errorMonitor->VerifyFound();
4218}
4219
4220TEST_F(VkLayerTest, DisabledIndependentBlend) {
4221 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4222 "blend and then specifying different blend states for two "
4223 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004224 VkPhysicalDeviceFeatures features = {};
4225 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004226 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4229 "Invalid Pipeline CreateInfo: If independent blend feature not "
4230 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004231
Cody Northropc31a84f2016-08-22 10:41:47 -06004232 VkDescriptorSetObj descriptorSet(m_device);
4233 descriptorSet.AppendDummy();
4234 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004235
Cody Northropc31a84f2016-08-22 10:41:47 -06004236 VkPipelineObj pipeline(m_device);
4237 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004238 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004239 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004240
Cody Northropc31a84f2016-08-22 10:41:47 -06004241 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4242 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4243 att_state1.blendEnable = VK_TRUE;
4244 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4245 att_state2.blendEnable = VK_FALSE;
4246 pipeline.AddColorAttachment(0, &att_state1);
4247 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004248 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004249 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004250}
4251
4252TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4253 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4254 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004255 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4258 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004259
4260 // Create a renderPass with a single color attachment
4261 VkAttachmentReference attach = {};
4262 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4263 VkSubpassDescription subpass = {};
4264 VkRenderPassCreateInfo rpci = {};
4265 rpci.subpassCount = 1;
4266 rpci.pSubpasses = &subpass;
4267 rpci.attachmentCount = 1;
4268 VkAttachmentDescription attach_desc = {};
4269 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4270 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4271 rpci.pAttachments = &attach_desc;
4272 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4273 VkRenderPass rp;
4274 subpass.pDepthStencilAttachment = &attach;
4275 subpass.pColorAttachments = NULL;
4276 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4277 m_errorMonitor->VerifyFound();
4278}
4279
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004280TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4281 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4282 "errors, when an attachment reference is "
4283 "VK_ATTACHMENT_UNUSED");
4284
4285 m_errorMonitor->ExpectSuccess();
4286
4287 ASSERT_NO_FATAL_FAILURE(InitState());
4288
4289 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004290 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004291
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004292 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004293
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295
4296 VkRenderPass rp;
4297 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4298 ASSERT_VK_SUCCESS(err);
4299
4300 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004301 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004302 VkFramebuffer fb;
4303 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4304 ASSERT_VK_SUCCESS(err);
4305
4306 // Record a command buffer which just begins and ends the renderpass. The
4307 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004308 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 +12004309 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004310 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004311 vkCmdEndRenderPass(m_commandBuffer->handle());
4312 m_errorMonitor->VerifyNotFound();
4313 EndCommandBuffer();
4314
4315 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4316 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4317}
4318
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004319// This is a positive test. No errors are expected.
4320TEST_F(VkLayerTest, StencilLoadOp) {
4321 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4322 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4323 VkResult result = VK_SUCCESS;
4324 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004325 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4326 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4327 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004328 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4329 return;
4330 }
4331
4332 ASSERT_NO_FATAL_FAILURE(InitState());
4333 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4334 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004335 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004336 VkAttachmentDescription att = {};
4337 VkAttachmentReference ref = {};
4338 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004339 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004340 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4341 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4342 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4343 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4344 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4345 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4346
4347 VkClearValue clear;
4348 clear.depthStencil.depth = 1.0;
4349 clear.depthStencil.stencil = 0;
4350 ref.attachment = 0;
4351 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4352
4353 VkSubpassDescription subpass = {};
4354 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4355 subpass.flags = 0;
4356 subpass.inputAttachmentCount = 0;
4357 subpass.pInputAttachments = NULL;
4358 subpass.colorAttachmentCount = 0;
4359 subpass.pColorAttachments = NULL;
4360 subpass.pResolveAttachments = NULL;
4361 subpass.pDepthStencilAttachment = &ref;
4362 subpass.preserveAttachmentCount = 0;
4363 subpass.pPreserveAttachments = NULL;
4364
4365 VkRenderPass rp;
4366 VkRenderPassCreateInfo rp_info = {};
4367 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4368 rp_info.attachmentCount = 1;
4369 rp_info.pAttachments = &att;
4370 rp_info.subpassCount = 1;
4371 rp_info.pSubpasses = &subpass;
4372 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4373 ASSERT_VK_SUCCESS(result);
4374
4375 VkImageView *depthView = m_depthStencil->BindInfo();
4376 VkFramebufferCreateInfo fb_info = {};
4377 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4378 fb_info.pNext = NULL;
4379 fb_info.renderPass = rp;
4380 fb_info.attachmentCount = 1;
4381 fb_info.pAttachments = depthView;
4382 fb_info.width = 100;
4383 fb_info.height = 100;
4384 fb_info.layers = 1;
4385 VkFramebuffer fb;
4386 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4387 ASSERT_VK_SUCCESS(result);
4388
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004389 VkRenderPassBeginInfo rpbinfo = {};
4390 rpbinfo.clearValueCount = 1;
4391 rpbinfo.pClearValues = &clear;
4392 rpbinfo.pNext = NULL;
4393 rpbinfo.renderPass = rp;
4394 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4395 rpbinfo.renderArea.extent.width = 100;
4396 rpbinfo.renderArea.extent.height = 100;
4397 rpbinfo.renderArea.offset.x = 0;
4398 rpbinfo.renderArea.offset.y = 0;
4399 rpbinfo.framebuffer = fb;
4400
4401 VkFence fence = {};
4402 VkFenceCreateInfo fence_ci = {};
4403 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4404 fence_ci.pNext = nullptr;
4405 fence_ci.flags = 0;
4406 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4407 ASSERT_VK_SUCCESS(result);
4408
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004409 m_commandBuffer->BeginCommandBuffer();
4410 m_commandBuffer->BeginRenderPass(rpbinfo);
4411 m_commandBuffer->EndRenderPass();
4412 m_commandBuffer->EndCommandBuffer();
4413 m_commandBuffer->QueueCommandBuffer(fence);
4414
4415 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004416 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 -06004417 VK_IMAGE_TILING_OPTIMAL, 0);
4418 VkImageMemoryBarrier barrier = {};
4419 VkImageSubresourceRange range;
4420 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004421 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4422 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004423 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4424 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4425 barrier.image = m_depthStencil->handle();
4426 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4427 range.baseMipLevel = 0;
4428 range.levelCount = 1;
4429 range.baseArrayLayer = 0;
4430 range.layerCount = 1;
4431 barrier.subresourceRange = range;
4432 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4433 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4434 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004435 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4436 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004437 barrier.srcAccessMask = 0;
4438 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4439 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4440 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004441 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4442 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4443 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004444 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004446 cregion.srcSubresource.mipLevel = 0;
4447 cregion.srcSubresource.baseArrayLayer = 0;
4448 cregion.srcSubresource.layerCount = 1;
4449 cregion.srcOffset.x = 0;
4450 cregion.srcOffset.y = 0;
4451 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004452 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004453 cregion.dstSubresource.mipLevel = 0;
4454 cregion.dstSubresource.baseArrayLayer = 0;
4455 cregion.dstSubresource.layerCount = 1;
4456 cregion.dstOffset.x = 0;
4457 cregion.dstOffset.y = 0;
4458 cregion.dstOffset.z = 0;
4459 cregion.extent.width = 100;
4460 cregion.extent.height = 100;
4461 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004462 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004463 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4464 cmdbuf.EndCommandBuffer();
4465
4466 VkSubmitInfo submit_info;
4467 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4468 submit_info.pNext = NULL;
4469 submit_info.waitSemaphoreCount = 0;
4470 submit_info.pWaitSemaphores = NULL;
4471 submit_info.pWaitDstStageMask = NULL;
4472 submit_info.commandBufferCount = 1;
4473 submit_info.pCommandBuffers = &cmdbuf.handle();
4474 submit_info.signalSemaphoreCount = 0;
4475 submit_info.pSignalSemaphores = NULL;
4476
4477 m_errorMonitor->ExpectSuccess();
4478 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4479 m_errorMonitor->VerifyNotFound();
4480
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004481 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004482 vkDestroyFence(m_device->device(), fence, nullptr);
4483 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4484 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4485}
4486
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004487TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4488 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4489 "attachment reference of VK_ATTACHMENT_UNUSED");
4490
4491 ASSERT_NO_FATAL_FAILURE(InitState());
4492 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4493
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004495
4496 VkAttachmentReference color_attach = {};
4497 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4498 color_attach.attachment = 0;
4499 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4500 VkSubpassDescription subpass = {};
4501 subpass.colorAttachmentCount = 1;
4502 subpass.pColorAttachments = &color_attach;
4503 subpass.preserveAttachmentCount = 1;
4504 subpass.pPreserveAttachments = &preserve_attachment;
4505
4506 VkRenderPassCreateInfo rpci = {};
4507 rpci.subpassCount = 1;
4508 rpci.pSubpasses = &subpass;
4509 rpci.attachmentCount = 1;
4510 VkAttachmentDescription attach_desc = {};
4511 attach_desc.format = VK_FORMAT_UNDEFINED;
4512 rpci.pAttachments = &attach_desc;
4513 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4514 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004515 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004516
4517 m_errorMonitor->VerifyFound();
4518
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004519 if (result == VK_SUCCESS) {
4520 vkDestroyRenderPass(m_device->device(), rp, NULL);
4521 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004522}
4523
Chris Forbesc5389742016-06-29 11:49:23 +12004524TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004525 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4526 "when the source of a subpass multisample resolve "
4527 "does not have multiple samples.");
4528
Chris Forbesc5389742016-06-29 11:49:23 +12004529 ASSERT_NO_FATAL_FAILURE(InitState());
4530
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4532 "Subpass 0 requests multisample resolve from attachment 0 which has "
4533 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004534
4535 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004536 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4537 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4538 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4539 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4540 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4541 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004542 };
4543
4544 VkAttachmentReference color = {
4545 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4546 };
4547
4548 VkAttachmentReference resolve = {
4549 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4550 };
4551
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004552 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004553
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004554 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004555
4556 VkRenderPass rp;
4557 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4558
4559 m_errorMonitor->VerifyFound();
4560
4561 if (err == VK_SUCCESS)
4562 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4563}
4564
4565TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004566 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4567 "when a subpass multisample resolve operation is "
4568 "requested, and the destination of that resolve has "
4569 "multiple samples.");
4570
Chris Forbesc5389742016-06-29 11:49:23 +12004571 ASSERT_NO_FATAL_FAILURE(InitState());
4572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4574 "Subpass 0 requests multisample resolve into attachment 1, which "
4575 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004576
4577 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004578 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4579 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4580 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4581 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4582 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4583 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004584 };
4585
4586 VkAttachmentReference color = {
4587 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4588 };
4589
4590 VkAttachmentReference resolve = {
4591 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4592 };
4593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004594 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004596 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004597
4598 VkRenderPass rp;
4599 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4600
4601 m_errorMonitor->VerifyFound();
4602
4603 if (err == VK_SUCCESS)
4604 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4605}
4606
Chris Forbes3f128ef2016-06-29 14:58:53 +12004607TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004608 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4609 "when the color and depth attachments used by a subpass "
4610 "have inconsistent sample counts");
4611
Chris Forbes3f128ef2016-06-29 14:58:53 +12004612 ASSERT_NO_FATAL_FAILURE(InitState());
4613
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4615 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004616
4617 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004618 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4619 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4620 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4621 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4622 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4623 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004624 };
4625
4626 VkAttachmentReference color[] = {
4627 {
4628 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4629 },
4630 {
4631 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4632 },
4633 };
4634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004635 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004637 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004638
4639 VkRenderPass rp;
4640 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4641
4642 m_errorMonitor->VerifyFound();
4643
4644 if (err == VK_SUCCESS)
4645 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4646}
4647
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004648TEST_F(VkLayerTest, FramebufferCreateErrors) {
4649 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4650 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004651 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004652 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004653 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004654 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004655 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004656 " 7. FB attachment w/o identity swizzle\n"
4657 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004658
4659 ASSERT_NO_FATAL_FAILURE(InitState());
4660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4663 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4664 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004665
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004666 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004667 VkAttachmentReference attach = {};
4668 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4669 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004670 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004671 VkRenderPassCreateInfo rpci = {};
4672 rpci.subpassCount = 1;
4673 rpci.pSubpasses = &subpass;
4674 rpci.attachmentCount = 1;
4675 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004676 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004677 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004678 rpci.pAttachments = &attach_desc;
4679 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4680 VkRenderPass rp;
4681 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4682 ASSERT_VK_SUCCESS(err);
4683
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004684 VkImageView ivs[2];
4685 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4686 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004687 VkFramebufferCreateInfo fb_info = {};
4688 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4689 fb_info.pNext = NULL;
4690 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004691 // Set mis-matching attachmentCount
4692 fb_info.attachmentCount = 2;
4693 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004694 fb_info.width = 100;
4695 fb_info.height = 100;
4696 fb_info.layers = 1;
4697
4698 VkFramebuffer fb;
4699 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4700
4701 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004702 if (err == VK_SUCCESS) {
4703 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4704 }
4705 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004706
4707 // Create a renderPass with a depth-stencil attachment created with
4708 // IMAGE_USAGE_COLOR_ATTACHMENT
4709 // Add our color attachment to pDepthStencilAttachment
4710 subpass.pDepthStencilAttachment = &attach;
4711 subpass.pColorAttachments = NULL;
4712 VkRenderPass rp_ds;
4713 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4714 ASSERT_VK_SUCCESS(err);
4715 // Set correct attachment count, but attachment has COLOR usage bit set
4716 fb_info.attachmentCount = 1;
4717 fb_info.renderPass = rp_ds;
4718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004720 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4721
4722 m_errorMonitor->VerifyFound();
4723 if (err == VK_SUCCESS) {
4724 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4725 }
4726 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004727
4728 // Create new renderpass with alternate attachment format from fb
4729 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4730 subpass.pDepthStencilAttachment = NULL;
4731 subpass.pColorAttachments = &attach;
4732 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4733 ASSERT_VK_SUCCESS(err);
4734
4735 // Cause error due to mis-matched formats between rp & fb
4736 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4737 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4739 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004740 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4741
4742 m_errorMonitor->VerifyFound();
4743 if (err == VK_SUCCESS) {
4744 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4745 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004746 vkDestroyRenderPass(m_device->device(), rp, NULL);
4747
4748 // Create new renderpass with alternate sample count from fb
4749 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4750 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4751 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4752 ASSERT_VK_SUCCESS(err);
4753
4754 // Cause error due to mis-matched sample count between rp & fb
4755 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4757 "that do not match the "
4758 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004759 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4760
4761 m_errorMonitor->VerifyFound();
4762 if (err == VK_SUCCESS) {
4763 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4764 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004765
4766 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004767
4768 // Create a custom imageView with non-1 mip levels
4769 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004770 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 -06004771 ASSERT_TRUE(image.initialized());
4772
4773 VkImageView view;
4774 VkImageViewCreateInfo ivci = {};
4775 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4776 ivci.image = image.handle();
4777 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4778 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4779 ivci.subresourceRange.layerCount = 1;
4780 ivci.subresourceRange.baseMipLevel = 0;
4781 // Set level count 2 (only 1 is allowed for FB attachment)
4782 ivci.subresourceRange.levelCount = 2;
4783 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4784 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4785 ASSERT_VK_SUCCESS(err);
4786 // Re-create renderpass to have matching sample count
4787 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4788 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4789 ASSERT_VK_SUCCESS(err);
4790
4791 fb_info.renderPass = rp;
4792 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004794 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4795
4796 m_errorMonitor->VerifyFound();
4797 if (err == VK_SUCCESS) {
4798 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4799 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004800 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004801 // Update view to original color buffer and grow FB dimensions too big
4802 fb_info.pAttachments = ivs;
4803 fb_info.height = 1024;
4804 fb_info.width = 1024;
4805 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4807 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004808 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4809
4810 m_errorMonitor->VerifyFound();
4811 if (err == VK_SUCCESS) {
4812 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4813 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004814 // Create view attachment with non-identity swizzle
4815 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4816 ivci.image = image.handle();
4817 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4818 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4819 ivci.subresourceRange.layerCount = 1;
4820 ivci.subresourceRange.baseMipLevel = 0;
4821 ivci.subresourceRange.levelCount = 1;
4822 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4823 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4824 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4825 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4826 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4827 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4828 ASSERT_VK_SUCCESS(err);
4829
4830 fb_info.pAttachments = &view;
4831 fb_info.height = 100;
4832 fb_info.width = 100;
4833 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4835 "framebuffer attachments must have "
4836 "been created with the identity "
4837 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004838 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4839
4840 m_errorMonitor->VerifyFound();
4841 if (err == VK_SUCCESS) {
4842 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4843 }
4844 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004845 // Request fb that exceeds max dimensions
4846 // reset attachment to color attachment
4847 fb_info.pAttachments = ivs;
4848 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4849 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4850 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4852 "dimensions exceed physical device "
4853 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004854 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4855
4856 m_errorMonitor->VerifyFound();
4857 if (err == VK_SUCCESS) {
4858 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4859 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004860
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004861 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004862}
4863
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004864// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004865TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004866 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004867
Michael Lentine860b0fe2016-05-20 10:14:00 -05004868 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004869 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004870
4871 VkEvent event;
4872 VkEventCreateInfo event_create_info{};
4873 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4874 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4875
4876 VkCommandPool command_pool;
4877 VkCommandPoolCreateInfo pool_create_info{};
4878 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4879 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4880 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004881 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004882
4883 VkCommandBuffer command_buffer;
4884 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004886 command_buffer_allocate_info.commandPool = command_pool;
4887 command_buffer_allocate_info.commandBufferCount = 1;
4888 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004890
4891 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004892 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004893
4894 {
4895 VkCommandBufferBeginInfo begin_info{};
4896 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4897 vkBeginCommandBuffer(command_buffer, &begin_info);
4898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004899 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 -05004900 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004901 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004902 vkEndCommandBuffer(command_buffer);
4903 }
4904 {
4905 VkSubmitInfo submit_info{};
4906 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4907 submit_info.commandBufferCount = 1;
4908 submit_info.pCommandBuffers = &command_buffer;
4909 submit_info.signalSemaphoreCount = 0;
4910 submit_info.pSignalSemaphores = nullptr;
4911 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4912 }
4913 { vkSetEvent(m_device->device(), event); }
4914
4915 vkQueueWaitIdle(queue);
4916
4917 vkDestroyEvent(m_device->device(), event, nullptr);
4918 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4919 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4920
4921 m_errorMonitor->VerifyNotFound();
4922}
Michael Lentine5627e692016-05-20 17:45:02 -05004923// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004924TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004926
Cody Northropc31a84f2016-08-22 10:41:47 -06004927 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004928 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004929 return;
4930
4931 m_errorMonitor->ExpectSuccess();
4932
4933 VkQueryPool query_pool;
4934 VkQueryPoolCreateInfo query_pool_create_info{};
4935 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4936 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4937 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004938 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004939
4940 VkCommandPool command_pool;
4941 VkCommandPoolCreateInfo pool_create_info{};
4942 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4943 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4944 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004945 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004946
4947 VkCommandBuffer command_buffer;
4948 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004950 command_buffer_allocate_info.commandPool = command_pool;
4951 command_buffer_allocate_info.commandBufferCount = 1;
4952 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004954
4955 VkCommandBuffer secondary_command_buffer;
4956 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004957 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004958
4959 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004961
4962 uint32_t qfi = 0;
4963 VkBufferCreateInfo buff_create_info = {};
4964 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4965 buff_create_info.size = 1024;
4966 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4967 buff_create_info.queueFamilyIndexCount = 1;
4968 buff_create_info.pQueueFamilyIndices = &qfi;
4969
4970 VkResult err;
4971 VkBuffer buffer;
4972 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4973 ASSERT_VK_SUCCESS(err);
4974 VkMemoryAllocateInfo mem_alloc = {};
4975 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4976 mem_alloc.pNext = NULL;
4977 mem_alloc.allocationSize = 1024;
4978 mem_alloc.memoryTypeIndex = 0;
4979
4980 VkMemoryRequirements memReqs;
4981 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004982 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004983 if (!pass) {
4984 vkDestroyBuffer(m_device->device(), buffer, NULL);
4985 return;
4986 }
4987
4988 VkDeviceMemory mem;
4989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4990 ASSERT_VK_SUCCESS(err);
4991 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4992 ASSERT_VK_SUCCESS(err);
4993
4994 VkCommandBufferInheritanceInfo hinfo = {};
4995 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
4996 hinfo.renderPass = VK_NULL_HANDLE;
4997 hinfo.subpass = 0;
4998 hinfo.framebuffer = VK_NULL_HANDLE;
4999 hinfo.occlusionQueryEnable = VK_FALSE;
5000 hinfo.queryFlags = 0;
5001 hinfo.pipelineStatistics = 0;
5002
5003 {
5004 VkCommandBufferBeginInfo begin_info{};
5005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5006 begin_info.pInheritanceInfo = &hinfo;
5007 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5008
5009 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005011
5012 vkEndCommandBuffer(secondary_command_buffer);
5013
5014 begin_info.pInheritanceInfo = nullptr;
5015 vkBeginCommandBuffer(command_buffer, &begin_info);
5016
5017 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005018 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005019
5020 vkEndCommandBuffer(command_buffer);
5021 }
5022 {
5023 VkSubmitInfo submit_info{};
5024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5025 submit_info.commandBufferCount = 1;
5026 submit_info.pCommandBuffers = &command_buffer;
5027 submit_info.signalSemaphoreCount = 0;
5028 submit_info.pSignalSemaphores = nullptr;
5029 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5030 }
5031
5032 vkQueueWaitIdle(queue);
5033
5034 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5035 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5036 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5037 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5038 vkDestroyBuffer(m_device->device(), buffer, NULL);
5039 vkFreeMemory(m_device->device(), mem, NULL);
5040
5041 m_errorMonitor->VerifyNotFound();
5042}
5043
5044// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005045TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005047
Cody Northropc31a84f2016-08-22 10:41:47 -06005048 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005049 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005050 return;
5051
5052 m_errorMonitor->ExpectSuccess();
5053
5054 VkQueryPool query_pool;
5055 VkQueryPoolCreateInfo query_pool_create_info{};
5056 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5057 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5058 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005059 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005060
5061 VkCommandPool command_pool;
5062 VkCommandPoolCreateInfo pool_create_info{};
5063 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5064 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5065 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005066 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005067
5068 VkCommandBuffer command_buffer[2];
5069 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005070 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005071 command_buffer_allocate_info.commandPool = command_pool;
5072 command_buffer_allocate_info.commandBufferCount = 2;
5073 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005075
5076 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005077 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005078
5079 uint32_t qfi = 0;
5080 VkBufferCreateInfo buff_create_info = {};
5081 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5082 buff_create_info.size = 1024;
5083 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5084 buff_create_info.queueFamilyIndexCount = 1;
5085 buff_create_info.pQueueFamilyIndices = &qfi;
5086
5087 VkResult err;
5088 VkBuffer buffer;
5089 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5090 ASSERT_VK_SUCCESS(err);
5091 VkMemoryAllocateInfo mem_alloc = {};
5092 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5093 mem_alloc.pNext = NULL;
5094 mem_alloc.allocationSize = 1024;
5095 mem_alloc.memoryTypeIndex = 0;
5096
5097 VkMemoryRequirements memReqs;
5098 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005099 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005100 if (!pass) {
5101 vkDestroyBuffer(m_device->device(), buffer, NULL);
5102 return;
5103 }
5104
5105 VkDeviceMemory mem;
5106 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5107 ASSERT_VK_SUCCESS(err);
5108 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5109 ASSERT_VK_SUCCESS(err);
5110
5111 {
5112 VkCommandBufferBeginInfo begin_info{};
5113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5114 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5115
5116 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005117 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005118
5119 vkEndCommandBuffer(command_buffer[0]);
5120
5121 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005123 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005124
5125 vkEndCommandBuffer(command_buffer[1]);
5126 }
5127 {
5128 VkSubmitInfo submit_info{};
5129 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5130 submit_info.commandBufferCount = 2;
5131 submit_info.pCommandBuffers = command_buffer;
5132 submit_info.signalSemaphoreCount = 0;
5133 submit_info.pSignalSemaphores = nullptr;
5134 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5135 }
5136
5137 vkQueueWaitIdle(queue);
5138
5139 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5140 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5141 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005142 vkDestroyBuffer(m_device->device(), buffer, NULL);
5143 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005144
5145 m_errorMonitor->VerifyNotFound();
5146}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005147
5148TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005149 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005150
Michael Lentine860b0fe2016-05-20 10:14:00 -05005151 m_errorMonitor->ExpectSuccess();
5152
Cody Northropc31a84f2016-08-22 10:41:47 -06005153 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005154 VkEvent event;
5155 VkEventCreateInfo event_create_info{};
5156 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5157 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5158
5159 VkCommandPool command_pool;
5160 VkCommandPoolCreateInfo pool_create_info{};
5161 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5162 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5163 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005164 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005165
5166 VkCommandBuffer command_buffer;
5167 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005169 command_buffer_allocate_info.commandPool = command_pool;
5170 command_buffer_allocate_info.commandBufferCount = 1;
5171 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005172 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005173
5174 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005175 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005176
5177 {
5178 VkCommandBufferBeginInfo begin_info{};
5179 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5180 vkBeginCommandBuffer(command_buffer, &begin_info);
5181
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5183 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5184 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005185 vkEndCommandBuffer(command_buffer);
5186 }
5187 {
5188 VkSubmitInfo submit_info{};
5189 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5190 submit_info.commandBufferCount = 1;
5191 submit_info.pCommandBuffers = &command_buffer;
5192 submit_info.signalSemaphoreCount = 0;
5193 submit_info.pSignalSemaphores = nullptr;
5194 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5195 }
5196 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5198 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005199 vkSetEvent(m_device->device(), event);
5200 m_errorMonitor->VerifyFound();
5201 }
5202
5203 vkQueueWaitIdle(queue);
5204
5205 vkDestroyEvent(m_device->device(), event, nullptr);
5206 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5207 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5208}
5209
5210// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005211TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5212 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5213 "run through a Submit & WaitForFences cycle 3 times. This "
5214 "previously revealed a bug so running this positive test "
5215 "to prevent a regression.");
5216 m_errorMonitor->ExpectSuccess();
5217
5218 ASSERT_NO_FATAL_FAILURE(InitState());
5219 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005220 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005221
5222 static const uint32_t NUM_OBJECTS = 2;
5223 static const uint32_t NUM_FRAMES = 3;
5224 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5225 VkFence fences[NUM_OBJECTS] = {};
5226
5227 VkCommandPool cmd_pool;
5228 VkCommandPoolCreateInfo cmd_pool_ci = {};
5229 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5230 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5231 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005232 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005233 ASSERT_VK_SUCCESS(err);
5234
5235 VkCommandBufferAllocateInfo cmd_buf_info = {};
5236 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5237 cmd_buf_info.commandPool = cmd_pool;
5238 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5239 cmd_buf_info.commandBufferCount = 1;
5240
5241 VkFenceCreateInfo fence_ci = {};
5242 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5243 fence_ci.pNext = nullptr;
5244 fence_ci.flags = 0;
5245
5246 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005248 ASSERT_VK_SUCCESS(err);
5249 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5250 ASSERT_VK_SUCCESS(err);
5251 }
5252
5253 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005254 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5255 // Create empty cmd buffer
5256 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5257 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005258
Tobin Ehlisf9025162016-05-26 06:55:21 -06005259 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5260 ASSERT_VK_SUCCESS(err);
5261 err = vkEndCommandBuffer(cmd_buffers[obj]);
5262 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005263
Tobin Ehlisf9025162016-05-26 06:55:21 -06005264 VkSubmitInfo submit_info = {};
5265 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5266 submit_info.commandBufferCount = 1;
5267 submit_info.pCommandBuffers = &cmd_buffers[obj];
5268 // Submit cmd buffer and wait for fence
5269 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5270 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005271 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005272 ASSERT_VK_SUCCESS(err);
5273 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5274 ASSERT_VK_SUCCESS(err);
5275 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005276 }
5277 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005278 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5279 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5280 vkDestroyFence(m_device->device(), fences[i], nullptr);
5281 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005282}
5283// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005284TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5285
5286 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005287 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005288
Cody Northropc31a84f2016-08-22 10:41:47 -06005289 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005290 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005291 return;
5292
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005293 m_errorMonitor->ExpectSuccess();
5294
5295 VkSemaphore semaphore;
5296 VkSemaphoreCreateInfo semaphore_create_info{};
5297 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005298 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005299
5300 VkCommandPool command_pool;
5301 VkCommandPoolCreateInfo pool_create_info{};
5302 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5303 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5304 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005305 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005306
5307 VkCommandBuffer command_buffer[2];
5308 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005310 command_buffer_allocate_info.commandPool = command_pool;
5311 command_buffer_allocate_info.commandBufferCount = 2;
5312 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005313 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005314
5315 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005316 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005317
5318 {
5319 VkCommandBufferBeginInfo begin_info{};
5320 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5321 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5322
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005323 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5324 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005325
5326 VkViewport viewport{};
5327 viewport.maxDepth = 1.0f;
5328 viewport.minDepth = 0.0f;
5329 viewport.width = 512;
5330 viewport.height = 512;
5331 viewport.x = 0;
5332 viewport.y = 0;
5333 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5334 vkEndCommandBuffer(command_buffer[0]);
5335 }
5336 {
5337 VkCommandBufferBeginInfo begin_info{};
5338 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5339 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5340
5341 VkViewport viewport{};
5342 viewport.maxDepth = 1.0f;
5343 viewport.minDepth = 0.0f;
5344 viewport.width = 512;
5345 viewport.height = 512;
5346 viewport.x = 0;
5347 viewport.y = 0;
5348 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5349 vkEndCommandBuffer(command_buffer[1]);
5350 }
5351 {
5352 VkSubmitInfo submit_info{};
5353 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5354 submit_info.commandBufferCount = 1;
5355 submit_info.pCommandBuffers = &command_buffer[0];
5356 submit_info.signalSemaphoreCount = 1;
5357 submit_info.pSignalSemaphores = &semaphore;
5358 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5359 }
5360 {
5361 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5362 VkSubmitInfo submit_info{};
5363 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5364 submit_info.commandBufferCount = 1;
5365 submit_info.pCommandBuffers = &command_buffer[1];
5366 submit_info.waitSemaphoreCount = 1;
5367 submit_info.pWaitSemaphores = &semaphore;
5368 submit_info.pWaitDstStageMask = flags;
5369 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5370 }
5371
5372 vkQueueWaitIdle(m_device->m_queue);
5373
5374 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005375 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005376 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5377
5378 m_errorMonitor->VerifyNotFound();
5379}
5380
5381// This is a positive test. No errors should be generated.
5382TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5383
5384 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5385 "submitted on separate queues, the second having a fence"
5386 "followed by a QueueWaitIdle.");
5387
Cody Northropc31a84f2016-08-22 10:41:47 -06005388 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005389 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005390 return;
5391
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005392 m_errorMonitor->ExpectSuccess();
5393
5394 VkFence fence;
5395 VkFenceCreateInfo fence_create_info{};
5396 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5397 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5398
5399 VkSemaphore semaphore;
5400 VkSemaphoreCreateInfo semaphore_create_info{};
5401 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005402 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005403
5404 VkCommandPool command_pool;
5405 VkCommandPoolCreateInfo pool_create_info{};
5406 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5407 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5408 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005409 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005410
5411 VkCommandBuffer command_buffer[2];
5412 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005414 command_buffer_allocate_info.commandPool = command_pool;
5415 command_buffer_allocate_info.commandBufferCount = 2;
5416 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005418
5419 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005421
5422 {
5423 VkCommandBufferBeginInfo begin_info{};
5424 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5425 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5426
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005427 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5428 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005429
5430 VkViewport viewport{};
5431 viewport.maxDepth = 1.0f;
5432 viewport.minDepth = 0.0f;
5433 viewport.width = 512;
5434 viewport.height = 512;
5435 viewport.x = 0;
5436 viewport.y = 0;
5437 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5438 vkEndCommandBuffer(command_buffer[0]);
5439 }
5440 {
5441 VkCommandBufferBeginInfo begin_info{};
5442 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5443 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5444
5445 VkViewport viewport{};
5446 viewport.maxDepth = 1.0f;
5447 viewport.minDepth = 0.0f;
5448 viewport.width = 512;
5449 viewport.height = 512;
5450 viewport.x = 0;
5451 viewport.y = 0;
5452 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5453 vkEndCommandBuffer(command_buffer[1]);
5454 }
5455 {
5456 VkSubmitInfo submit_info{};
5457 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5458 submit_info.commandBufferCount = 1;
5459 submit_info.pCommandBuffers = &command_buffer[0];
5460 submit_info.signalSemaphoreCount = 1;
5461 submit_info.pSignalSemaphores = &semaphore;
5462 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5463 }
5464 {
5465 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5466 VkSubmitInfo submit_info{};
5467 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5468 submit_info.commandBufferCount = 1;
5469 submit_info.pCommandBuffers = &command_buffer[1];
5470 submit_info.waitSemaphoreCount = 1;
5471 submit_info.pWaitSemaphores = &semaphore;
5472 submit_info.pWaitDstStageMask = flags;
5473 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5474 }
5475
5476 vkQueueWaitIdle(m_device->m_queue);
5477
5478 vkDestroyFence(m_device->device(), fence, nullptr);
5479 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005481 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5482
5483 m_errorMonitor->VerifyNotFound();
5484}
5485
5486// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005487TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005488
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005489 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5490 "submitted on separate queues, the second having a fence"
5491 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005492
Cody Northropc31a84f2016-08-22 10:41:47 -06005493 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005494 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005495 return;
5496
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005497 m_errorMonitor->ExpectSuccess();
5498
5499 VkFence fence;
5500 VkFenceCreateInfo fence_create_info{};
5501 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5502 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5503
5504 VkSemaphore semaphore;
5505 VkSemaphoreCreateInfo semaphore_create_info{};
5506 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005508
5509 VkCommandPool command_pool;
5510 VkCommandPoolCreateInfo pool_create_info{};
5511 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5512 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5513 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005514 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005515
5516 VkCommandBuffer command_buffer[2];
5517 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005519 command_buffer_allocate_info.commandPool = command_pool;
5520 command_buffer_allocate_info.commandBufferCount = 2;
5521 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005522 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005523
5524 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005525 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005526
5527 {
5528 VkCommandBufferBeginInfo begin_info{};
5529 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5530 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5531
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005532 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5533 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005534
5535 VkViewport viewport{};
5536 viewport.maxDepth = 1.0f;
5537 viewport.minDepth = 0.0f;
5538 viewport.width = 512;
5539 viewport.height = 512;
5540 viewport.x = 0;
5541 viewport.y = 0;
5542 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5543 vkEndCommandBuffer(command_buffer[0]);
5544 }
5545 {
5546 VkCommandBufferBeginInfo begin_info{};
5547 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5548 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5549
5550 VkViewport viewport{};
5551 viewport.maxDepth = 1.0f;
5552 viewport.minDepth = 0.0f;
5553 viewport.width = 512;
5554 viewport.height = 512;
5555 viewport.x = 0;
5556 viewport.y = 0;
5557 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5558 vkEndCommandBuffer(command_buffer[1]);
5559 }
5560 {
5561 VkSubmitInfo submit_info{};
5562 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5563 submit_info.commandBufferCount = 1;
5564 submit_info.pCommandBuffers = &command_buffer[0];
5565 submit_info.signalSemaphoreCount = 1;
5566 submit_info.pSignalSemaphores = &semaphore;
5567 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5568 }
5569 {
5570 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5571 VkSubmitInfo submit_info{};
5572 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5573 submit_info.commandBufferCount = 1;
5574 submit_info.pCommandBuffers = &command_buffer[1];
5575 submit_info.waitSemaphoreCount = 1;
5576 submit_info.pWaitSemaphores = &semaphore;
5577 submit_info.pWaitDstStageMask = flags;
5578 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5579 }
5580
5581 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5582 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5583
5584 vkDestroyFence(m_device->device(), fence, nullptr);
5585 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005586 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005587 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5588
5589 m_errorMonitor->VerifyNotFound();
5590}
5591
Chris Forbes0f8126b2016-06-20 17:48:22 +12005592TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005593
5594 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005595 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005596 printf("Test requires two queues, skipping\n");
5597 return;
5598 }
5599
5600 VkResult err;
5601
5602 m_errorMonitor->ExpectSuccess();
5603
5604 VkQueue q0 = m_device->m_queue;
5605 VkQueue q1 = nullptr;
5606 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5607 ASSERT_NE(q1, nullptr);
5608
5609 // An (empty) command buffer. We must have work in the first submission --
5610 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005611 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005612 VkCommandPool pool;
5613 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5614 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005615 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5616 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005617 VkCommandBuffer cb;
5618 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5619 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621 err = vkBeginCommandBuffer(cb, &cbbi);
5622 ASSERT_VK_SUCCESS(err);
5623 err = vkEndCommandBuffer(cb);
5624 ASSERT_VK_SUCCESS(err);
5625
5626 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005628 VkSemaphore s;
5629 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5630 ASSERT_VK_SUCCESS(err);
5631
5632 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005633 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005634
5635 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5636 ASSERT_VK_SUCCESS(err);
5637
5638 // Second submission, to q1, waiting on s
5639 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005640 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005641
5642 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5643 ASSERT_VK_SUCCESS(err);
5644
5645 // Wait for q0 idle
5646 err = vkQueueWaitIdle(q0);
5647 ASSERT_VK_SUCCESS(err);
5648
5649 // Command buffer should have been completed (it was on q0); reset the pool.
5650 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5651
5652 m_errorMonitor->VerifyNotFound();
5653
5654 // Force device completely idle and clean up resources
5655 vkDeviceWaitIdle(m_device->device());
5656 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5657 vkDestroySemaphore(m_device->device(), s, nullptr);
5658}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005659
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005660// This is a positive test. No errors should be generated.
5661TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5662
5663 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5664 "submitted on separate queues, the second having a fence, "
5665 "followed by a WaitForFences call.");
5666
Cody Northropc31a84f2016-08-22 10:41:47 -06005667 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005668 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005669 return;
5670
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005671 m_errorMonitor->ExpectSuccess();
5672
Cody Northropc31a84f2016-08-22 10:41:47 -06005673 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005674 VkFence fence;
5675 VkFenceCreateInfo fence_create_info{};
5676 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5677 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5678
5679 VkSemaphore semaphore;
5680 VkSemaphoreCreateInfo semaphore_create_info{};
5681 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005683
5684 VkCommandPool command_pool;
5685 VkCommandPoolCreateInfo pool_create_info{};
5686 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5687 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5688 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005690
5691 VkCommandBuffer command_buffer[2];
5692 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005694 command_buffer_allocate_info.commandPool = command_pool;
5695 command_buffer_allocate_info.commandBufferCount = 2;
5696 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005698
5699 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005700 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005701
5702 {
5703 VkCommandBufferBeginInfo begin_info{};
5704 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5705 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005707 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5708 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005709
5710 VkViewport viewport{};
5711 viewport.maxDepth = 1.0f;
5712 viewport.minDepth = 0.0f;
5713 viewport.width = 512;
5714 viewport.height = 512;
5715 viewport.x = 0;
5716 viewport.y = 0;
5717 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5718 vkEndCommandBuffer(command_buffer[0]);
5719 }
5720 {
5721 VkCommandBufferBeginInfo begin_info{};
5722 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5723 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5724
5725 VkViewport viewport{};
5726 viewport.maxDepth = 1.0f;
5727 viewport.minDepth = 0.0f;
5728 viewport.width = 512;
5729 viewport.height = 512;
5730 viewport.x = 0;
5731 viewport.y = 0;
5732 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5733 vkEndCommandBuffer(command_buffer[1]);
5734 }
5735 {
5736 VkSubmitInfo submit_info{};
5737 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5738 submit_info.commandBufferCount = 1;
5739 submit_info.pCommandBuffers = &command_buffer[0];
5740 submit_info.signalSemaphoreCount = 1;
5741 submit_info.pSignalSemaphores = &semaphore;
5742 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5743 }
5744 {
5745 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5746 VkSubmitInfo submit_info{};
5747 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5748 submit_info.commandBufferCount = 1;
5749 submit_info.pCommandBuffers = &command_buffer[1];
5750 submit_info.waitSemaphoreCount = 1;
5751 submit_info.pWaitSemaphores = &semaphore;
5752 submit_info.pWaitDstStageMask = flags;
5753 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5754 }
5755
5756 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5757
5758 vkDestroyFence(m_device->device(), fence, nullptr);
5759 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005760 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005761 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5762
5763 m_errorMonitor->VerifyNotFound();
5764}
5765
5766// This is a positive test. No errors should be generated.
5767TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5768
5769 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5770 "on the same queue, sharing a signal/wait semaphore, the "
5771 "second having a fence, "
5772 "followed by a WaitForFences call.");
5773
5774 m_errorMonitor->ExpectSuccess();
5775
Cody Northropc31a84f2016-08-22 10:41:47 -06005776 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005777 VkFence fence;
5778 VkFenceCreateInfo fence_create_info{};
5779 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5780 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5781
5782 VkSemaphore semaphore;
5783 VkSemaphoreCreateInfo semaphore_create_info{};
5784 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005785 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005786
5787 VkCommandPool command_pool;
5788 VkCommandPoolCreateInfo pool_create_info{};
5789 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5790 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5791 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005793
5794 VkCommandBuffer command_buffer[2];
5795 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005797 command_buffer_allocate_info.commandPool = command_pool;
5798 command_buffer_allocate_info.commandBufferCount = 2;
5799 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005801
5802 {
5803 VkCommandBufferBeginInfo begin_info{};
5804 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5805 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005807 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5808 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005809
5810 VkViewport viewport{};
5811 viewport.maxDepth = 1.0f;
5812 viewport.minDepth = 0.0f;
5813 viewport.width = 512;
5814 viewport.height = 512;
5815 viewport.x = 0;
5816 viewport.y = 0;
5817 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5818 vkEndCommandBuffer(command_buffer[0]);
5819 }
5820 {
5821 VkCommandBufferBeginInfo begin_info{};
5822 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5823 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5824
5825 VkViewport viewport{};
5826 viewport.maxDepth = 1.0f;
5827 viewport.minDepth = 0.0f;
5828 viewport.width = 512;
5829 viewport.height = 512;
5830 viewport.x = 0;
5831 viewport.y = 0;
5832 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5833 vkEndCommandBuffer(command_buffer[1]);
5834 }
5835 {
5836 VkSubmitInfo submit_info{};
5837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5838 submit_info.commandBufferCount = 1;
5839 submit_info.pCommandBuffers = &command_buffer[0];
5840 submit_info.signalSemaphoreCount = 1;
5841 submit_info.pSignalSemaphores = &semaphore;
5842 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5843 }
5844 {
5845 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5846 VkSubmitInfo submit_info{};
5847 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5848 submit_info.commandBufferCount = 1;
5849 submit_info.pCommandBuffers = &command_buffer[1];
5850 submit_info.waitSemaphoreCount = 1;
5851 submit_info.pWaitSemaphores = &semaphore;
5852 submit_info.pWaitDstStageMask = flags;
5853 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5854 }
5855
5856 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5857
5858 vkDestroyFence(m_device->device(), fence, nullptr);
5859 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005861 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5862
5863 m_errorMonitor->VerifyNotFound();
5864}
5865
5866// This is a positive test. No errors should be generated.
5867TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5870 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5871 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005872
5873 m_errorMonitor->ExpectSuccess();
5874
Cody Northropc31a84f2016-08-22 10:41:47 -06005875 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005876 VkFence fence;
5877 VkFenceCreateInfo fence_create_info{};
5878 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5879 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5880
5881 VkCommandPool command_pool;
5882 VkCommandPoolCreateInfo pool_create_info{};
5883 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5884 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5885 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005886 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005887
5888 VkCommandBuffer command_buffer[2];
5889 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005890 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005891 command_buffer_allocate_info.commandPool = command_pool;
5892 command_buffer_allocate_info.commandBufferCount = 2;
5893 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005895
5896 {
5897 VkCommandBufferBeginInfo begin_info{};
5898 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5899 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005901 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5902 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005903
5904 VkViewport viewport{};
5905 viewport.maxDepth = 1.0f;
5906 viewport.minDepth = 0.0f;
5907 viewport.width = 512;
5908 viewport.height = 512;
5909 viewport.x = 0;
5910 viewport.y = 0;
5911 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5912 vkEndCommandBuffer(command_buffer[0]);
5913 }
5914 {
5915 VkCommandBufferBeginInfo begin_info{};
5916 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5917 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5918
5919 VkViewport viewport{};
5920 viewport.maxDepth = 1.0f;
5921 viewport.minDepth = 0.0f;
5922 viewport.width = 512;
5923 viewport.height = 512;
5924 viewport.x = 0;
5925 viewport.y = 0;
5926 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5927 vkEndCommandBuffer(command_buffer[1]);
5928 }
5929 {
5930 VkSubmitInfo submit_info{};
5931 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5932 submit_info.commandBufferCount = 1;
5933 submit_info.pCommandBuffers = &command_buffer[0];
5934 submit_info.signalSemaphoreCount = 0;
5935 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5936 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5937 }
5938 {
5939 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5940 VkSubmitInfo submit_info{};
5941 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5942 submit_info.commandBufferCount = 1;
5943 submit_info.pCommandBuffers = &command_buffer[1];
5944 submit_info.waitSemaphoreCount = 0;
5945 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5946 submit_info.pWaitDstStageMask = flags;
5947 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5948 }
5949
5950 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005952 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005953 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005954
5955 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005956 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005957 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5958
5959 m_errorMonitor->VerifyNotFound();
5960}
5961
5962// This is a positive test. No errors should be generated.
5963TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5964
5965 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5966 "on the same queue, the second having a fence, followed "
5967 "by a WaitForFences call.");
5968
5969 m_errorMonitor->ExpectSuccess();
5970
Cody Northropc31a84f2016-08-22 10:41:47 -06005971 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005972 VkFence fence;
5973 VkFenceCreateInfo fence_create_info{};
5974 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5975 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5976
5977 VkCommandPool command_pool;
5978 VkCommandPoolCreateInfo pool_create_info{};
5979 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5980 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5981 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005983
5984 VkCommandBuffer command_buffer[2];
5985 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005986 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005987 command_buffer_allocate_info.commandPool = command_pool;
5988 command_buffer_allocate_info.commandBufferCount = 2;
5989 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005991
5992 {
5993 VkCommandBufferBeginInfo begin_info{};
5994 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5995 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005997 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5998 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005999
6000 VkViewport viewport{};
6001 viewport.maxDepth = 1.0f;
6002 viewport.minDepth = 0.0f;
6003 viewport.width = 512;
6004 viewport.height = 512;
6005 viewport.x = 0;
6006 viewport.y = 0;
6007 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6008 vkEndCommandBuffer(command_buffer[0]);
6009 }
6010 {
6011 VkCommandBufferBeginInfo begin_info{};
6012 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6013 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6014
6015 VkViewport viewport{};
6016 viewport.maxDepth = 1.0f;
6017 viewport.minDepth = 0.0f;
6018 viewport.width = 512;
6019 viewport.height = 512;
6020 viewport.x = 0;
6021 viewport.y = 0;
6022 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6023 vkEndCommandBuffer(command_buffer[1]);
6024 }
6025 {
6026 VkSubmitInfo submit_info{};
6027 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6028 submit_info.commandBufferCount = 1;
6029 submit_info.pCommandBuffers = &command_buffer[0];
6030 submit_info.signalSemaphoreCount = 0;
6031 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6032 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6033 }
6034 {
6035 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6036 VkSubmitInfo submit_info{};
6037 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6038 submit_info.commandBufferCount = 1;
6039 submit_info.pCommandBuffers = &command_buffer[1];
6040 submit_info.waitSemaphoreCount = 0;
6041 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6042 submit_info.pWaitDstStageMask = flags;
6043 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6044 }
6045
6046 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6047
6048 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006049 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006050 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6051
6052 m_errorMonitor->VerifyNotFound();
6053}
6054
6055// This is a positive test. No errors should be generated.
6056TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006058 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6059 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006060 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006061
6062 m_errorMonitor->ExpectSuccess();
6063
6064 VkFence fence;
6065 VkFenceCreateInfo fence_create_info{};
6066 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6067 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6068
6069 VkSemaphore semaphore;
6070 VkSemaphoreCreateInfo semaphore_create_info{};
6071 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006073
6074 VkCommandPool command_pool;
6075 VkCommandPoolCreateInfo pool_create_info{};
6076 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6077 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6078 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006079 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006080
6081 VkCommandBuffer command_buffer[2];
6082 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006083 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006084 command_buffer_allocate_info.commandPool = command_pool;
6085 command_buffer_allocate_info.commandBufferCount = 2;
6086 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006088
6089 {
6090 VkCommandBufferBeginInfo begin_info{};
6091 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6092 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006094 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6095 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006096
6097 VkViewport viewport{};
6098 viewport.maxDepth = 1.0f;
6099 viewport.minDepth = 0.0f;
6100 viewport.width = 512;
6101 viewport.height = 512;
6102 viewport.x = 0;
6103 viewport.y = 0;
6104 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6105 vkEndCommandBuffer(command_buffer[0]);
6106 }
6107 {
6108 VkCommandBufferBeginInfo begin_info{};
6109 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6110 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6111
6112 VkViewport viewport{};
6113 viewport.maxDepth = 1.0f;
6114 viewport.minDepth = 0.0f;
6115 viewport.width = 512;
6116 viewport.height = 512;
6117 viewport.x = 0;
6118 viewport.y = 0;
6119 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6120 vkEndCommandBuffer(command_buffer[1]);
6121 }
6122 {
6123 VkSubmitInfo submit_info[2];
6124 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6125
6126 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6127 submit_info[0].pNext = NULL;
6128 submit_info[0].commandBufferCount = 1;
6129 submit_info[0].pCommandBuffers = &command_buffer[0];
6130 submit_info[0].signalSemaphoreCount = 1;
6131 submit_info[0].pSignalSemaphores = &semaphore;
6132 submit_info[0].waitSemaphoreCount = 0;
6133 submit_info[0].pWaitSemaphores = NULL;
6134 submit_info[0].pWaitDstStageMask = 0;
6135
6136 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6137 submit_info[1].pNext = NULL;
6138 submit_info[1].commandBufferCount = 1;
6139 submit_info[1].pCommandBuffers = &command_buffer[1];
6140 submit_info[1].waitSemaphoreCount = 1;
6141 submit_info[1].pWaitSemaphores = &semaphore;
6142 submit_info[1].pWaitDstStageMask = flags;
6143 submit_info[1].signalSemaphoreCount = 0;
6144 submit_info[1].pSignalSemaphores = NULL;
6145 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6146 }
6147
6148 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6149
6150 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006151 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006152 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006153 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006154
6155 m_errorMonitor->VerifyNotFound();
6156}
6157
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006158TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006159 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6160 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006161
Cody Northropc31a84f2016-08-22 10:41:47 -06006162 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006163 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6165 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006166 m_errorMonitor->VerifyFound();
6167}
6168
6169TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006170 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6171 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006172
Cody Northropc31a84f2016-08-22 10:41:47 -06006173 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006174 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6176 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006177 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006178}
6179
6180TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006181 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6182 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006183
Cody Northropc31a84f2016-08-22 10:41:47 -06006184 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006185 // Dynamic viewport state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006186 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 -06006187 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006188 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006189}
6190
6191TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006192 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6193 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006194
Cody Northropc31a84f2016-08-22 10:41:47 -06006195 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006196 // Dynamic scissor state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006197 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 -06006198 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006199 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006200}
6201
Cortd713fe82016-07-27 09:51:27 -07006202TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006203 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6204 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006205
6206 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006207 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6209 "Dynamic blend constants state not set for this command buffer");
6210 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006211 m_errorMonitor->VerifyFound();
6212}
6213
6214TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006215 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6216 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006217
6218 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006219 if (!m_device->phy().features().depthBounds) {
6220 printf("Device does not support depthBounds test; skipped.\n");
6221 return;
6222 }
6223 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6225 "Dynamic depth bounds state not set for this command buffer");
6226 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006227 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006228}
6229
6230TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006231 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6232 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006233
6234 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006235 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6237 "Dynamic stencil read mask state not set for this command buffer");
6238 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006239 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006240}
6241
6242TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006243 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6244 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006245
6246 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006247 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6249 "Dynamic stencil write mask state not set for this command buffer");
6250 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006251 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006252}
6253
6254TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006255 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6256 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006257
6258 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006259 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6261 "Dynamic stencil reference state not set for this command buffer");
6262 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006263 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006264}
6265
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006266TEST_F(VkLayerTest, IndexBufferNotBound) {
6267 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006268
6269 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6271 "Index buffer object not bound to this command buffer when Indexed ");
6272 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006273 m_errorMonitor->VerifyFound();
6274}
6275
Karl Schultz6addd812016-02-02 17:17:23 -07006276TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6278 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6279 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006280
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006281 ASSERT_NO_FATAL_FAILURE(InitState());
6282 ASSERT_NO_FATAL_FAILURE(InitViewport());
6283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6284
Karl Schultz6addd812016-02-02 17:17:23 -07006285 // We luck out b/c by default the framework creates CB w/ the
6286 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006287 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006288 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006289 EndCommandBuffer();
6290
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006291 // Bypass framework since it does the waits automatically
6292 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006293 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006294 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6295 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006296 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006297 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006298 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006299 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006301 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006302 submit_info.pSignalSemaphores = NULL;
6303
Chris Forbes40028e22016-06-13 09:59:34 +12006304 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006305 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006306
Karl Schultz6addd812016-02-02 17:17:23 -07006307 // Cause validation error by re-submitting cmd buffer that should only be
6308 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006309 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006310
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006311 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006312}
6313
Karl Schultz6addd812016-02-02 17:17:23 -07006314TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006315 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006316 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006317
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6319 "type "
6320 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006321
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006322 ASSERT_NO_FATAL_FAILURE(InitState());
6323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006324
Karl Schultz6addd812016-02-02 17:17:23 -07006325 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6326 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006327 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006328 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6329 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006330
6331 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6333 ds_pool_ci.pNext = NULL;
6334 ds_pool_ci.flags = 0;
6335 ds_pool_ci.maxSets = 1;
6336 ds_pool_ci.poolSizeCount = 1;
6337 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006338
6339 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006340 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006341 ASSERT_VK_SUCCESS(err);
6342
6343 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006344 dsl_binding.binding = 0;
6345 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6346 dsl_binding.descriptorCount = 1;
6347 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6348 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006349
6350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006351 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6352 ds_layout_ci.pNext = NULL;
6353 ds_layout_ci.bindingCount = 1;
6354 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006355
6356 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006358 ASSERT_VK_SUCCESS(err);
6359
6360 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006361 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006363 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006364 alloc_info.descriptorPool = ds_pool;
6365 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006367
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006368 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006369
Chia-I Wuf7458c52015-10-26 21:10:41 +08006370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6371 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006372}
6373
Karl Schultz6addd812016-02-02 17:17:23 -07006374TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6375 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006376
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6378 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6379 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006380
Tobin Ehlise735c692015-10-08 13:13:50 -06006381 ASSERT_NO_FATAL_FAILURE(InitState());
6382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006383
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006384 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006385 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6386 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006387
6388 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006389 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6390 ds_pool_ci.pNext = NULL;
6391 ds_pool_ci.maxSets = 1;
6392 ds_pool_ci.poolSizeCount = 1;
6393 ds_pool_ci.flags = 0;
6394 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6395 // app can only call vkResetDescriptorPool on this pool.;
6396 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006397
6398 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006399 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006400 ASSERT_VK_SUCCESS(err);
6401
6402 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 dsl_binding.binding = 0;
6404 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6405 dsl_binding.descriptorCount = 1;
6406 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6407 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006408
6409 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006410 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6411 ds_layout_ci.pNext = NULL;
6412 ds_layout_ci.bindingCount = 1;
6413 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006414
6415 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006416 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006417 ASSERT_VK_SUCCESS(err);
6418
6419 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006420 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006421 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006422 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006423 alloc_info.descriptorPool = ds_pool;
6424 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006425 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006426 ASSERT_VK_SUCCESS(err);
6427
6428 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006429 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006430
Chia-I Wuf7458c52015-10-26 21:10:41 +08006431 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006433}
6434
Karl Schultz6addd812016-02-02 17:17:23 -07006435TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006436 // Attempt to clear Descriptor Pool with bad object.
6437 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006438
6439 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006441 uint64_t fake_pool_handle = 0xbaad6001;
6442 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6443 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006444 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006445}
6446
Karl Schultz6addd812016-02-02 17:17:23 -07006447TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6449 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006450 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006451 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006452
6453 uint64_t fake_set_handle = 0xbaad6001;
6454 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006455 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006457
6458 ASSERT_NO_FATAL_FAILURE(InitState());
6459
6460 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6461 layout_bindings[0].binding = 0;
6462 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6463 layout_bindings[0].descriptorCount = 1;
6464 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6465 layout_bindings[0].pImmutableSamplers = NULL;
6466
6467 VkDescriptorSetLayout descriptor_set_layout;
6468 VkDescriptorSetLayoutCreateInfo dslci = {};
6469 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6470 dslci.pNext = NULL;
6471 dslci.bindingCount = 1;
6472 dslci.pBindings = layout_bindings;
6473 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006474 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006475
6476 VkPipelineLayout pipeline_layout;
6477 VkPipelineLayoutCreateInfo plci = {};
6478 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6479 plci.pNext = NULL;
6480 plci.setLayoutCount = 1;
6481 plci.pSetLayouts = &descriptor_set_layout;
6482 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006483 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006484
6485 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006486 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6487 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006488 m_errorMonitor->VerifyFound();
6489 EndCommandBuffer();
6490 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6491 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006492}
6493
Karl Schultz6addd812016-02-02 17:17:23 -07006494TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006495 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6496 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006497 uint64_t fake_layout_handle = 0xbaad6001;
6498 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006500 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006501 VkPipelineLayout pipeline_layout;
6502 VkPipelineLayoutCreateInfo plci = {};
6503 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6504 plci.pNext = NULL;
6505 plci.setLayoutCount = 1;
6506 plci.pSetLayouts = &bad_layout;
6507 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6508
6509 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006510}
6511
Mark Muellerd4914412016-06-13 17:52:06 -06006512TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6513 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6514 "1) A uniform buffer update must have a valid buffer index."
6515 "2) When using an array of descriptors in a single WriteDescriptor,"
6516 " the descriptor types and stageflags must all be the same."
6517 "3) Immutable Sampler state must match across descriptors");
6518
6519 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006520 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6521 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6522 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6523 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6524 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006525
Mark Muellerd4914412016-06-13 17:52:06 -06006526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6527
6528 ASSERT_NO_FATAL_FAILURE(InitState());
6529 VkDescriptorPoolSize ds_type_count[4] = {};
6530 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6531 ds_type_count[0].descriptorCount = 1;
6532 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6533 ds_type_count[1].descriptorCount = 1;
6534 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6535 ds_type_count[2].descriptorCount = 1;
6536 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6537 ds_type_count[3].descriptorCount = 1;
6538
6539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6541 ds_pool_ci.maxSets = 1;
6542 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6543 ds_pool_ci.pPoolSizes = ds_type_count;
6544
6545 VkDescriptorPool ds_pool;
6546 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6547 ASSERT_VK_SUCCESS(err);
6548
Mark Muellerb9896722016-06-16 09:54:29 -06006549 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006550 layout_binding[0].binding = 0;
6551 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6552 layout_binding[0].descriptorCount = 1;
6553 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6554 layout_binding[0].pImmutableSamplers = NULL;
6555
6556 layout_binding[1].binding = 1;
6557 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6558 layout_binding[1].descriptorCount = 1;
6559 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6560 layout_binding[1].pImmutableSamplers = NULL;
6561
6562 VkSamplerCreateInfo sampler_ci = {};
6563 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6564 sampler_ci.pNext = NULL;
6565 sampler_ci.magFilter = VK_FILTER_NEAREST;
6566 sampler_ci.minFilter = VK_FILTER_NEAREST;
6567 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6568 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6569 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6570 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6571 sampler_ci.mipLodBias = 1.0;
6572 sampler_ci.anisotropyEnable = VK_FALSE;
6573 sampler_ci.maxAnisotropy = 1;
6574 sampler_ci.compareEnable = VK_FALSE;
6575 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6576 sampler_ci.minLod = 1.0;
6577 sampler_ci.maxLod = 1.0;
6578 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6579 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6580 VkSampler sampler;
6581
6582 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6583 ASSERT_VK_SUCCESS(err);
6584
6585 layout_binding[2].binding = 2;
6586 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6587 layout_binding[2].descriptorCount = 1;
6588 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6589 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6590
Mark Muellerd4914412016-06-13 17:52:06 -06006591 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6592 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6593 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6594 ds_layout_ci.pBindings = layout_binding;
6595 VkDescriptorSetLayout ds_layout;
6596 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6597 ASSERT_VK_SUCCESS(err);
6598
6599 VkDescriptorSetAllocateInfo alloc_info = {};
6600 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6601 alloc_info.descriptorSetCount = 1;
6602 alloc_info.descriptorPool = ds_pool;
6603 alloc_info.pSetLayouts = &ds_layout;
6604 VkDescriptorSet descriptorSet;
6605 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6606 ASSERT_VK_SUCCESS(err);
6607
6608 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6609 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6610 pipeline_layout_ci.pNext = NULL;
6611 pipeline_layout_ci.setLayoutCount = 1;
6612 pipeline_layout_ci.pSetLayouts = &ds_layout;
6613
6614 VkPipelineLayout pipeline_layout;
6615 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6616 ASSERT_VK_SUCCESS(err);
6617
Mark Mueller5c838ce2016-06-16 09:54:29 -06006618 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006619 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6620 descriptor_write.dstSet = descriptorSet;
6621 descriptor_write.dstBinding = 0;
6622 descriptor_write.descriptorCount = 1;
6623 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6624
Mark Mueller5c838ce2016-06-16 09:54:29 -06006625 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006626 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6627 m_errorMonitor->VerifyFound();
6628
6629 // Create a buffer to update the descriptor with
6630 uint32_t qfi = 0;
6631 VkBufferCreateInfo buffCI = {};
6632 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6633 buffCI.size = 1024;
6634 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6635 buffCI.queueFamilyIndexCount = 1;
6636 buffCI.pQueueFamilyIndices = &qfi;
6637
6638 VkBuffer dyub;
6639 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6640 ASSERT_VK_SUCCESS(err);
6641 VkDescriptorBufferInfo buffInfo = {};
6642 buffInfo.buffer = dyub;
6643 buffInfo.offset = 0;
6644 buffInfo.range = 1024;
6645
6646 descriptor_write.pBufferInfo = &buffInfo;
6647 descriptor_write.descriptorCount = 2;
6648
Mark Mueller5c838ce2016-06-16 09:54:29 -06006649 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6651 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6652 m_errorMonitor->VerifyFound();
6653
Mark Mueller5c838ce2016-06-16 09:54:29 -06006654 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6655 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006656 descriptor_write.dstBinding = 1;
6657 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006658
Mark Mueller5c838ce2016-06-16 09:54:29 -06006659 // Make pImageInfo index non-null to avoid complaints of it missing
6660 VkDescriptorImageInfo imageInfo = {};
6661 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6662 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6665 m_errorMonitor->VerifyFound();
6666
Mark Muellerd4914412016-06-13 17:52:06 -06006667 vkDestroyBuffer(m_device->device(), dyub, NULL);
6668 vkDestroySampler(m_device->device(), sampler, NULL);
6669 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6671 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6672}
6673
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006674TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6675 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6676 "due to a buffer dependency being destroyed.");
6677 ASSERT_NO_FATAL_FAILURE(InitState());
6678
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006679 VkBuffer buffer;
6680 VkDeviceMemory mem;
6681 VkMemoryRequirements mem_reqs;
6682
6683 VkBufferCreateInfo buf_info = {};
6684 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12006685 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006686 buf_info.size = 256;
6687 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6688 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6689 ASSERT_VK_SUCCESS(err);
6690
6691 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6692
6693 VkMemoryAllocateInfo alloc_info = {};
6694 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6695 alloc_info.allocationSize = 256;
6696 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006697 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 -06006698 if (!pass) {
6699 vkDestroyBuffer(m_device->device(), buffer, NULL);
6700 return;
6701 }
6702 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6703 ASSERT_VK_SUCCESS(err);
6704
6705 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6706 ASSERT_VK_SUCCESS(err);
6707
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006708 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12006709 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006710 m_commandBuffer->EndCommandBuffer();
6711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006713 // Destroy buffer dependency prior to submit to cause ERROR
6714 vkDestroyBuffer(m_device->device(), buffer, NULL);
6715
6716 VkSubmitInfo submit_info = {};
6717 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6718 submit_info.commandBufferCount = 1;
6719 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6721
6722 m_errorMonitor->VerifyFound();
6723 vkFreeMemory(m_device->handle(), mem, NULL);
6724}
6725
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006726TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6727 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6728 "due to an image dependency being destroyed.");
6729 ASSERT_NO_FATAL_FAILURE(InitState());
6730
6731 VkImage image;
6732 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6733 VkImageCreateInfo image_create_info = {};
6734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6735 image_create_info.pNext = NULL;
6736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6737 image_create_info.format = tex_format;
6738 image_create_info.extent.width = 32;
6739 image_create_info.extent.height = 32;
6740 image_create_info.extent.depth = 1;
6741 image_create_info.mipLevels = 1;
6742 image_create_info.arrayLayers = 1;
6743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6744 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006745 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006746 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006748 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006749 // Have to bind memory to image before recording cmd in cmd buffer using it
6750 VkMemoryRequirements mem_reqs;
6751 VkDeviceMemory image_mem;
6752 bool pass;
6753 VkMemoryAllocateInfo mem_alloc = {};
6754 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6755 mem_alloc.pNext = NULL;
6756 mem_alloc.memoryTypeIndex = 0;
6757 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6758 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006760 ASSERT_TRUE(pass);
6761 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6762 ASSERT_VK_SUCCESS(err);
6763 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6764 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006765
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006766 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006767 VkClearColorValue ccv;
6768 ccv.float32[0] = 1.0f;
6769 ccv.float32[1] = 1.0f;
6770 ccv.float32[2] = 1.0f;
6771 ccv.float32[3] = 1.0f;
6772 VkImageSubresourceRange isr = {};
6773 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006774 isr.baseArrayLayer = 0;
6775 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006776 isr.layerCount = 1;
6777 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006778 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006779 m_commandBuffer->EndCommandBuffer();
6780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006782 // Destroy image dependency prior to submit to cause ERROR
6783 vkDestroyImage(m_device->device(), image, NULL);
6784
6785 VkSubmitInfo submit_info = {};
6786 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6787 submit_info.commandBufferCount = 1;
6788 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6789 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6790
6791 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006792 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006793}
6794
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006795TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6796 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6797 "due to a framebuffer image dependency being destroyed.");
6798 VkFormatProperties format_properties;
6799 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006800 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6801 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006802 return;
6803 }
6804
6805 ASSERT_NO_FATAL_FAILURE(InitState());
6806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6807
6808 VkImageCreateInfo image_ci = {};
6809 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6810 image_ci.pNext = NULL;
6811 image_ci.imageType = VK_IMAGE_TYPE_2D;
6812 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6813 image_ci.extent.width = 32;
6814 image_ci.extent.height = 32;
6815 image_ci.extent.depth = 1;
6816 image_ci.mipLevels = 1;
6817 image_ci.arrayLayers = 1;
6818 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6819 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006820 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006821 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6822 image_ci.flags = 0;
6823 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006824 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006825
6826 VkMemoryRequirements memory_reqs;
6827 VkDeviceMemory image_memory;
6828 bool pass;
6829 VkMemoryAllocateInfo memory_info = {};
6830 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6831 memory_info.pNext = NULL;
6832 memory_info.allocationSize = 0;
6833 memory_info.memoryTypeIndex = 0;
6834 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6835 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006836 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006837 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006838 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006839 ASSERT_VK_SUCCESS(err);
6840 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6841 ASSERT_VK_SUCCESS(err);
6842
6843 VkImageViewCreateInfo ivci = {
6844 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6845 nullptr,
6846 0,
6847 image,
6848 VK_IMAGE_VIEW_TYPE_2D,
6849 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006850 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006851 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6852 };
6853 VkImageView view;
6854 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6855 ASSERT_VK_SUCCESS(err);
6856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006857 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006858 VkFramebuffer fb;
6859 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6860 ASSERT_VK_SUCCESS(err);
6861
6862 // Just use default renderpass with our framebuffer
6863 m_renderPassBeginInfo.framebuffer = fb;
6864 // Create Null cmd buffer for submit
6865 BeginCommandBuffer();
6866 EndCommandBuffer();
6867 // Destroy image attached to framebuffer to invalidate cmd buffer
6868 vkDestroyImage(m_device->device(), image, NULL);
6869 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006871 QueueCommandBuffer(false);
6872 m_errorMonitor->VerifyFound();
6873
6874 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6875 vkDestroyImageView(m_device->device(), view, nullptr);
6876 vkFreeMemory(m_device->device(), image_memory, nullptr);
6877}
6878
Tobin Ehlis88becd72016-09-21 14:33:41 -06006879TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
6880 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
6881 VkFormatProperties format_properties;
6882 VkResult err = VK_SUCCESS;
6883 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06006884
6885 ASSERT_NO_FATAL_FAILURE(InitState());
6886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6887
6888 VkImageCreateInfo image_ci = {};
6889 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6890 image_ci.pNext = NULL;
6891 image_ci.imageType = VK_IMAGE_TYPE_2D;
6892 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6893 image_ci.extent.width = 256;
6894 image_ci.extent.height = 256;
6895 image_ci.extent.depth = 1;
6896 image_ci.mipLevels = 1;
6897 image_ci.arrayLayers = 1;
6898 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6899 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06006900 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06006901 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6902 image_ci.flags = 0;
6903 VkImage image;
6904 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
6905
6906 VkMemoryRequirements memory_reqs;
6907 VkDeviceMemory image_memory;
6908 bool pass;
6909 VkMemoryAllocateInfo memory_info = {};
6910 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6911 memory_info.pNext = NULL;
6912 memory_info.allocationSize = 0;
6913 memory_info.memoryTypeIndex = 0;
6914 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6915 memory_info.allocationSize = memory_reqs.size;
6916 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6917 ASSERT_TRUE(pass);
6918 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6919 ASSERT_VK_SUCCESS(err);
6920 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6921 ASSERT_VK_SUCCESS(err);
6922
6923 VkImageViewCreateInfo ivci = {
6924 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6925 nullptr,
6926 0,
6927 image,
6928 VK_IMAGE_VIEW_TYPE_2D,
6929 VK_FORMAT_B8G8R8A8_UNORM,
6930 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
6931 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6932 };
6933 VkImageView view;
6934 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6935 ASSERT_VK_SUCCESS(err);
6936
6937 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
6938 VkFramebuffer fb;
6939 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6940 ASSERT_VK_SUCCESS(err);
6941
6942 // Just use default renderpass with our framebuffer
6943 m_renderPassBeginInfo.framebuffer = fb;
6944 // Create Null cmd buffer for submit
6945 BeginCommandBuffer();
6946 EndCommandBuffer();
6947 // Submit cmd buffer to put it (and attached imageView) in-flight
6948 VkSubmitInfo submit_info = {};
6949 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6950 submit_info.commandBufferCount = 1;
6951 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6952 // Submit cmd buffer to put framebuffer and children in-flight
6953 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6954 // Destroy image attached to framebuffer while in-flight
6955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
6956 vkDestroyImage(m_device->device(), image, NULL);
6957 m_errorMonitor->VerifyFound();
6958 // Wait for queue to complete so we can safely destroy image and other objects
6959 vkQueueWaitIdle(m_device->m_queue);
6960 vkDestroyImage(m_device->device(), image, NULL);
6961 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6962 vkDestroyImageView(m_device->device(), view, nullptr);
6963 vkFreeMemory(m_device->device(), image_memory, nullptr);
6964}
6965
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006966TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006967 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006968 ASSERT_NO_FATAL_FAILURE(InitState());
6969
6970 VkImage image;
6971 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6972 VkImageCreateInfo image_create_info = {};
6973 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6974 image_create_info.pNext = NULL;
6975 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6976 image_create_info.format = tex_format;
6977 image_create_info.extent.width = 32;
6978 image_create_info.extent.height = 32;
6979 image_create_info.extent.depth = 1;
6980 image_create_info.mipLevels = 1;
6981 image_create_info.arrayLayers = 1;
6982 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6983 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006985 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006986 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006987 ASSERT_VK_SUCCESS(err);
6988 // Have to bind memory to image before recording cmd in cmd buffer using it
6989 VkMemoryRequirements mem_reqs;
6990 VkDeviceMemory image_mem;
6991 bool pass;
6992 VkMemoryAllocateInfo mem_alloc = {};
6993 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6994 mem_alloc.pNext = NULL;
6995 mem_alloc.memoryTypeIndex = 0;
6996 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6997 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006998 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006999 ASSERT_TRUE(pass);
7000 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7001 ASSERT_VK_SUCCESS(err);
7002
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007003 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
7004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7005 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007006
7007 m_commandBuffer->BeginCommandBuffer();
7008 VkClearColorValue ccv;
7009 ccv.float32[0] = 1.0f;
7010 ccv.float32[1] = 1.0f;
7011 ccv.float32[2] = 1.0f;
7012 ccv.float32[3] = 1.0f;
7013 VkImageSubresourceRange isr = {};
7014 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7015 isr.baseArrayLayer = 0;
7016 isr.baseMipLevel = 0;
7017 isr.layerCount = 1;
7018 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007019 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007020 m_commandBuffer->EndCommandBuffer();
7021
7022 m_errorMonitor->VerifyFound();
7023 vkDestroyImage(m_device->device(), image, NULL);
7024 vkFreeMemory(m_device->device(), image_mem, nullptr);
7025}
7026
7027TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007028 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007029 ASSERT_NO_FATAL_FAILURE(InitState());
7030
7031 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 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 -06007033 VK_IMAGE_TILING_OPTIMAL, 0);
7034 ASSERT_TRUE(image.initialized());
7035
7036 VkBuffer buffer;
7037 VkDeviceMemory mem;
7038 VkMemoryRequirements mem_reqs;
7039
7040 VkBufferCreateInfo buf_info = {};
7041 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12007042 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007043 buf_info.size = 256;
7044 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7045 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
7046 ASSERT_VK_SUCCESS(err);
7047
7048 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
7049
7050 VkMemoryAllocateInfo alloc_info = {};
7051 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7052 alloc_info.allocationSize = 256;
7053 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007054 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 -06007055 if (!pass) {
7056 vkDestroyBuffer(m_device->device(), buffer, NULL);
7057 return;
7058 }
7059 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
7060 ASSERT_VK_SUCCESS(err);
7061
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007062 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7064 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007065 VkBufferImageCopy region = {};
7066 region.bufferRowLength = 128;
7067 region.bufferImageHeight = 128;
7068 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7069
7070 region.imageSubresource.layerCount = 1;
7071 region.imageExtent.height = 4;
7072 region.imageExtent.width = 4;
7073 region.imageExtent.depth = 1;
7074 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
7076 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007077 m_commandBuffer->EndCommandBuffer();
7078
7079 m_errorMonitor->VerifyFound();
7080
7081 vkDestroyBuffer(m_device->device(), buffer, NULL);
7082 vkFreeMemory(m_device->handle(), mem, NULL);
7083}
7084
Tobin Ehlis85940f52016-07-07 16:57:21 -06007085TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7086 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7087 "due to an event dependency being destroyed.");
7088 ASSERT_NO_FATAL_FAILURE(InitState());
7089
7090 VkEvent event;
7091 VkEventCreateInfo evci = {};
7092 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7093 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7094 ASSERT_VK_SUCCESS(result);
7095
7096 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007097 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007098 m_commandBuffer->EndCommandBuffer();
7099
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007101 // Destroy event dependency prior to submit to cause ERROR
7102 vkDestroyEvent(m_device->device(), event, NULL);
7103
7104 VkSubmitInfo submit_info = {};
7105 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7106 submit_info.commandBufferCount = 1;
7107 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7108 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7109
7110 m_errorMonitor->VerifyFound();
7111}
7112
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007113TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7114 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7115 "due to a query pool dependency being destroyed.");
7116 ASSERT_NO_FATAL_FAILURE(InitState());
7117
7118 VkQueryPool query_pool;
7119 VkQueryPoolCreateInfo qpci{};
7120 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7121 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7122 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007124 ASSERT_VK_SUCCESS(result);
7125
7126 m_commandBuffer->BeginCommandBuffer();
7127 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7128 m_commandBuffer->EndCommandBuffer();
7129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007131 // Destroy query pool dependency prior to submit to cause ERROR
7132 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7133
7134 VkSubmitInfo submit_info = {};
7135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7136 submit_info.commandBufferCount = 1;
7137 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7139
7140 m_errorMonitor->VerifyFound();
7141}
7142
Tobin Ehlis24130d92016-07-08 15:50:53 -06007143TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7144 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7145 "due to a pipeline dependency being destroyed.");
7146 ASSERT_NO_FATAL_FAILURE(InitState());
7147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7148
7149 VkResult err;
7150
7151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7153
7154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007156 ASSERT_VK_SUCCESS(err);
7157
7158 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7159 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7160 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007161 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007162 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007163 vp_state_ci.scissorCount = 1;
7164 VkRect2D scissors = {}; // Dummy scissors to point to
7165 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007166
7167 VkPipelineShaderStageCreateInfo shaderStages[2];
7168 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7169
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7171 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7172 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007173 shaderStages[0] = vs.GetStageCreateInfo();
7174 shaderStages[1] = fs.GetStageCreateInfo();
7175
7176 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7177 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7178
7179 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7180 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7181 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7182
7183 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7184 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12007185 rs_ci.rasterizerDiscardEnable = true;
7186 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007187
7188 VkPipelineColorBlendAttachmentState att = {};
7189 att.blendEnable = VK_FALSE;
7190 att.colorWriteMask = 0xf;
7191
7192 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7193 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7194 cb_ci.attachmentCount = 1;
7195 cb_ci.pAttachments = &att;
7196
7197 VkGraphicsPipelineCreateInfo gp_ci = {};
7198 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7199 gp_ci.stageCount = 2;
7200 gp_ci.pStages = shaderStages;
7201 gp_ci.pVertexInputState = &vi_ci;
7202 gp_ci.pInputAssemblyState = &ia_ci;
7203 gp_ci.pViewportState = &vp_state_ci;
7204 gp_ci.pRasterizationState = &rs_ci;
7205 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007206 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7207 gp_ci.layout = pipeline_layout;
7208 gp_ci.renderPass = renderPass();
7209
7210 VkPipelineCacheCreateInfo pc_ci = {};
7211 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7212
7213 VkPipeline pipeline;
7214 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007215 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007216 ASSERT_VK_SUCCESS(err);
7217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007218 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007219 ASSERT_VK_SUCCESS(err);
7220
7221 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007223 m_commandBuffer->EndCommandBuffer();
7224 // Now destroy pipeline in order to cause error when submitting
7225 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007228
7229 VkSubmitInfo submit_info = {};
7230 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7231 submit_info.commandBufferCount = 1;
7232 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7233 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7234
7235 m_errorMonitor->VerifyFound();
7236 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7237 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7238}
7239
Tobin Ehlis31289162016-08-17 14:57:58 -06007240TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7241 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7242 "due to a bound descriptor set with a buffer dependency "
7243 "being destroyed.");
7244 ASSERT_NO_FATAL_FAILURE(InitState());
7245 ASSERT_NO_FATAL_FAILURE(InitViewport());
7246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7247
7248 VkDescriptorPoolSize ds_type_count = {};
7249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7250 ds_type_count.descriptorCount = 1;
7251
7252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7254 ds_pool_ci.pNext = NULL;
7255 ds_pool_ci.maxSets = 1;
7256 ds_pool_ci.poolSizeCount = 1;
7257 ds_pool_ci.pPoolSizes = &ds_type_count;
7258
7259 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007260 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007261 ASSERT_VK_SUCCESS(err);
7262
7263 VkDescriptorSetLayoutBinding dsl_binding = {};
7264 dsl_binding.binding = 0;
7265 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7266 dsl_binding.descriptorCount = 1;
7267 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7268 dsl_binding.pImmutableSamplers = NULL;
7269
7270 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7271 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7272 ds_layout_ci.pNext = NULL;
7273 ds_layout_ci.bindingCount = 1;
7274 ds_layout_ci.pBindings = &dsl_binding;
7275 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007276 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007277 ASSERT_VK_SUCCESS(err);
7278
7279 VkDescriptorSet descriptorSet;
7280 VkDescriptorSetAllocateInfo alloc_info = {};
7281 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7282 alloc_info.descriptorSetCount = 1;
7283 alloc_info.descriptorPool = ds_pool;
7284 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007285 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007286 ASSERT_VK_SUCCESS(err);
7287
7288 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7289 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7290 pipeline_layout_ci.pNext = NULL;
7291 pipeline_layout_ci.setLayoutCount = 1;
7292 pipeline_layout_ci.pSetLayouts = &ds_layout;
7293
7294 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007295 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007296 ASSERT_VK_SUCCESS(err);
7297
7298 // Create a buffer to update the descriptor with
7299 uint32_t qfi = 0;
7300 VkBufferCreateInfo buffCI = {};
7301 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7302 buffCI.size = 1024;
7303 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7304 buffCI.queueFamilyIndexCount = 1;
7305 buffCI.pQueueFamilyIndices = &qfi;
7306
7307 VkBuffer buffer;
7308 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7309 ASSERT_VK_SUCCESS(err);
7310 // Allocate memory and bind to buffer so we can make it to the appropriate
7311 // error
7312 VkMemoryAllocateInfo mem_alloc = {};
7313 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7314 mem_alloc.pNext = NULL;
7315 mem_alloc.allocationSize = 1024;
7316 mem_alloc.memoryTypeIndex = 0;
7317
7318 VkMemoryRequirements memReqs;
7319 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007320 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007321 if (!pass) {
7322 vkDestroyBuffer(m_device->device(), buffer, NULL);
7323 return;
7324 }
7325
7326 VkDeviceMemory mem;
7327 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7328 ASSERT_VK_SUCCESS(err);
7329 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7330 ASSERT_VK_SUCCESS(err);
7331 // Correctly update descriptor to avoid "NOT_UPDATED" error
7332 VkDescriptorBufferInfo buffInfo = {};
7333 buffInfo.buffer = buffer;
7334 buffInfo.offset = 0;
7335 buffInfo.range = 1024;
7336
7337 VkWriteDescriptorSet descriptor_write;
7338 memset(&descriptor_write, 0, sizeof(descriptor_write));
7339 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7340 descriptor_write.dstSet = descriptorSet;
7341 descriptor_write.dstBinding = 0;
7342 descriptor_write.descriptorCount = 1;
7343 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7344 descriptor_write.pBufferInfo = &buffInfo;
7345
7346 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7347
7348 // Create PSO to be used for draw-time errors below
7349 char const *vsSource = "#version 450\n"
7350 "\n"
7351 "out gl_PerVertex { \n"
7352 " vec4 gl_Position;\n"
7353 "};\n"
7354 "void main(){\n"
7355 " gl_Position = vec4(1);\n"
7356 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 char const *fsSource = "#version 450\n"
7358 "\n"
7359 "layout(location=0) out vec4 x;\n"
7360 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7361 "void main(){\n"
7362 " x = vec4(bar.y);\n"
7363 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007364 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7366 VkPipelineObj pipe(m_device);
7367 pipe.AddShader(&vs);
7368 pipe.AddShader(&fs);
7369 pipe.AddColorAttachment();
7370 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7371
7372 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7374 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7375 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007376 Draw(1, 0, 0, 0);
7377 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007379 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7380 vkDestroyBuffer(m_device->device(), buffer, NULL);
7381 // Attempt to submit cmd buffer
7382 VkSubmitInfo submit_info = {};
7383 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7384 submit_info.commandBufferCount = 1;
7385 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7386 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7387 m_errorMonitor->VerifyFound();
7388 // Cleanup
7389 vkFreeMemory(m_device->device(), mem, NULL);
7390
7391 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7392 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7393 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7394}
7395
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007396TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7397 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7398 "due to a bound descriptor sets with a combined image "
7399 "sampler having their image, sampler, and descriptor set "
7400 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007401 "submit associated cmd buffers. Attempt to destroy a "
7402 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007403 ASSERT_NO_FATAL_FAILURE(InitState());
7404 ASSERT_NO_FATAL_FAILURE(InitViewport());
7405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7406
7407 VkDescriptorPoolSize ds_type_count = {};
7408 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7409 ds_type_count.descriptorCount = 1;
7410
7411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7413 ds_pool_ci.pNext = NULL;
7414 ds_pool_ci.maxSets = 1;
7415 ds_pool_ci.poolSizeCount = 1;
7416 ds_pool_ci.pPoolSizes = &ds_type_count;
7417
7418 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007420 ASSERT_VK_SUCCESS(err);
7421
7422 VkDescriptorSetLayoutBinding dsl_binding = {};
7423 dsl_binding.binding = 0;
7424 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7425 dsl_binding.descriptorCount = 1;
7426 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7427 dsl_binding.pImmutableSamplers = NULL;
7428
7429 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7430 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7431 ds_layout_ci.pNext = NULL;
7432 ds_layout_ci.bindingCount = 1;
7433 ds_layout_ci.pBindings = &dsl_binding;
7434 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007436 ASSERT_VK_SUCCESS(err);
7437
7438 VkDescriptorSet descriptorSet;
7439 VkDescriptorSetAllocateInfo alloc_info = {};
7440 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7441 alloc_info.descriptorSetCount = 1;
7442 alloc_info.descriptorPool = ds_pool;
7443 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007444 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007445 ASSERT_VK_SUCCESS(err);
7446
7447 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7448 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7449 pipeline_layout_ci.pNext = NULL;
7450 pipeline_layout_ci.setLayoutCount = 1;
7451 pipeline_layout_ci.pSetLayouts = &ds_layout;
7452
7453 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007454 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007455 ASSERT_VK_SUCCESS(err);
7456
7457 // Create images to update the descriptor with
7458 VkImage image;
7459 VkImage image2;
7460 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7461 const int32_t tex_width = 32;
7462 const int32_t tex_height = 32;
7463 VkImageCreateInfo image_create_info = {};
7464 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7465 image_create_info.pNext = NULL;
7466 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7467 image_create_info.format = tex_format;
7468 image_create_info.extent.width = tex_width;
7469 image_create_info.extent.height = tex_height;
7470 image_create_info.extent.depth = 1;
7471 image_create_info.mipLevels = 1;
7472 image_create_info.arrayLayers = 1;
7473 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7474 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7475 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7476 image_create_info.flags = 0;
7477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7478 ASSERT_VK_SUCCESS(err);
7479 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7480 ASSERT_VK_SUCCESS(err);
7481
7482 VkMemoryRequirements memory_reqs;
7483 VkDeviceMemory image_memory;
7484 bool pass;
7485 VkMemoryAllocateInfo memory_info = {};
7486 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7487 memory_info.pNext = NULL;
7488 memory_info.allocationSize = 0;
7489 memory_info.memoryTypeIndex = 0;
7490 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7491 // Allocate enough memory for both images
7492 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007494 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007495 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007496 ASSERT_VK_SUCCESS(err);
7497 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7498 ASSERT_VK_SUCCESS(err);
7499 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007501 ASSERT_VK_SUCCESS(err);
7502
7503 VkImageViewCreateInfo image_view_create_info = {};
7504 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7505 image_view_create_info.image = image;
7506 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7507 image_view_create_info.format = tex_format;
7508 image_view_create_info.subresourceRange.layerCount = 1;
7509 image_view_create_info.subresourceRange.baseMipLevel = 0;
7510 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007512
7513 VkImageView view;
7514 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007515 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007516 ASSERT_VK_SUCCESS(err);
7517 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007518 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007519 ASSERT_VK_SUCCESS(err);
7520 // Create Samplers
7521 VkSamplerCreateInfo sampler_ci = {};
7522 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7523 sampler_ci.pNext = NULL;
7524 sampler_ci.magFilter = VK_FILTER_NEAREST;
7525 sampler_ci.minFilter = VK_FILTER_NEAREST;
7526 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7527 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7528 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7529 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7530 sampler_ci.mipLodBias = 1.0;
7531 sampler_ci.anisotropyEnable = VK_FALSE;
7532 sampler_ci.maxAnisotropy = 1;
7533 sampler_ci.compareEnable = VK_FALSE;
7534 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7535 sampler_ci.minLod = 1.0;
7536 sampler_ci.maxLod = 1.0;
7537 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7538 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7539 VkSampler sampler;
7540 VkSampler sampler2;
7541 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7542 ASSERT_VK_SUCCESS(err);
7543 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7544 ASSERT_VK_SUCCESS(err);
7545 // Update descriptor with image and sampler
7546 VkDescriptorImageInfo img_info = {};
7547 img_info.sampler = sampler;
7548 img_info.imageView = view;
7549 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7550
7551 VkWriteDescriptorSet descriptor_write;
7552 memset(&descriptor_write, 0, sizeof(descriptor_write));
7553 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7554 descriptor_write.dstSet = descriptorSet;
7555 descriptor_write.dstBinding = 0;
7556 descriptor_write.descriptorCount = 1;
7557 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7558 descriptor_write.pImageInfo = &img_info;
7559
7560 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7561
7562 // Create PSO to be used for draw-time errors below
7563 char const *vsSource = "#version 450\n"
7564 "\n"
7565 "out gl_PerVertex { \n"
7566 " vec4 gl_Position;\n"
7567 "};\n"
7568 "void main(){\n"
7569 " gl_Position = vec4(1);\n"
7570 "}\n";
7571 char const *fsSource = "#version 450\n"
7572 "\n"
7573 "layout(set=0, binding=0) uniform sampler2D s;\n"
7574 "layout(location=0) out vec4 x;\n"
7575 "void main(){\n"
7576 " x = texture(s, vec2(1));\n"
7577 "}\n";
7578 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7579 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7580 VkPipelineObj pipe(m_device);
7581 pipe.AddShader(&vs);
7582 pipe.AddShader(&fs);
7583 pipe.AddColorAttachment();
7584 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7585
7586 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007588 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7590 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7591 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007592 Draw(1, 0, 0, 0);
7593 EndCommandBuffer();
7594 // Destroy sampler invalidates the cmd buffer, causing error on submit
7595 vkDestroySampler(m_device->device(), sampler, NULL);
7596 // Attempt to submit cmd buffer
7597 VkSubmitInfo submit_info = {};
7598 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7599 submit_info.commandBufferCount = 1;
7600 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7601 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7602 m_errorMonitor->VerifyFound();
7603 // Now re-update descriptor with valid sampler and delete image
7604 img_info.sampler = sampler2;
7605 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007607 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007608 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7609 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7610 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007611 Draw(1, 0, 0, 0);
7612 EndCommandBuffer();
7613 // Destroy image invalidates the cmd buffer, causing error on submit
7614 vkDestroyImage(m_device->device(), image, NULL);
7615 // Attempt to submit cmd buffer
7616 submit_info = {};
7617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7618 submit_info.commandBufferCount = 1;
7619 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7620 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7621 m_errorMonitor->VerifyFound();
7622 // Now update descriptor to be valid, but then free descriptor
7623 img_info.imageView = view2;
7624 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007626 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007627 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7628 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7629 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007630 Draw(1, 0, 0, 0);
7631 EndCommandBuffer();
7632 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007634 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007635 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007636 // Attempt to submit cmd buffer
7637 submit_info = {};
7638 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7639 submit_info.commandBufferCount = 1;
7640 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7641 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7642 m_errorMonitor->VerifyFound();
7643 // Cleanup
7644 vkFreeMemory(m_device->device(), image_memory, NULL);
7645 vkDestroySampler(m_device->device(), sampler2, NULL);
7646 vkDestroyImage(m_device->device(), image2, NULL);
7647 vkDestroyImageView(m_device->device(), view, NULL);
7648 vkDestroyImageView(m_device->device(), view2, NULL);
7649 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7650 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7651 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7652}
7653
Karl Schultz6addd812016-02-02 17:17:23 -07007654TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007655 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7656 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007657 // Create a valid cmd buffer
7658 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007659 uint64_t fake_pipeline_handle = 0xbaad6001;
7660 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06007661 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7663
7664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007665 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007666 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007667 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007668
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007669 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007670 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 -06007671 Draw(1, 0, 0, 0);
7672 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007673
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007674 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007675 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 +12007676 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007677 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7678 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007679}
7680
Karl Schultz6addd812016-02-02 17:17:23 -07007681TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007682 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007683 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007686
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007687 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007688 ASSERT_NO_FATAL_FAILURE(InitViewport());
7689 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007690 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007691 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7692 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007693
7694 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007695 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7696 ds_pool_ci.pNext = NULL;
7697 ds_pool_ci.maxSets = 1;
7698 ds_pool_ci.poolSizeCount = 1;
7699 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007700
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007701 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007702 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007703 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007704
Tony Barboureb254902015-07-15 12:50:33 -06007705 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007706 dsl_binding.binding = 0;
7707 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7708 dsl_binding.descriptorCount = 1;
7709 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7710 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007711
Tony Barboureb254902015-07-15 12:50:33 -06007712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7714 ds_layout_ci.pNext = NULL;
7715 ds_layout_ci.bindingCount = 1;
7716 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007717 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007719 ASSERT_VK_SUCCESS(err);
7720
7721 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007722 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007723 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007724 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007725 alloc_info.descriptorPool = ds_pool;
7726 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007727 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007728 ASSERT_VK_SUCCESS(err);
7729
Tony Barboureb254902015-07-15 12:50:33 -06007730 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7732 pipeline_layout_ci.pNext = NULL;
7733 pipeline_layout_ci.setLayoutCount = 1;
7734 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007735
7736 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007737 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007738 ASSERT_VK_SUCCESS(err);
7739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007740 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007741 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007742 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007744
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007745 VkPipelineObj pipe(m_device);
7746 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007747 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007748 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007749 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007750
7751 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007752 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7753 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7754 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007756 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007757
Chia-I Wuf7458c52015-10-26 21:10:41 +08007758 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7759 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7760 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007761}
7762
Karl Schultz6addd812016-02-02 17:17:23 -07007763TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007764 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007765 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007766
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7768 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007769
7770 ASSERT_NO_FATAL_FAILURE(InitState());
7771 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007772 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7773 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007774
7775 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007776 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7777 ds_pool_ci.pNext = NULL;
7778 ds_pool_ci.maxSets = 1;
7779 ds_pool_ci.poolSizeCount = 1;
7780 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007781
7782 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007783 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007784 ASSERT_VK_SUCCESS(err);
7785
7786 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007787 dsl_binding.binding = 0;
7788 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7789 dsl_binding.descriptorCount = 1;
7790 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7791 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007792
7793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7795 ds_layout_ci.pNext = NULL;
7796 ds_layout_ci.bindingCount = 1;
7797 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007798 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007800 ASSERT_VK_SUCCESS(err);
7801
7802 VkDescriptorSet descriptorSet;
7803 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007804 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007805 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007806 alloc_info.descriptorPool = ds_pool;
7807 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007808 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007809 ASSERT_VK_SUCCESS(err);
7810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007811 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007812 VkWriteDescriptorSet descriptor_write;
7813 memset(&descriptor_write, 0, sizeof(descriptor_write));
7814 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7815 descriptor_write.dstSet = descriptorSet;
7816 descriptor_write.dstBinding = 0;
7817 descriptor_write.descriptorCount = 1;
7818 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7819 descriptor_write.pTexelBufferView = &view;
7820
7821 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007823 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007824
7825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7827}
7828
Mark Youngd339ba32016-05-30 13:28:35 -06007829TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
7830 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has"
7831 " no memory bound to it.");
7832
7833 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7835 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Youngd339ba32016-05-30 13:28:35 -06007836
7837 ASSERT_NO_FATAL_FAILURE(InitState());
7838
7839 // Create a buffer with no bound memory and then attempt to create
7840 // a buffer view.
7841 VkBufferCreateInfo buff_ci = {};
7842 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12007843 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06007844 buff_ci.size = 256;
7845 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7846 VkBuffer buffer;
7847 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7848 ASSERT_VK_SUCCESS(err);
7849
7850 VkBufferViewCreateInfo buff_view_ci = {};
7851 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7852 buff_view_ci.buffer = buffer;
7853 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7854 buff_view_ci.range = VK_WHOLE_SIZE;
7855 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007856 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06007857
7858 m_errorMonitor->VerifyFound();
7859 vkDestroyBuffer(m_device->device(), buffer, NULL);
7860 // If last error is success, it still created the view, so delete it.
7861 if (err == VK_SUCCESS) {
7862 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7863 }
7864}
7865
Karl Schultz6addd812016-02-02 17:17:23 -07007866TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
7867 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
7868 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07007869 // 1. No dynamicOffset supplied
7870 // 2. Too many dynamicOffsets supplied
7871 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07007872 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
7874 "0 dynamicOffsets are left in "
7875 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007876
7877 ASSERT_NO_FATAL_FAILURE(InitState());
7878 ASSERT_NO_FATAL_FAILURE(InitViewport());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7880
7881 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7883 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007884
7885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7887 ds_pool_ci.pNext = NULL;
7888 ds_pool_ci.maxSets = 1;
7889 ds_pool_ci.poolSizeCount = 1;
7890 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007891
7892 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007894 ASSERT_VK_SUCCESS(err);
7895
7896 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007897 dsl_binding.binding = 0;
7898 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7899 dsl_binding.descriptorCount = 1;
7900 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7901 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007902
7903 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007904 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7905 ds_layout_ci.pNext = NULL;
7906 ds_layout_ci.bindingCount = 1;
7907 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007908 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007910 ASSERT_VK_SUCCESS(err);
7911
7912 VkDescriptorSet descriptorSet;
7913 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007914 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007915 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007916 alloc_info.descriptorPool = ds_pool;
7917 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007918 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007919 ASSERT_VK_SUCCESS(err);
7920
7921 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007922 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7923 pipeline_layout_ci.pNext = NULL;
7924 pipeline_layout_ci.setLayoutCount = 1;
7925 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007926
7927 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007929 ASSERT_VK_SUCCESS(err);
7930
7931 // Create a buffer to update the descriptor with
7932 uint32_t qfi = 0;
7933 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007934 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7935 buffCI.size = 1024;
7936 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7937 buffCI.queueFamilyIndexCount = 1;
7938 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007939
7940 VkBuffer dyub;
7941 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007943 // Allocate memory and bind to buffer so we can make it to the appropriate
7944 // error
7945 VkMemoryAllocateInfo mem_alloc = {};
7946 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7947 mem_alloc.pNext = NULL;
7948 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12007949 mem_alloc.memoryTypeIndex = 0;
7950
7951 VkMemoryRequirements memReqs;
7952 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12007954 if (!pass) {
7955 vkDestroyBuffer(m_device->device(), dyub, NULL);
7956 return;
7957 }
7958
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007959 VkDeviceMemory mem;
7960 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7961 ASSERT_VK_SUCCESS(err);
7962 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
7963 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007964 // Correctly update descriptor to avoid "NOT_UPDATED" error
7965 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007966 buffInfo.buffer = dyub;
7967 buffInfo.offset = 0;
7968 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07007969
7970 VkWriteDescriptorSet descriptor_write;
7971 memset(&descriptor_write, 0, sizeof(descriptor_write));
7972 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7973 descriptor_write.dstSet = descriptorSet;
7974 descriptor_write.dstBinding = 0;
7975 descriptor_write.descriptorCount = 1;
7976 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7977 descriptor_write.pBufferInfo = &buffInfo;
7978
7979 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7980
7981 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7983 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007984 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007985 uint32_t pDynOff[2] = {512, 756};
7986 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7988 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
7989 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7990 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12007991 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07007992 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
7994 "offset 0 and range 1024 that "
7995 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07007996 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007997 char const *vsSource = "#version 450\n"
7998 "\n"
7999 "out gl_PerVertex { \n"
8000 " vec4 gl_Position;\n"
8001 "};\n"
8002 "void main(){\n"
8003 " gl_Position = vec4(1);\n"
8004 "}\n";
8005 char const *fsSource = "#version 450\n"
8006 "\n"
8007 "layout(location=0) out vec4 x;\n"
8008 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8009 "void main(){\n"
8010 " x = vec4(bar.y);\n"
8011 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07008012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8014 VkPipelineObj pipe(m_device);
8015 pipe.AddShader(&vs);
8016 pipe.AddShader(&fs);
8017 pipe.AddColorAttachment();
8018 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008020 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008021 // This update should succeed, but offset size of 512 will overstep buffer
8022 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008023 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8024 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07008025 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008026 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008027
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008028 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06008029 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008030
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008031 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008032 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008033 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8034}
8035
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008036TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
8037 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
8038 "that doesn't have memory bound");
8039 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8041 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
8042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8043 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008044
8045 ASSERT_NO_FATAL_FAILURE(InitState());
8046 ASSERT_NO_FATAL_FAILURE(InitViewport());
8047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8048
8049 VkDescriptorPoolSize ds_type_count = {};
8050 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8051 ds_type_count.descriptorCount = 1;
8052
8053 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8054 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8055 ds_pool_ci.pNext = NULL;
8056 ds_pool_ci.maxSets = 1;
8057 ds_pool_ci.poolSizeCount = 1;
8058 ds_pool_ci.pPoolSizes = &ds_type_count;
8059
8060 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008062 ASSERT_VK_SUCCESS(err);
8063
8064 VkDescriptorSetLayoutBinding dsl_binding = {};
8065 dsl_binding.binding = 0;
8066 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8067 dsl_binding.descriptorCount = 1;
8068 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8069 dsl_binding.pImmutableSamplers = NULL;
8070
8071 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8072 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8073 ds_layout_ci.pNext = NULL;
8074 ds_layout_ci.bindingCount = 1;
8075 ds_layout_ci.pBindings = &dsl_binding;
8076 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008077 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008078 ASSERT_VK_SUCCESS(err);
8079
8080 VkDescriptorSet descriptorSet;
8081 VkDescriptorSetAllocateInfo alloc_info = {};
8082 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8083 alloc_info.descriptorSetCount = 1;
8084 alloc_info.descriptorPool = ds_pool;
8085 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008086 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008087 ASSERT_VK_SUCCESS(err);
8088
8089 // Create a buffer to update the descriptor with
8090 uint32_t qfi = 0;
8091 VkBufferCreateInfo buffCI = {};
8092 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8093 buffCI.size = 1024;
8094 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8095 buffCI.queueFamilyIndexCount = 1;
8096 buffCI.pQueueFamilyIndices = &qfi;
8097
8098 VkBuffer dyub;
8099 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8100 ASSERT_VK_SUCCESS(err);
8101
8102 // Attempt to update descriptor without binding memory to it
8103 VkDescriptorBufferInfo buffInfo = {};
8104 buffInfo.buffer = dyub;
8105 buffInfo.offset = 0;
8106 buffInfo.range = 1024;
8107
8108 VkWriteDescriptorSet descriptor_write;
8109 memset(&descriptor_write, 0, sizeof(descriptor_write));
8110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8111 descriptor_write.dstSet = descriptorSet;
8112 descriptor_write.dstBinding = 0;
8113 descriptor_write.descriptorCount = 1;
8114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8115 descriptor_write.pBufferInfo = &buffInfo;
8116
8117 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8118 m_errorMonitor->VerifyFound();
8119
8120 vkDestroyBuffer(m_device->device(), dyub, NULL);
8121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8123}
8124
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008125TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008126 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008127 ASSERT_NO_FATAL_FAILURE(InitState());
8128 ASSERT_NO_FATAL_FAILURE(InitViewport());
8129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8130
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008131 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008132 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008133 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8134 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8135 pipeline_layout_ci.pushConstantRangeCount = 1;
8136 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8137
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008138 //
8139 // Check for invalid push constant ranges in pipeline layouts.
8140 //
8141 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008142 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008143 char const *msg;
8144 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008145
Karl Schultzc81037d2016-05-12 08:11:23 -06008146 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8147 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8148 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8149 "vkCreatePipelineLayout() call has push constants index 0 with "
8150 "size 0."},
8151 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8152 "vkCreatePipelineLayout() call has push constants index 0 with "
8153 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008154 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008155 "vkCreatePipelineLayout() call has push constants index 0 with "
8156 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008157 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008158 "vkCreatePipelineLayout() call has push constants index 0 with "
8159 "size 0."},
8160 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8161 "vkCreatePipelineLayout() call has push constants index 0 with "
8162 "offset 1. Offset must"},
8163 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8164 "vkCreatePipelineLayout() call has push constants index 0 "
8165 "with offset "},
8166 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8167 "vkCreatePipelineLayout() call has push constants "
8168 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008169 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008170 "vkCreatePipelineLayout() call has push constants index 0 "
8171 "with offset "},
8172 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8173 "vkCreatePipelineLayout() call has push "
8174 "constants index 0 with offset "},
8175 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8176 "vkCreatePipelineLayout() call has push "
8177 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008178 }};
8179
8180 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008181 for (const auto &iter : range_tests) {
8182 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008185 m_errorMonitor->VerifyFound();
8186 if (VK_SUCCESS == err) {
8187 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8188 }
8189 }
8190
8191 // Check for invalid stage flag
8192 pc_range.offset = 0;
8193 pc_range.size = 16;
8194 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008195 m_errorMonitor->SetDesiredFailureMsg(
8196 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8197 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008199 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008200 if (VK_SUCCESS == err) {
8201 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8202 }
8203
8204 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008205 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008206 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008207 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008208 char const *msg;
8209 };
8210
Karl Schultzc81037d2016-05-12 08:11:23 -06008211 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008212 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8213 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8214 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8215 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8216 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008217 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008218 {
8219 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8220 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8221 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8222 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8223 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008224 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008225 },
8226 {
8227 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8228 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8229 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8230 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8231 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008232 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008233 },
8234 {
8235 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8236 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8237 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8238 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8239 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008240 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008241 },
8242 {
8243 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8244 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8245 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8246 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8247 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008248 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008249 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008250
Karl Schultzc81037d2016-05-12 08:11:23 -06008251 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008252 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008253 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8255 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008256 m_errorMonitor->VerifyFound();
8257 if (VK_SUCCESS == err) {
8258 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8259 }
8260 }
8261
8262 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008263 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8264 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8265 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8266 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8267 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8268 ""},
8269 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8270 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8271 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8272 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8273 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8274 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008275 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008276 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8277 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008279 m_errorMonitor->VerifyNotFound();
8280 if (VK_SUCCESS == err) {
8281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8282 }
8283 }
8284
8285 //
8286 // CmdPushConstants tests
8287 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008288 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008289
8290 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008291 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8292 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008293 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8294 "vkCmdPushConstants() call has push constants with size 1. Size "
8295 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008296 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008297 "vkCmdPushConstants() call has push constants with size 1. Size "
8298 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008299 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008300 "vkCmdPushConstants() call has push constants with offset 1. "
8301 "Offset must be a multiple of 4."},
8302 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8303 "vkCmdPushConstants() call has push constants with offset 1. "
8304 "Offset must be a multiple of 4."},
8305 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8306 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8307 "0x1 not within flag-matching ranges in pipeline layout"},
8308 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8309 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8310 "0x1 not within flag-matching ranges in pipeline layout"},
8311 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8312 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8313 "0x1 not within flag-matching ranges in pipeline layout"},
8314 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8315 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8316 "0x1 not within flag-matching ranges in pipeline layout"},
8317 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8318 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8319 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008321 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8322 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008323 }};
8324
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008325 BeginCommandBuffer();
8326
8327 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008328 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008329 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008330 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008332 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008334 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008335 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8337 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008338 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008339 m_errorMonitor->VerifyFound();
8340 }
8341
8342 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008345 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008346 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008347
Karl Schultzc81037d2016-05-12 08:11:23 -06008348 // overlapping range tests with cmd
8349 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8350 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8351 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8352 "0x1 not within flag-matching ranges in pipeline layout"},
8353 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8354 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8355 "0x1 not within flag-matching ranges in pipeline layout"},
8356 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8357 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8358 "0x1 not within flag-matching ranges in pipeline layout"},
8359 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008360 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008361 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008362 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8363 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008364 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008366 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008368 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008369 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8371 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008372 iter.range.size, dummy_values);
8373 m_errorMonitor->VerifyFound();
8374 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008375 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8376
8377 // positive overlapping range tests with cmd
8378 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8379 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8380 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8381 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8382 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8383 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008384 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008385 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008386 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8387 {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 -06008388 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008389 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008390 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008391 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008392 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008393 for (const auto &iter : cmd_overlap_tests_pos) {
8394 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008396 iter.range.size, dummy_values);
8397 m_errorMonitor->VerifyNotFound();
8398 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008399 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008400
8401 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008402}
8403
Karl Schultz6addd812016-02-02 17:17:23 -07008404TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008405 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008406 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008407
8408 ASSERT_NO_FATAL_FAILURE(InitState());
8409 ASSERT_NO_FATAL_FAILURE(InitViewport());
8410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8411
Mike Stroyanb8a61002016-06-20 16:00:28 -06008412 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8413 VkImageTiling tiling;
8414 VkFormatProperties format_properties;
8415 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008417 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008418 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008419 tiling = VK_IMAGE_TILING_OPTIMAL;
8420 } else {
8421 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8422 "skipped.\n");
8423 return;
8424 }
8425
Tobin Ehlis559c6382015-11-05 09:52:49 -07008426 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8427 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008428 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8429 ds_type_count[0].descriptorCount = 10;
8430 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8431 ds_type_count[1].descriptorCount = 2;
8432 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8433 ds_type_count[2].descriptorCount = 2;
8434 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8435 ds_type_count[3].descriptorCount = 5;
8436 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8437 // type
8438 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8439 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8440 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008441
8442 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008443 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8444 ds_pool_ci.pNext = NULL;
8445 ds_pool_ci.maxSets = 5;
8446 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8447 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008448
8449 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008450 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008451 ASSERT_VK_SUCCESS(err);
8452
8453 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8454 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008455 dsl_binding[0].binding = 0;
8456 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8457 dsl_binding[0].descriptorCount = 5;
8458 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8459 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008460
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008461 // Create layout identical to set0 layout but w/ different stageFlags
8462 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008463 dsl_fs_stage_only.binding = 0;
8464 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8465 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8467 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008468 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008469 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008470 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8471 ds_layout_ci.pNext = NULL;
8472 ds_layout_ci.bindingCount = 1;
8473 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008474 static const uint32_t NUM_LAYOUTS = 4;
8475 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008476 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008477 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8478 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008480 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008481 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008483 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008484 dsl_binding[0].binding = 0;
8485 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008486 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008487 dsl_binding[1].binding = 1;
8488 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8489 dsl_binding[1].descriptorCount = 2;
8490 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8491 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008492 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008493 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008495 ASSERT_VK_SUCCESS(err);
8496 dsl_binding[0].binding = 0;
8497 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008498 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008499 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008501 ASSERT_VK_SUCCESS(err);
8502 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008503 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008505 ASSERT_VK_SUCCESS(err);
8506
8507 static const uint32_t NUM_SETS = 4;
8508 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8509 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008510 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008511 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008512 alloc_info.descriptorPool = ds_pool;
8513 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008515 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008516 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008517 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008518 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008520 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008521
8522 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008523 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8524 pipeline_layout_ci.pNext = NULL;
8525 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8526 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008527
8528 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008530 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008531 // Create pipelineLayout with only one setLayout
8532 pipeline_layout_ci.setLayoutCount = 1;
8533 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008534 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008535 ASSERT_VK_SUCCESS(err);
8536 // Create pipelineLayout with 2 descriptor setLayout at index 0
8537 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8538 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008540 ASSERT_VK_SUCCESS(err);
8541 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8542 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8543 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008544 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008545 ASSERT_VK_SUCCESS(err);
8546 // Create pipelineLayout with UB type, but stageFlags for FS only
8547 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8548 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008549 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008550 ASSERT_VK_SUCCESS(err);
8551 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8552 VkDescriptorSetLayout pl_bad_s0[2] = {};
8553 pl_bad_s0[0] = ds_layout_fs_only;
8554 pl_bad_s0[1] = ds_layout[1];
8555 pipeline_layout_ci.setLayoutCount = 2;
8556 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8557 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008558 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008559 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008560
8561 // Create a buffer to update the descriptor with
8562 uint32_t qfi = 0;
8563 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008564 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8565 buffCI.size = 1024;
8566 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8567 buffCI.queueFamilyIndexCount = 1;
8568 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008569
8570 VkBuffer dyub;
8571 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8572 ASSERT_VK_SUCCESS(err);
8573 // Correctly update descriptor to avoid "NOT_UPDATED" error
8574 static const uint32_t NUM_BUFFS = 5;
8575 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008576 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008577 buffInfo[i].buffer = dyub;
8578 buffInfo[i].offset = 0;
8579 buffInfo[i].range = 1024;
8580 }
Karl Schultz6addd812016-02-02 17:17:23 -07008581 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008582 const int32_t tex_width = 32;
8583 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008584 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008585 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8586 image_create_info.pNext = NULL;
8587 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8588 image_create_info.format = tex_format;
8589 image_create_info.extent.width = tex_width;
8590 image_create_info.extent.height = tex_height;
8591 image_create_info.extent.depth = 1;
8592 image_create_info.mipLevels = 1;
8593 image_create_info.arrayLayers = 1;
8594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008595 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008596 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008597 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008598 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008600
Karl Schultz6addd812016-02-02 17:17:23 -07008601 VkMemoryRequirements memReqs;
8602 VkDeviceMemory imageMem;
8603 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008604 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008605 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8606 memAlloc.pNext = NULL;
8607 memAlloc.allocationSize = 0;
8608 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008609 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8610 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008611 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008612 ASSERT_TRUE(pass);
8613 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8614 ASSERT_VK_SUCCESS(err);
8615 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8616 ASSERT_VK_SUCCESS(err);
8617
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008618 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008619 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8620 image_view_create_info.image = image;
8621 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8622 image_view_create_info.format = tex_format;
8623 image_view_create_info.subresourceRange.layerCount = 1;
8624 image_view_create_info.subresourceRange.baseMipLevel = 0;
8625 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008626 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008627
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008628 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008629 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008630 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008631 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008632 imageInfo[0].imageView = view;
8633 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8634 imageInfo[1].imageView = view;
8635 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008636 imageInfo[2].imageView = view;
8637 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8638 imageInfo[3].imageView = view;
8639 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008640
8641 static const uint32_t NUM_SET_UPDATES = 3;
8642 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8643 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8644 descriptor_write[0].dstSet = descriptorSet[0];
8645 descriptor_write[0].dstBinding = 0;
8646 descriptor_write[0].descriptorCount = 5;
8647 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8648 descriptor_write[0].pBufferInfo = buffInfo;
8649 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8650 descriptor_write[1].dstSet = descriptorSet[1];
8651 descriptor_write[1].dstBinding = 0;
8652 descriptor_write[1].descriptorCount = 2;
8653 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8654 descriptor_write[1].pImageInfo = imageInfo;
8655 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8656 descriptor_write[2].dstSet = descriptorSet[1];
8657 descriptor_write[2].dstBinding = 1;
8658 descriptor_write[2].descriptorCount = 2;
8659 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008660 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008661
8662 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008663
Tobin Ehlis88452832015-12-03 09:40:56 -07008664 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 char const *vsSource = "#version 450\n"
8666 "\n"
8667 "out gl_PerVertex {\n"
8668 " vec4 gl_Position;\n"
8669 "};\n"
8670 "void main(){\n"
8671 " gl_Position = vec4(1);\n"
8672 "}\n";
8673 char const *fsSource = "#version 450\n"
8674 "\n"
8675 "layout(location=0) out vec4 x;\n"
8676 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8677 "void main(){\n"
8678 " x = vec4(bar.y);\n"
8679 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008680 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8681 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008682 VkPipelineObj pipe(m_device);
8683 pipe.AddShader(&vs);
8684 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008685 pipe.AddColorAttachment();
8686 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008687
8688 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008689
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008690 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008691 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8692 // of PSO
8693 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8694 // cmd_pipeline.c
8695 // due to the fact that cmd_alloc_dset_data() has not been called in
8696 // cmd_bind_graphics_pipeline()
8697 // TODO : Want to cause various binding incompatibility issues here to test
8698 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008699 // First cause various verify_layout_compatibility() fails
8700 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008701 // verify_set_layout_compatibility fail cases:
8702 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8704 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8705 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008706 m_errorMonitor->VerifyFound();
8707
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008708 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8710 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8711 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008712 m_errorMonitor->VerifyFound();
8713
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008714 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008715 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8716 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8718 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8719 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008720 m_errorMonitor->VerifyFound();
8721
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008722 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8723 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8725 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8726 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008727 m_errorMonitor->VerifyFound();
8728
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008729 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8730 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8732 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8733 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8734 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008735 m_errorMonitor->VerifyFound();
8736
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008737 // Cause INFO messages due to disturbing previously bound Sets
8738 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8740 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008741 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8743 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8744 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008745 m_errorMonitor->VerifyFound();
8746
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8748 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008749 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8751 "any subsequent sets were disturbed ");
8752 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8753 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008754 m_errorMonitor->VerifyFound();
8755
Tobin Ehlis10fad692016-07-07 12:00:36 -06008756 // Now that we're done actively using the pipelineLayout that gfx pipeline
8757 // was created with, we should be able to delete it. Do that now to verify
8758 // that validation obeys pipelineLayout lifetime
8759 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8760
Tobin Ehlis88452832015-12-03 09:40:56 -07008761 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008762 // 1. Error due to not binding required set (we actually use same code as
8763 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8765 &descriptorSet[0], 0, NULL);
8766 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8767 &descriptorSet[1], 0, NULL);
8768 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 -07008769 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008770 m_errorMonitor->VerifyFound();
8771
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008772 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008773 // 2. Error due to bound set not being compatible with PSO's
8774 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008775 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8776 &descriptorSet[0], 0, NULL);
8777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008778 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008779 m_errorMonitor->VerifyFound();
8780
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008781 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008782 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008783 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8784 }
8785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008786 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8787 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008788 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008789 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8790 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008791 vkFreeMemory(m_device->device(), imageMem, NULL);
8792 vkDestroyImage(m_device->device(), image, NULL);
8793 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008794}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008795
Karl Schultz6addd812016-02-02 17:17:23 -07008796TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8799 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008800
8801 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008802 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008803 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008804 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008806 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008807}
8808
Karl Schultz6addd812016-02-02 17:17:23 -07008809TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8810 VkResult err;
8811 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008814
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008815 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008816
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008817 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008818 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008819 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008820 cmd.commandPool = m_commandPool;
8821 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008822 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008823
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008824 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008825 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008826
8827 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008828 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008829 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008830 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008831 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008832 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 -07008833 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008834
8835 // The error should be caught by validation of the BeginCommandBuffer call
8836 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
8837
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008838 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008839 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008840}
8841
Karl Schultz6addd812016-02-02 17:17:23 -07008842TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008843 // Cause error due to Begin while recording CB
8844 // Then cause 2 errors for attempting to reset CB w/o having
8845 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
8846 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008848
8849 ASSERT_NO_FATAL_FAILURE(InitState());
8850
8851 // Calls AllocateCommandBuffers
8852 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
8853
Karl Schultz6addd812016-02-02 17:17:23 -07008854 // Force the failure by setting the Renderpass and Framebuffer fields with
8855 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008856 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008857 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008858 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8859 cmd_buf_info.pNext = NULL;
8860 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008861 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008862
8863 // Begin CB to transition to recording state
8864 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
8865 // Can't re-begin. This should trigger error
8866 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008867 m_errorMonitor->VerifyFound();
8868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008870 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
8871 // Reset attempt will trigger error due to incorrect CommandPool state
8872 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008873 m_errorMonitor->VerifyFound();
8874
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008876 // Transition CB to RECORDED state
8877 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
8878 // Now attempting to Begin will implicitly reset, which triggers error
8879 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008880 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07008881}
8882
Karl Schultz6addd812016-02-02 17:17:23 -07008883TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008884 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07008885 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008886
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008888
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008889 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008891
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008892 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008893 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8894 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008895
8896 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008897 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8898 ds_pool_ci.pNext = NULL;
8899 ds_pool_ci.maxSets = 1;
8900 ds_pool_ci.poolSizeCount = 1;
8901 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008902
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008903 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008905 ASSERT_VK_SUCCESS(err);
8906
Tony Barboureb254902015-07-15 12:50:33 -06008907 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008908 dsl_binding.binding = 0;
8909 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8910 dsl_binding.descriptorCount = 1;
8911 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8912 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008913
Tony Barboureb254902015-07-15 12:50:33 -06008914 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008915 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8916 ds_layout_ci.pNext = NULL;
8917 ds_layout_ci.bindingCount = 1;
8918 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008919
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008920 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008922 ASSERT_VK_SUCCESS(err);
8923
8924 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008925 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008926 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008927 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008928 alloc_info.descriptorPool = ds_pool;
8929 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008930 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008931 ASSERT_VK_SUCCESS(err);
8932
Tony Barboureb254902015-07-15 12:50:33 -06008933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8935 pipeline_layout_ci.setLayoutCount = 1;
8936 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008937
8938 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008940 ASSERT_VK_SUCCESS(err);
8941
Tobin Ehlise68360f2015-10-01 11:15:13 -06008942 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008943 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06008944
8945 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008946 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8947 vp_state_ci.scissorCount = 1;
8948 vp_state_ci.pScissors = &sc;
8949 vp_state_ci.viewportCount = 1;
8950 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008951
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008952 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8953 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8954 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8955 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8956 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8957 rs_state_ci.depthClampEnable = VK_FALSE;
8958 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8959 rs_state_ci.depthBiasEnable = VK_FALSE;
8960
Tony Barboureb254902015-07-15 12:50:33 -06008961 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008962 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8963 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008964 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008965 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8966 gp_ci.layout = pipeline_layout;
8967 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06008968
8969 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008970 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8971 pc_ci.initialDataSize = 0;
8972 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008973
8974 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06008975 VkPipelineCache pipelineCache;
8976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008977 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06008978 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008979 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06008980
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008981 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008982
Chia-I Wuf7458c52015-10-26 21:10:41 +08008983 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8984 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8985 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8986 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008987}
Tobin Ehlis912df022015-09-17 08:46:18 -06008988/*// TODO : This test should be good, but needs Tess support in compiler to run
8989TEST_F(VkLayerTest, InvalidPatchControlPoints)
8990{
8991 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06008992 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008993
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008995 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
8996primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008997
Tobin Ehlis912df022015-09-17 08:46:18 -06008998 ASSERT_NO_FATAL_FAILURE(InitState());
8999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06009000
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009001 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06009002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009003 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009004
9005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9007 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009008 ds_pool_ci.poolSizeCount = 1;
9009 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06009010
9011 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009012 err = vkCreateDescriptorPool(m_device->device(),
9013VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06009014 ASSERT_VK_SUCCESS(err);
9015
9016 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009017 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06009018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009019 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9021 dsl_binding.pImmutableSamplers = NULL;
9022
9023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009024 ds_layout_ci.sType =
9025VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009026 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009027 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009028 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06009029
9030 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9032&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009033 ASSERT_VK_SUCCESS(err);
9034
9035 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009036 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
9037VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06009038 ASSERT_VK_SUCCESS(err);
9039
9040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009041 pipeline_layout_ci.sType =
9042VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009043 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009044 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009045 pipeline_layout_ci.pSetLayouts = &ds_layout;
9046
9047 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009048 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9049&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009050 ASSERT_VK_SUCCESS(err);
9051
9052 VkPipelineShaderStageCreateInfo shaderStages[3];
9053 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
9054
Karl Schultz6addd812016-02-02 17:17:23 -07009055 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
9056this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009057 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07009058 VkShaderObj
9059tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
9060this);
9061 VkShaderObj
9062te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
9063this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009064
Karl Schultz6addd812016-02-02 17:17:23 -07009065 shaderStages[0].sType =
9066VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009067 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009068 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009069 shaderStages[1].sType =
9070VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009071 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009072 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009073 shaderStages[2].sType =
9074VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009075 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009076 shaderStages[2].shader = te.handle();
9077
9078 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009079 iaCI.sType =
9080VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009081 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009082
9083 VkPipelineTessellationStateCreateInfo tsCI = {};
9084 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9085 tsCI.patchControlPoints = 0; // This will cause an error
9086
9087 VkGraphicsPipelineCreateInfo gp_ci = {};
9088 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9089 gp_ci.pNext = NULL;
9090 gp_ci.stageCount = 3;
9091 gp_ci.pStages = shaderStages;
9092 gp_ci.pVertexInputState = NULL;
9093 gp_ci.pInputAssemblyState = &iaCI;
9094 gp_ci.pTessellationState = &tsCI;
9095 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009096 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009097 gp_ci.pMultisampleState = NULL;
9098 gp_ci.pDepthStencilState = NULL;
9099 gp_ci.pColorBlendState = NULL;
9100 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9101 gp_ci.layout = pipeline_layout;
9102 gp_ci.renderPass = renderPass();
9103
9104 VkPipelineCacheCreateInfo pc_ci = {};
9105 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9106 pc_ci.pNext = NULL;
9107 pc_ci.initialSize = 0;
9108 pc_ci.initialData = 0;
9109 pc_ci.maxSize = 0;
9110
9111 VkPipeline pipeline;
9112 VkPipelineCache pipelineCache;
9113
Karl Schultz6addd812016-02-02 17:17:23 -07009114 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9115&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009116 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9118&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009119
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009120 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009121
Chia-I Wuf7458c52015-10-26 21:10:41 +08009122 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9123 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9124 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9125 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009126}
9127*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009128// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009129TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009130 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9133 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009134
Tobin Ehlise68360f2015-10-01 11:15:13 -06009135 ASSERT_NO_FATAL_FAILURE(InitState());
9136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009137
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009138 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9140 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009141
9142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9144 ds_pool_ci.maxSets = 1;
9145 ds_pool_ci.poolSizeCount = 1;
9146 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009147
9148 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009150 ASSERT_VK_SUCCESS(err);
9151
9152 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009153 dsl_binding.binding = 0;
9154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9155 dsl_binding.descriptorCount = 1;
9156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009157
9158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9160 ds_layout_ci.bindingCount = 1;
9161 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009162
9163 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009164 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009165 ASSERT_VK_SUCCESS(err);
9166
9167 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009168 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009170 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009171 alloc_info.descriptorPool = ds_pool;
9172 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009174 ASSERT_VK_SUCCESS(err);
9175
9176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9178 pipeline_layout_ci.setLayoutCount = 1;
9179 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009180
9181 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009183 ASSERT_VK_SUCCESS(err);
9184
9185 VkViewport vp = {}; // Just need dummy vp to point to
9186
9187 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009188 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9189 vp_state_ci.scissorCount = 0;
9190 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9191 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009192
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009193 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9194 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9195 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9196 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9197 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9198 rs_state_ci.depthClampEnable = VK_FALSE;
9199 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9200 rs_state_ci.depthBiasEnable = VK_FALSE;
9201
Cody Northropeb3a6c12015-10-05 14:44:45 -06009202 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009203 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009205 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9206 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9207 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009208 shaderStages[0] = vs.GetStageCreateInfo();
9209 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009210
9211 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009212 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9213 gp_ci.stageCount = 2;
9214 gp_ci.pStages = shaderStages;
9215 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009216 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009217 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9218 gp_ci.layout = pipeline_layout;
9219 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009220
9221 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009222 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009223
9224 VkPipeline pipeline;
9225 VkPipelineCache pipelineCache;
9226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009228 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009229 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009231 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009232
Chia-I Wuf7458c52015-10-26 21:10:41 +08009233 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9234 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9235 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9236 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009237}
Karl Schultz6addd812016-02-02 17:17:23 -07009238// Don't set viewport state in PSO. This is an error b/c we always need this
9239// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009240// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009241TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009242 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009243 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009244
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009246
Tobin Ehlise68360f2015-10-01 11:15:13 -06009247 ASSERT_NO_FATAL_FAILURE(InitState());
9248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009249
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009250 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009251 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9252 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009253
9254 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009255 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9256 ds_pool_ci.maxSets = 1;
9257 ds_pool_ci.poolSizeCount = 1;
9258 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009259
9260 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009261 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009262 ASSERT_VK_SUCCESS(err);
9263
9264 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009265 dsl_binding.binding = 0;
9266 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9267 dsl_binding.descriptorCount = 1;
9268 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009269
9270 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009271 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9272 ds_layout_ci.bindingCount = 1;
9273 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009274
9275 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009276 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009277 ASSERT_VK_SUCCESS(err);
9278
9279 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009280 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009281 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009282 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009283 alloc_info.descriptorPool = ds_pool;
9284 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009285 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009286 ASSERT_VK_SUCCESS(err);
9287
9288 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009289 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9290 pipeline_layout_ci.setLayoutCount = 1;
9291 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009292
9293 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009294 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009295 ASSERT_VK_SUCCESS(err);
9296
9297 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9298 // Set scissor as dynamic to avoid second error
9299 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009300 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9301 dyn_state_ci.dynamicStateCount = 1;
9302 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009303
Cody Northropeb3a6c12015-10-05 14:44:45 -06009304 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009305 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009306
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009307 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9308 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9309 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009310 shaderStages[0] = vs.GetStageCreateInfo();
9311 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009312
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009313 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9314 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9315 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9316 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9317 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9318 rs_state_ci.depthClampEnable = VK_FALSE;
9319 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9320 rs_state_ci.depthBiasEnable = VK_FALSE;
9321
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009323 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9324 gp_ci.stageCount = 2;
9325 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009326 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009327 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9328 // should cause validation error
9329 gp_ci.pDynamicState = &dyn_state_ci;
9330 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9331 gp_ci.layout = pipeline_layout;
9332 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009333
9334 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009335 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009336
9337 VkPipeline pipeline;
9338 VkPipelineCache pipelineCache;
9339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009340 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009341 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009342 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009343
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009344 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009345
Chia-I Wuf7458c52015-10-26 21:10:41 +08009346 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9347 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9348 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9349 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009350}
9351// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009352// Then run second test where dynamic scissor count doesn't match PSO scissor
9353// count
9354TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9355 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9358 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009359
Tobin Ehlise68360f2015-10-01 11:15:13 -06009360 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009361
9362 if (!m_device->phy().features().multiViewport) {
9363 printf("Device does not support multiple viewports/scissors; skipped.\n");
9364 return;
9365 }
9366
Tobin Ehlise68360f2015-10-01 11:15:13 -06009367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009368
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009369 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009370 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9371 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009372
9373 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009374 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9375 ds_pool_ci.maxSets = 1;
9376 ds_pool_ci.poolSizeCount = 1;
9377 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009378
9379 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009380 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009381 ASSERT_VK_SUCCESS(err);
9382
9383 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009384 dsl_binding.binding = 0;
9385 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9386 dsl_binding.descriptorCount = 1;
9387 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009388
9389 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009390 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9391 ds_layout_ci.bindingCount = 1;
9392 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009393
9394 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009395 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009396 ASSERT_VK_SUCCESS(err);
9397
9398 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009399 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009400 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009401 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009402 alloc_info.descriptorPool = ds_pool;
9403 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009404 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009405 ASSERT_VK_SUCCESS(err);
9406
9407 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009408 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9409 pipeline_layout_ci.setLayoutCount = 1;
9410 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009411
9412 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009413 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009414 ASSERT_VK_SUCCESS(err);
9415
9416 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009417 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9418 vp_state_ci.viewportCount = 1;
9419 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9420 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009421 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009422
9423 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9424 // Set scissor as dynamic to avoid that error
9425 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009426 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9427 dyn_state_ci.dynamicStateCount = 1;
9428 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009429
Cody Northropeb3a6c12015-10-05 14:44:45 -06009430 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009431 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009432
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009433 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9434 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9435 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009436 shaderStages[0] = vs.GetStageCreateInfo();
9437 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009438
Cody Northropf6622dc2015-10-06 10:33:21 -06009439 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9440 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9441 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009442 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009443 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009444 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009445 vi_ci.pVertexAttributeDescriptions = nullptr;
9446
9447 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9448 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9449 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9450
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009451 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009452 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009453 rs_ci.pNext = nullptr;
9454
Mark Youngc89c6312016-03-31 16:03:20 -06009455 VkPipelineColorBlendAttachmentState att = {};
9456 att.blendEnable = VK_FALSE;
9457 att.colorWriteMask = 0xf;
9458
Cody Northropf6622dc2015-10-06 10:33:21 -06009459 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9460 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9461 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009462 cb_ci.attachmentCount = 1;
9463 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009464
Tobin Ehlise68360f2015-10-01 11:15:13 -06009465 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009466 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9467 gp_ci.stageCount = 2;
9468 gp_ci.pStages = shaderStages;
9469 gp_ci.pVertexInputState = &vi_ci;
9470 gp_ci.pInputAssemblyState = &ia_ci;
9471 gp_ci.pViewportState = &vp_state_ci;
9472 gp_ci.pRasterizationState = &rs_ci;
9473 gp_ci.pColorBlendState = &cb_ci;
9474 gp_ci.pDynamicState = &dyn_state_ci;
9475 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9476 gp_ci.layout = pipeline_layout;
9477 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009478
9479 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009480 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009481
9482 VkPipeline pipeline;
9483 VkPipelineCache pipelineCache;
9484
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009485 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009486 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009487 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009488
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009489 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009490
Tobin Ehlisd332f282015-10-02 11:00:56 -06009491 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009492 // First need to successfully create the PSO from above by setting
9493 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009495
9496 VkViewport vp = {}; // Just need dummy vp to point to
9497 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009498 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009499 ASSERT_VK_SUCCESS(err);
9500 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009501 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009502 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009503 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009504 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009505 Draw(1, 0, 0, 0);
9506
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009507 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009508
9509 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9510 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9511 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9512 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009513 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009514}
9515// Create PSO w/o non-zero scissorCount but no scissor data
9516// Then run second test where dynamic viewportCount doesn't match PSO
9517// viewportCount
9518TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9519 VkResult err;
9520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009521 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 -07009522
9523 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009524
9525 if (!m_device->phy().features().multiViewport) {
9526 printf("Device does not support multiple viewports/scissors; skipped.\n");
9527 return;
9528 }
9529
Karl Schultz6addd812016-02-02 17:17:23 -07009530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9531
9532 VkDescriptorPoolSize ds_type_count = {};
9533 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9534 ds_type_count.descriptorCount = 1;
9535
9536 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9537 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9538 ds_pool_ci.maxSets = 1;
9539 ds_pool_ci.poolSizeCount = 1;
9540 ds_pool_ci.pPoolSizes = &ds_type_count;
9541
9542 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009543 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009544 ASSERT_VK_SUCCESS(err);
9545
9546 VkDescriptorSetLayoutBinding dsl_binding = {};
9547 dsl_binding.binding = 0;
9548 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9549 dsl_binding.descriptorCount = 1;
9550 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9551
9552 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9553 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9554 ds_layout_ci.bindingCount = 1;
9555 ds_layout_ci.pBindings = &dsl_binding;
9556
9557 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009559 ASSERT_VK_SUCCESS(err);
9560
9561 VkDescriptorSet descriptorSet;
9562 VkDescriptorSetAllocateInfo alloc_info = {};
9563 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9564 alloc_info.descriptorSetCount = 1;
9565 alloc_info.descriptorPool = ds_pool;
9566 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009567 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009568 ASSERT_VK_SUCCESS(err);
9569
9570 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9571 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9572 pipeline_layout_ci.setLayoutCount = 1;
9573 pipeline_layout_ci.pSetLayouts = &ds_layout;
9574
9575 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009576 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009577 ASSERT_VK_SUCCESS(err);
9578
9579 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9580 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9581 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009583 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009584 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009585
9586 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9587 // Set scissor as dynamic to avoid that error
9588 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9589 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9590 dyn_state_ci.dynamicStateCount = 1;
9591 dyn_state_ci.pDynamicStates = &vp_state;
9592
9593 VkPipelineShaderStageCreateInfo shaderStages[2];
9594 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9597 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9598 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009599 shaderStages[0] = vs.GetStageCreateInfo();
9600 shaderStages[1] = fs.GetStageCreateInfo();
9601
9602 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9603 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9604 vi_ci.pNext = nullptr;
9605 vi_ci.vertexBindingDescriptionCount = 0;
9606 vi_ci.pVertexBindingDescriptions = nullptr;
9607 vi_ci.vertexAttributeDescriptionCount = 0;
9608 vi_ci.pVertexAttributeDescriptions = nullptr;
9609
9610 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9611 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9612 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9613
9614 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9615 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9616 rs_ci.pNext = nullptr;
9617
Mark Youngc89c6312016-03-31 16:03:20 -06009618 VkPipelineColorBlendAttachmentState att = {};
9619 att.blendEnable = VK_FALSE;
9620 att.colorWriteMask = 0xf;
9621
Karl Schultz6addd812016-02-02 17:17:23 -07009622 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9623 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9624 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009625 cb_ci.attachmentCount = 1;
9626 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009627
9628 VkGraphicsPipelineCreateInfo gp_ci = {};
9629 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9630 gp_ci.stageCount = 2;
9631 gp_ci.pStages = shaderStages;
9632 gp_ci.pVertexInputState = &vi_ci;
9633 gp_ci.pInputAssemblyState = &ia_ci;
9634 gp_ci.pViewportState = &vp_state_ci;
9635 gp_ci.pRasterizationState = &rs_ci;
9636 gp_ci.pColorBlendState = &cb_ci;
9637 gp_ci.pDynamicState = &dyn_state_ci;
9638 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9639 gp_ci.layout = pipeline_layout;
9640 gp_ci.renderPass = renderPass();
9641
9642 VkPipelineCacheCreateInfo pc_ci = {};
9643 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9644
9645 VkPipeline pipeline;
9646 VkPipelineCache pipelineCache;
9647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009648 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009649 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009651
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009652 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009653
9654 // Now hit second fail case where we set scissor w/ different count than PSO
9655 // First need to successfully create the PSO from above by setting
9656 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009658
Tobin Ehlisd332f282015-10-02 11:00:56 -06009659 VkRect2D sc = {}; // Just need dummy vp to point to
9660 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009661 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009662 ASSERT_VK_SUCCESS(err);
9663 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009664 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009665 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009666 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009667 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009668 Draw(1, 0, 0, 0);
9669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009670 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009671
Chia-I Wuf7458c52015-10-26 21:10:41 +08009672 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009676 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009677}
9678
Mark Young7394fdd2016-03-31 14:56:43 -06009679TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9680 VkResult err;
9681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009683
9684 ASSERT_NO_FATAL_FAILURE(InitState());
9685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9686
9687 VkDescriptorPoolSize ds_type_count = {};
9688 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9689 ds_type_count.descriptorCount = 1;
9690
9691 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9692 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9693 ds_pool_ci.maxSets = 1;
9694 ds_pool_ci.poolSizeCount = 1;
9695 ds_pool_ci.pPoolSizes = &ds_type_count;
9696
9697 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009698 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009699 ASSERT_VK_SUCCESS(err);
9700
9701 VkDescriptorSetLayoutBinding dsl_binding = {};
9702 dsl_binding.binding = 0;
9703 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9704 dsl_binding.descriptorCount = 1;
9705 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9706
9707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9709 ds_layout_ci.bindingCount = 1;
9710 ds_layout_ci.pBindings = &dsl_binding;
9711
9712 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009714 ASSERT_VK_SUCCESS(err);
9715
9716 VkDescriptorSet descriptorSet;
9717 VkDescriptorSetAllocateInfo alloc_info = {};
9718 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9719 alloc_info.descriptorSetCount = 1;
9720 alloc_info.descriptorPool = ds_pool;
9721 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009722 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009723 ASSERT_VK_SUCCESS(err);
9724
9725 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9726 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9727 pipeline_layout_ci.setLayoutCount = 1;
9728 pipeline_layout_ci.pSetLayouts = &ds_layout;
9729
9730 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009731 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009732 ASSERT_VK_SUCCESS(err);
9733
9734 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9735 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9736 vp_state_ci.scissorCount = 1;
9737 vp_state_ci.pScissors = NULL;
9738 vp_state_ci.viewportCount = 1;
9739 vp_state_ci.pViewports = NULL;
9740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009742 // Set scissor as dynamic to avoid that error
9743 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9744 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9745 dyn_state_ci.dynamicStateCount = 2;
9746 dyn_state_ci.pDynamicStates = dynamic_states;
9747
9748 VkPipelineShaderStageCreateInfo shaderStages[2];
9749 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009751 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9752 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009753 this); // TODO - We shouldn't need a fragment shader
9754 // but add it to be able to run on more devices
9755 shaderStages[0] = vs.GetStageCreateInfo();
9756 shaderStages[1] = fs.GetStageCreateInfo();
9757
9758 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9759 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9760 vi_ci.pNext = nullptr;
9761 vi_ci.vertexBindingDescriptionCount = 0;
9762 vi_ci.pVertexBindingDescriptions = nullptr;
9763 vi_ci.vertexAttributeDescriptionCount = 0;
9764 vi_ci.pVertexAttributeDescriptions = nullptr;
9765
9766 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9767 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9768 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9769
9770 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9771 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9772 rs_ci.pNext = nullptr;
9773
Mark Young47107952016-05-02 15:59:55 -06009774 // Check too low (line width of -1.0f).
9775 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009776
9777 VkPipelineColorBlendAttachmentState att = {};
9778 att.blendEnable = VK_FALSE;
9779 att.colorWriteMask = 0xf;
9780
9781 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9782 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9783 cb_ci.pNext = nullptr;
9784 cb_ci.attachmentCount = 1;
9785 cb_ci.pAttachments = &att;
9786
9787 VkGraphicsPipelineCreateInfo gp_ci = {};
9788 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9789 gp_ci.stageCount = 2;
9790 gp_ci.pStages = shaderStages;
9791 gp_ci.pVertexInputState = &vi_ci;
9792 gp_ci.pInputAssemblyState = &ia_ci;
9793 gp_ci.pViewportState = &vp_state_ci;
9794 gp_ci.pRasterizationState = &rs_ci;
9795 gp_ci.pColorBlendState = &cb_ci;
9796 gp_ci.pDynamicState = &dyn_state_ci;
9797 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9798 gp_ci.layout = pipeline_layout;
9799 gp_ci.renderPass = renderPass();
9800
9801 VkPipelineCacheCreateInfo pc_ci = {};
9802 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9803
9804 VkPipeline pipeline;
9805 VkPipelineCache pipelineCache;
9806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009807 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009808 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009809 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009810
9811 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009812 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009815
9816 // Check too high (line width of 65536.0f).
9817 rs_ci.lineWidth = 65536.0f;
9818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009820 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009821 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009822
9823 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009824 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009827
9828 dyn_state_ci.dynamicStateCount = 3;
9829
9830 rs_ci.lineWidth = 1.0f;
9831
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009832 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009833 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009835 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009836 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009837
9838 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06009839 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06009840 m_errorMonitor->VerifyFound();
9841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009843
9844 // Check too high with dynamic setting.
9845 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
9846 m_errorMonitor->VerifyFound();
9847 EndCommandBuffer();
9848
9849 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9850 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9851 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9852 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009853 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009854}
9855
Karl Schultz6addd812016-02-02 17:17:23 -07009856TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009857 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9859 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009860
9861 ASSERT_NO_FATAL_FAILURE(InitState());
9862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009863
Tony Barbourfe3351b2015-07-28 10:17:20 -06009864 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009865 // Don't care about RenderPass handle b/c error should be flagged before
9866 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009867 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009868
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009869 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009870}
9871
Karl Schultz6addd812016-02-02 17:17:23 -07009872TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009873 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9875 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009876
9877 ASSERT_NO_FATAL_FAILURE(InitState());
9878 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009879
Tony Barbourfe3351b2015-07-28 10:17:20 -06009880 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009881 // Just create a dummy Renderpass that's non-NULL so we can get to the
9882 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009883 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009884
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009885 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009886}
9887
Chris Forbes2eeabe32016-06-21 20:52:34 +12009888TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
9889 m_errorMonitor->ExpectSuccess();
9890
9891 ASSERT_NO_FATAL_FAILURE(InitState());
9892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +12009895 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
9896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009897 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009898 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9899 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +12009901 m_errorMonitor->VerifyNotFound();
9902 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9903 m_errorMonitor->VerifyNotFound();
9904
9905 m_commandBuffer->EndCommandBuffer();
9906 m_errorMonitor->VerifyNotFound();
9907}
9908
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009909TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
9910 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
9911 "the number of renderPass attachments that use loadOp"
9912 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
9913
9914 ASSERT_NO_FATAL_FAILURE(InitState());
9915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9916
9917 // Create a renderPass with a single attachment that uses loadOp CLEAR
9918 VkAttachmentReference attach = {};
9919 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9920 VkSubpassDescription subpass = {};
9921 subpass.inputAttachmentCount = 1;
9922 subpass.pInputAttachments = &attach;
9923 VkRenderPassCreateInfo rpci = {};
9924 rpci.subpassCount = 1;
9925 rpci.pSubpasses = &subpass;
9926 rpci.attachmentCount = 1;
9927 VkAttachmentDescription attach_desc = {};
9928 attach_desc.format = VK_FORMAT_UNDEFINED;
9929 // Set loadOp to CLEAR
9930 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9931 rpci.pAttachments = &attach_desc;
9932 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9933 VkRenderPass rp;
9934 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9935
9936 VkCommandBufferInheritanceInfo hinfo = {};
9937 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9938 hinfo.renderPass = VK_NULL_HANDLE;
9939 hinfo.subpass = 0;
9940 hinfo.framebuffer = VK_NULL_HANDLE;
9941 hinfo.occlusionQueryEnable = VK_FALSE;
9942 hinfo.queryFlags = 0;
9943 hinfo.pipelineStatistics = 0;
9944 VkCommandBufferBeginInfo info = {};
9945 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9946 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9947 info.pInheritanceInfo = &hinfo;
9948
9949 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9950 VkRenderPassBeginInfo rp_begin = {};
9951 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9952 rp_begin.pNext = NULL;
9953 rp_begin.renderPass = renderPass();
9954 rp_begin.framebuffer = framebuffer();
9955 rp_begin.clearValueCount = 0; // Should be 1
9956
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
9958 "there must be at least 1 entries in "
9959 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009961 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009962
9963 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009964
9965 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009966}
9967
Cody Northrop3bb4d962016-05-09 16:15:57 -06009968TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
9969
9970 TEST_DESCRIPTION("End a command buffer with an active render pass");
9971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9973 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009974
9975 ASSERT_NO_FATAL_FAILURE(InitState());
9976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9977
9978 // The framework's BeginCommandBuffer calls CreateRenderPass
9979 BeginCommandBuffer();
9980
9981 // Call directly into vkEndCommandBuffer instead of the
9982 // the framework's EndCommandBuffer, which inserts a
9983 // vkEndRenderPass
9984 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
9985
9986 m_errorMonitor->VerifyFound();
9987
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9989 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009990}
9991
Karl Schultz6addd812016-02-02 17:17:23 -07009992TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009993 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9995 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009996
9997 ASSERT_NO_FATAL_FAILURE(InitState());
9998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009999
10000 // Renderpass is started here
10001 BeginCommandBuffer();
10002
10003 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010004 vk_testing::Buffer dstBuffer;
10005 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010006
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010007 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010008
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010009 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010010}
10011
Karl Schultz6addd812016-02-02 17:17:23 -070010012TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010013 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10015 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010016
10017 ASSERT_NO_FATAL_FAILURE(InitState());
10018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010019
10020 // Renderpass is started here
10021 BeginCommandBuffer();
10022
10023 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010024 vk_testing::Buffer dstBuffer;
10025 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010026
Karl Schultz6addd812016-02-02 17:17:23 -070010027 VkDeviceSize dstOffset = 0;
10028 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -060010029 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010031 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010032
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010033 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010034}
10035
Karl Schultz6addd812016-02-02 17:17:23 -070010036TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010037 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10039 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010040
10041 ASSERT_NO_FATAL_FAILURE(InitState());
10042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010043
10044 // Renderpass is started here
10045 BeginCommandBuffer();
10046
Michael Lentine0a369f62016-02-03 16:51:46 -060010047 VkClearColorValue clear_color;
10048 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -070010049 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10050 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10051 const int32_t tex_width = 32;
10052 const int32_t tex_height = 32;
10053 VkImageCreateInfo image_create_info = {};
10054 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10055 image_create_info.pNext = NULL;
10056 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10057 image_create_info.format = tex_format;
10058 image_create_info.extent.width = tex_width;
10059 image_create_info.extent.height = tex_height;
10060 image_create_info.extent.depth = 1;
10061 image_create_info.mipLevels = 1;
10062 image_create_info.arrayLayers = 1;
10063 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10064 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10065 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010066
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010067 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010070 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010072 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010073
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010074 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010075}
10076
Karl Schultz6addd812016-02-02 17:17:23 -070010077TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010078 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10080 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010081
10082 ASSERT_NO_FATAL_FAILURE(InitState());
10083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010084
10085 // Renderpass is started here
10086 BeginCommandBuffer();
10087
10088 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010089 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010090 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10091 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10092 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10093 image_create_info.extent.width = 64;
10094 image_create_info.extent.height = 64;
10095 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10096 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010097
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010098 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010099 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010101 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010103 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10104 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010105
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010106 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010107}
10108
Karl Schultz6addd812016-02-02 17:17:23 -070010109TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010110 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010111 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10114 "must be issued inside an active "
10115 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010116
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010117 ASSERT_NO_FATAL_FAILURE(InitState());
10118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010119
10120 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010121 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010122 ASSERT_VK_SUCCESS(err);
10123
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010124 VkClearAttachment color_attachment;
10125 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10126 color_attachment.clearValue.color.float32[0] = 0;
10127 color_attachment.clearValue.color.float32[1] = 0;
10128 color_attachment.clearValue.color.float32[2] = 0;
10129 color_attachment.clearValue.color.float32[3] = 0;
10130 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010131 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010133
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010134 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010135}
10136
Chris Forbes3b97e932016-09-07 11:29:24 +120010137TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10138 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10139 "called too many times in a renderpass instance");
10140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10142 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010143
10144 ASSERT_NO_FATAL_FAILURE(InitState());
10145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10146
10147 BeginCommandBuffer();
10148
10149 // error here.
10150 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10151 m_errorMonitor->VerifyFound();
10152
10153 EndCommandBuffer();
10154}
10155
Chris Forbes6d624702016-09-07 13:57:05 +120010156TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10157 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10158 "called before the final subpass has been reached");
10159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10161 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010162
10163 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010164 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10165 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010168
10169 VkRenderPass rp;
10170 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10171 ASSERT_VK_SUCCESS(err);
10172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010173 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010174
10175 VkFramebuffer fb;
10176 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10177 ASSERT_VK_SUCCESS(err);
10178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 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 +120010182
10183 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10184
10185 // Error here.
10186 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10187 m_errorMonitor->VerifyFound();
10188
10189 // Clean up.
10190 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10191 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10192}
10193
Karl Schultz9e66a292016-04-21 15:57:51 -060010194TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10195 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10197 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010198
10199 ASSERT_NO_FATAL_FAILURE(InitState());
10200 BeginCommandBuffer();
10201
10202 VkBufferMemoryBarrier buf_barrier = {};
10203 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10204 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10205 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10206 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10207 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10208 buf_barrier.buffer = VK_NULL_HANDLE;
10209 buf_barrier.offset = 0;
10210 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10212 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010213
10214 m_errorMonitor->VerifyFound();
10215}
10216
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010217TEST_F(VkLayerTest, InvalidBarriers) {
10218 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010221
10222 ASSERT_NO_FATAL_FAILURE(InitState());
10223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10224
10225 VkMemoryBarrier mem_barrier = {};
10226 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10227 mem_barrier.pNext = NULL;
10228 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10229 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10230 BeginCommandBuffer();
10231 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010232 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010233 &mem_barrier, 0, nullptr, 0, nullptr);
10234 m_errorMonitor->VerifyFound();
10235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010237 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010238 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 -060010239 ASSERT_TRUE(image.initialized());
10240 VkImageMemoryBarrier img_barrier = {};
10241 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10242 img_barrier.pNext = NULL;
10243 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10244 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10245 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10246 // New layout can't be UNDEFINED
10247 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10248 img_barrier.image = image.handle();
10249 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10250 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10251 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10252 img_barrier.subresourceRange.baseArrayLayer = 0;
10253 img_barrier.subresourceRange.baseMipLevel = 0;
10254 img_barrier.subresourceRange.layerCount = 1;
10255 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010256 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10257 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010258 m_errorMonitor->VerifyFound();
10259 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10262 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010263 // baseArrayLayer + layerCount must be <= image's arrayLayers
10264 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10266 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010267 m_errorMonitor->VerifyFound();
10268 img_barrier.subresourceRange.baseArrayLayer = 0;
10269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010271 // baseMipLevel + levelCount must be <= image's mipLevels
10272 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010273 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10274 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010275 m_errorMonitor->VerifyFound();
10276 img_barrier.subresourceRange.baseMipLevel = 0;
10277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010278 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 -060010279 vk_testing::Buffer buffer;
10280 buffer.init(*m_device, 256);
10281 VkBufferMemoryBarrier buf_barrier = {};
10282 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10283 buf_barrier.pNext = NULL;
10284 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10285 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10286 buf_barrier.buffer = buffer.handle();
10287 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10288 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10289 buf_barrier.offset = 0;
10290 buf_barrier.size = VK_WHOLE_SIZE;
10291 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010292 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10293 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010294 m_errorMonitor->VerifyFound();
10295 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010298 buf_barrier.offset = 257;
10299 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010300 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10301 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010302 m_errorMonitor->VerifyFound();
10303 buf_barrier.offset = 0;
10304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010306 buf_barrier.size = 257;
10307 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010308 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10309 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010310 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010311
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010312 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10314 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10315 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010316 VkDepthStencilObj ds_image(m_device);
10317 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10318 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010319 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10320 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010321 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010322 // Use of COLOR aspect on DS image is error
10323 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010324 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10325 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010326 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010327 // Now test depth-only
10328 VkFormatProperties format_props;
10329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10331 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10333 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010334 VkDepthStencilObj d_image(m_device);
10335 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10336 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010338 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010339 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010340 // Use of COLOR aspect on depth image is error
10341 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010342 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10343 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010344 m_errorMonitor->VerifyFound();
10345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10347 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010348 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10350 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010351 VkDepthStencilObj s_image(m_device);
10352 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10353 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010354 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010355 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010356 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010357 // Use of COLOR aspect on depth image is error
10358 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10360 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010361 m_errorMonitor->VerifyFound();
10362 }
10363 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10365 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010366 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 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 -060010368 ASSERT_TRUE(c_image.initialized());
10369 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10370 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10371 img_barrier.image = c_image.handle();
10372 // Set aspect to depth (non-color)
10373 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010374 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10375 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010376 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010377}
10378
Karl Schultz6addd812016-02-02 17:17:23 -070010379TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010380 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010381 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010384
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010385 ASSERT_NO_FATAL_FAILURE(InitState());
10386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010387 uint32_t qfi = 0;
10388 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010389 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10390 buffCI.size = 1024;
10391 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10392 buffCI.queueFamilyIndexCount = 1;
10393 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010394
10395 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010396 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010397 ASSERT_VK_SUCCESS(err);
10398
10399 BeginCommandBuffer();
10400 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010401 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10402 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010403 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010405
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010406 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010407
Chia-I Wuf7458c52015-10-26 21:10:41 +080010408 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010409}
10410
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010411TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10412 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10414 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10415 "of the indices specified when the device was created, via the "
10416 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010417
10418 ASSERT_NO_FATAL_FAILURE(InitState());
10419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10420 VkBufferCreateInfo buffCI = {};
10421 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10422 buffCI.size = 1024;
10423 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10424 buffCI.queueFamilyIndexCount = 1;
10425 // Introduce failure by specifying invalid queue_family_index
10426 uint32_t qfi = 777;
10427 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010428 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010429
10430 VkBuffer ib;
10431 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10432
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010433 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010434 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010435}
10436
Karl Schultz6addd812016-02-02 17:17:23 -070010437TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010438 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10439 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010442
10443 ASSERT_NO_FATAL_FAILURE(InitState());
10444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010445
10446 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010447
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010448 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10449 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010450
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010451 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010452}
10453
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010454TEST_F(VkLayerTest, DSUsageBitsErrors) {
10455 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10456 "that do not have correct usage bits sets.");
10457 VkResult err;
10458
10459 ASSERT_NO_FATAL_FAILURE(InitState());
10460 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10461 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10462 ds_type_count[i].type = VkDescriptorType(i);
10463 ds_type_count[i].descriptorCount = 1;
10464 }
10465 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10466 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10467 ds_pool_ci.pNext = NULL;
10468 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10469 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10470 ds_pool_ci.pPoolSizes = ds_type_count;
10471
10472 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010473 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010474 ASSERT_VK_SUCCESS(err);
10475
10476 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010477 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010478 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10479 dsl_binding[i].binding = 0;
10480 dsl_binding[i].descriptorType = VkDescriptorType(i);
10481 dsl_binding[i].descriptorCount = 1;
10482 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10483 dsl_binding[i].pImmutableSamplers = NULL;
10484 }
10485
10486 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10487 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10488 ds_layout_ci.pNext = NULL;
10489 ds_layout_ci.bindingCount = 1;
10490 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10491 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10492 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010494 ASSERT_VK_SUCCESS(err);
10495 }
10496 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10497 VkDescriptorSetAllocateInfo alloc_info = {};
10498 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10499 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10500 alloc_info.descriptorPool = ds_pool;
10501 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010503 ASSERT_VK_SUCCESS(err);
10504
10505 // Create a buffer & bufferView to be used for invalid updates
10506 VkBufferCreateInfo buff_ci = {};
10507 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10508 // This usage is not valid for any descriptor type
10509 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10510 buff_ci.size = 256;
10511 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10512 VkBuffer buffer;
10513 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10514 ASSERT_VK_SUCCESS(err);
10515
10516 VkBufferViewCreateInfo buff_view_ci = {};
10517 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10518 buff_view_ci.buffer = buffer;
10519 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10520 buff_view_ci.range = VK_WHOLE_SIZE;
10521 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010522 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010523 ASSERT_VK_SUCCESS(err);
10524
10525 // Create an image to be used for invalid updates
10526 VkImageCreateInfo image_ci = {};
10527 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10528 image_ci.imageType = VK_IMAGE_TYPE_2D;
10529 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10530 image_ci.extent.width = 64;
10531 image_ci.extent.height = 64;
10532 image_ci.extent.depth = 1;
10533 image_ci.mipLevels = 1;
10534 image_ci.arrayLayers = 1;
10535 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10536 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10537 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10538 // This usage is not valid for any descriptor type
10539 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10540 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10541 VkImage image;
10542 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10543 ASSERT_VK_SUCCESS(err);
10544 // Bind memory to image
10545 VkMemoryRequirements mem_reqs;
10546 VkDeviceMemory image_mem;
10547 bool pass;
10548 VkMemoryAllocateInfo mem_alloc = {};
10549 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10550 mem_alloc.pNext = NULL;
10551 mem_alloc.allocationSize = 0;
10552 mem_alloc.memoryTypeIndex = 0;
10553 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10554 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010555 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010556 ASSERT_TRUE(pass);
10557 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10558 ASSERT_VK_SUCCESS(err);
10559 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10560 ASSERT_VK_SUCCESS(err);
10561 // Now create view for image
10562 VkImageViewCreateInfo image_view_ci = {};
10563 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10564 image_view_ci.image = image;
10565 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10566 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10567 image_view_ci.subresourceRange.layerCount = 1;
10568 image_view_ci.subresourceRange.baseArrayLayer = 0;
10569 image_view_ci.subresourceRange.levelCount = 1;
10570 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10571 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010572 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010573 ASSERT_VK_SUCCESS(err);
10574
10575 VkDescriptorBufferInfo buff_info = {};
10576 buff_info.buffer = buffer;
10577 VkDescriptorImageInfo img_info = {};
10578 img_info.imageView = image_view;
10579 VkWriteDescriptorSet descriptor_write = {};
10580 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10581 descriptor_write.dstBinding = 0;
10582 descriptor_write.descriptorCount = 1;
10583 descriptor_write.pTexelBufferView = &buff_view;
10584 descriptor_write.pBufferInfo = &buff_info;
10585 descriptor_write.pImageInfo = &img_info;
10586
10587 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10589 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10590 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10591 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10592 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10593 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10594 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10595 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10596 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10597 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10598 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010599 // Start loop at 1 as SAMPLER desc type has no usage bit error
10600 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10601 descriptor_write.descriptorType = VkDescriptorType(i);
10602 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010605 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010606
10607 m_errorMonitor->VerifyFound();
10608 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10609 }
10610 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10611 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010612 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010613 vkDestroyImageView(m_device->device(), image_view, NULL);
10614 vkDestroyBuffer(m_device->device(), buffer, NULL);
10615 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010617 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10618}
10619
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010620TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010621 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10622 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10623 "1. offset value greater than buffer size\n"
10624 "2. range value of 0\n"
10625 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010626 VkResult err;
10627
10628 ASSERT_NO_FATAL_FAILURE(InitState());
10629 VkDescriptorPoolSize ds_type_count = {};
10630 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10631 ds_type_count.descriptorCount = 1;
10632
10633 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10634 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10635 ds_pool_ci.pNext = NULL;
10636 ds_pool_ci.maxSets = 1;
10637 ds_pool_ci.poolSizeCount = 1;
10638 ds_pool_ci.pPoolSizes = &ds_type_count;
10639
10640 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010641 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010642 ASSERT_VK_SUCCESS(err);
10643
10644 // Create layout with single uniform buffer descriptor
10645 VkDescriptorSetLayoutBinding dsl_binding = {};
10646 dsl_binding.binding = 0;
10647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10648 dsl_binding.descriptorCount = 1;
10649 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10650 dsl_binding.pImmutableSamplers = NULL;
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 ds_layout_ci.pBindings = &dsl_binding;
10657 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010659 ASSERT_VK_SUCCESS(err);
10660
10661 VkDescriptorSet descriptor_set = {};
10662 VkDescriptorSetAllocateInfo alloc_info = {};
10663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10664 alloc_info.descriptorSetCount = 1;
10665 alloc_info.descriptorPool = ds_pool;
10666 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010668 ASSERT_VK_SUCCESS(err);
10669
10670 // Create a buffer to be used for invalid updates
10671 VkBufferCreateInfo buff_ci = {};
10672 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10673 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10674 buff_ci.size = 256;
10675 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10676 VkBuffer buffer;
10677 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10678 ASSERT_VK_SUCCESS(err);
10679 // Have to bind memory to buffer before descriptor update
10680 VkMemoryAllocateInfo mem_alloc = {};
10681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10682 mem_alloc.pNext = NULL;
10683 mem_alloc.allocationSize = 256;
10684 mem_alloc.memoryTypeIndex = 0;
10685
10686 VkMemoryRequirements mem_reqs;
10687 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010688 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010689 if (!pass) {
10690 vkDestroyBuffer(m_device->device(), buffer, NULL);
10691 return;
10692 }
10693
10694 VkDeviceMemory mem;
10695 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10696 ASSERT_VK_SUCCESS(err);
10697 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10698 ASSERT_VK_SUCCESS(err);
10699
10700 VkDescriptorBufferInfo buff_info = {};
10701 buff_info.buffer = buffer;
10702 // First make offset 1 larger than buffer size
10703 buff_info.offset = 257;
10704 buff_info.range = VK_WHOLE_SIZE;
10705 VkWriteDescriptorSet descriptor_write = {};
10706 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10707 descriptor_write.dstBinding = 0;
10708 descriptor_write.descriptorCount = 1;
10709 descriptor_write.pTexelBufferView = nullptr;
10710 descriptor_write.pBufferInfo = &buff_info;
10711 descriptor_write.pImageInfo = nullptr;
10712
10713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10714 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010716
10717 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10718
10719 m_errorMonitor->VerifyFound();
10720 // Now cause error due to range of 0
10721 buff_info.offset = 0;
10722 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10724 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010725
10726 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10727
10728 m_errorMonitor->VerifyFound();
10729 // Now cause error due to range exceeding buffer size - offset
10730 buff_info.offset = 128;
10731 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010732 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 -060010733
10734 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10735
10736 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010737 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010738 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10739 vkDestroyBuffer(m_device->device(), buffer, NULL);
10740 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10742}
10743
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010744TEST_F(VkLayerTest, DSAspectBitsErrors) {
10745 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10746 // are set, but could expand this test to hit more cases.
10747 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10748 "that do not have correct aspect bits sets.");
10749 VkResult err;
10750
10751 ASSERT_NO_FATAL_FAILURE(InitState());
10752 VkDescriptorPoolSize ds_type_count = {};
10753 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10754 ds_type_count.descriptorCount = 1;
10755
10756 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10757 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10758 ds_pool_ci.pNext = NULL;
10759 ds_pool_ci.maxSets = 5;
10760 ds_pool_ci.poolSizeCount = 1;
10761 ds_pool_ci.pPoolSizes = &ds_type_count;
10762
10763 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010764 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010765 ASSERT_VK_SUCCESS(err);
10766
10767 VkDescriptorSetLayoutBinding dsl_binding = {};
10768 dsl_binding.binding = 0;
10769 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10770 dsl_binding.descriptorCount = 1;
10771 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10772 dsl_binding.pImmutableSamplers = NULL;
10773
10774 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10775 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10776 ds_layout_ci.pNext = NULL;
10777 ds_layout_ci.bindingCount = 1;
10778 ds_layout_ci.pBindings = &dsl_binding;
10779 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010780 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010781 ASSERT_VK_SUCCESS(err);
10782
10783 VkDescriptorSet descriptor_set = {};
10784 VkDescriptorSetAllocateInfo alloc_info = {};
10785 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10786 alloc_info.descriptorSetCount = 1;
10787 alloc_info.descriptorPool = ds_pool;
10788 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010789 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010790 ASSERT_VK_SUCCESS(err);
10791
10792 // Create an image to be used for invalid updates
10793 VkImageCreateInfo image_ci = {};
10794 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10795 image_ci.imageType = VK_IMAGE_TYPE_2D;
10796 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10797 image_ci.extent.width = 64;
10798 image_ci.extent.height = 64;
10799 image_ci.extent.depth = 1;
10800 image_ci.mipLevels = 1;
10801 image_ci.arrayLayers = 1;
10802 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10803 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10804 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10805 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10806 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10807 VkImage image;
10808 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10809 ASSERT_VK_SUCCESS(err);
10810 // Bind memory to image
10811 VkMemoryRequirements mem_reqs;
10812 VkDeviceMemory image_mem;
10813 bool pass;
10814 VkMemoryAllocateInfo mem_alloc = {};
10815 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10816 mem_alloc.pNext = NULL;
10817 mem_alloc.allocationSize = 0;
10818 mem_alloc.memoryTypeIndex = 0;
10819 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10820 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010821 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010822 ASSERT_TRUE(pass);
10823 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10824 ASSERT_VK_SUCCESS(err);
10825 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10826 ASSERT_VK_SUCCESS(err);
10827 // Now create view for image
10828 VkImageViewCreateInfo image_view_ci = {};
10829 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10830 image_view_ci.image = image;
10831 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10832 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10833 image_view_ci.subresourceRange.layerCount = 1;
10834 image_view_ci.subresourceRange.baseArrayLayer = 0;
10835 image_view_ci.subresourceRange.levelCount = 1;
10836 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010837 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010838
10839 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010840 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010841 ASSERT_VK_SUCCESS(err);
10842
10843 VkDescriptorImageInfo img_info = {};
10844 img_info.imageView = image_view;
10845 VkWriteDescriptorSet descriptor_write = {};
10846 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10847 descriptor_write.dstBinding = 0;
10848 descriptor_write.descriptorCount = 1;
10849 descriptor_write.pTexelBufferView = NULL;
10850 descriptor_write.pBufferInfo = NULL;
10851 descriptor_write.pImageInfo = &img_info;
10852 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10853 descriptor_write.dstSet = descriptor_set;
10854 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10855 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010857
10858 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10859
10860 m_errorMonitor->VerifyFound();
10861 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10862 vkDestroyImage(m_device->device(), image, NULL);
10863 vkFreeMemory(m_device->device(), image_mem, NULL);
10864 vkDestroyImageView(m_device->device(), image_view, NULL);
10865 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10866 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10867}
10868
Karl Schultz6addd812016-02-02 17:17:23 -070010869TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010870 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010871 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10874 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10875 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010876
Tobin Ehlis3b780662015-05-28 12:11:26 -060010877 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010878 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010879 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010880 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10881 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010882
10883 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010884 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10885 ds_pool_ci.pNext = NULL;
10886 ds_pool_ci.maxSets = 1;
10887 ds_pool_ci.poolSizeCount = 1;
10888 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010889
Tobin Ehlis3b780662015-05-28 12:11:26 -060010890 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010891 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010892 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010893 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010894 dsl_binding.binding = 0;
10895 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10896 dsl_binding.descriptorCount = 1;
10897 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10898 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010899
Tony Barboureb254902015-07-15 12:50:33 -060010900 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010901 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10902 ds_layout_ci.pNext = NULL;
10903 ds_layout_ci.bindingCount = 1;
10904 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010905
Tobin Ehlis3b780662015-05-28 12:11:26 -060010906 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010907 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010908 ASSERT_VK_SUCCESS(err);
10909
10910 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010911 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010912 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010913 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010914 alloc_info.descriptorPool = ds_pool;
10915 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010916 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010917 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010918
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010919 VkSamplerCreateInfo sampler_ci = {};
10920 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10921 sampler_ci.pNext = NULL;
10922 sampler_ci.magFilter = VK_FILTER_NEAREST;
10923 sampler_ci.minFilter = VK_FILTER_NEAREST;
10924 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10925 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10926 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10927 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10928 sampler_ci.mipLodBias = 1.0;
10929 sampler_ci.anisotropyEnable = VK_FALSE;
10930 sampler_ci.maxAnisotropy = 1;
10931 sampler_ci.compareEnable = VK_FALSE;
10932 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10933 sampler_ci.minLod = 1.0;
10934 sampler_ci.maxLod = 1.0;
10935 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10936 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10937 VkSampler sampler;
10938 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10939 ASSERT_VK_SUCCESS(err);
10940
10941 VkDescriptorImageInfo info = {};
10942 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010943
10944 VkWriteDescriptorSet descriptor_write;
10945 memset(&descriptor_write, 0, sizeof(descriptor_write));
10946 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010947 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010948 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010949 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010950 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010951 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010952
10953 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10954
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010955 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010956
Chia-I Wuf7458c52015-10-26 21:10:41 +080010957 vkDestroySampler(m_device->device(), sampler, NULL);
10958 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10959 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010960}
10961
Karl Schultz6addd812016-02-02 17:17:23 -070010962TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010963 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010964 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10967 " binding #0 with 1 total descriptors but update of 1 descriptors "
10968 "starting at binding offset of 0 combined with update array element "
10969 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010970
Tobin Ehlis3b780662015-05-28 12:11:26 -060010971 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010972 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010973 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10975 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010976
10977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10979 ds_pool_ci.pNext = NULL;
10980 ds_pool_ci.maxSets = 1;
10981 ds_pool_ci.poolSizeCount = 1;
10982 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010983
Tobin Ehlis3b780662015-05-28 12:11:26 -060010984 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010987
Tony Barboureb254902015-07-15 12:50:33 -060010988 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010989 dsl_binding.binding = 0;
10990 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10991 dsl_binding.descriptorCount = 1;
10992 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10993 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010994
10995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10997 ds_layout_ci.pNext = NULL;
10998 ds_layout_ci.bindingCount = 1;
10999 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011000
Tobin Ehlis3b780662015-05-28 12:11:26 -060011001 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011003 ASSERT_VK_SUCCESS(err);
11004
11005 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011006 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011008 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011009 alloc_info.descriptorPool = ds_pool;
11010 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011012 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011013
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011014 // Correctly update descriptor to avoid "NOT_UPDATED" error
11015 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011016 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011017 buff_info.offset = 0;
11018 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011019
11020 VkWriteDescriptorSet descriptor_write;
11021 memset(&descriptor_write, 0, sizeof(descriptor_write));
11022 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011023 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011024 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011025 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011026 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11027 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011028
11029 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11030
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011031 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011032
Chia-I Wuf7458c52015-10-26 21:10:41 +080011033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011035}
11036
Karl Schultz6addd812016-02-02 17:17:23 -070011037TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
11038 // Create layout w/ count of 1 and attempt update to that layout w/ binding
11039 // index 2
11040 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011043
Tobin Ehlis3b780662015-05-28 12:11:26 -060011044 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011045 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11048 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011049
11050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11052 ds_pool_ci.pNext = NULL;
11053 ds_pool_ci.maxSets = 1;
11054 ds_pool_ci.poolSizeCount = 1;
11055 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011056
Tobin Ehlis3b780662015-05-28 12:11:26 -060011057 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011059 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011060
Tony Barboureb254902015-07-15 12:50:33 -060011061 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011062 dsl_binding.binding = 0;
11063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11064 dsl_binding.descriptorCount = 1;
11065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11066 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011067
11068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11070 ds_layout_ci.pNext = NULL;
11071 ds_layout_ci.bindingCount = 1;
11072 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011073 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011074 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011075 ASSERT_VK_SUCCESS(err);
11076
11077 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011078 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011080 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011081 alloc_info.descriptorPool = ds_pool;
11082 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011083 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011084 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011085
Tony Barboureb254902015-07-15 12:50:33 -060011086 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011087 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11088 sampler_ci.pNext = NULL;
11089 sampler_ci.magFilter = VK_FILTER_NEAREST;
11090 sampler_ci.minFilter = VK_FILTER_NEAREST;
11091 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11092 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11093 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11094 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11095 sampler_ci.mipLodBias = 1.0;
11096 sampler_ci.anisotropyEnable = VK_FALSE;
11097 sampler_ci.maxAnisotropy = 1;
11098 sampler_ci.compareEnable = VK_FALSE;
11099 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11100 sampler_ci.minLod = 1.0;
11101 sampler_ci.maxLod = 1.0;
11102 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11103 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011104
Tobin Ehlis3b780662015-05-28 12:11:26 -060011105 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011106 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011107 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011108
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011109 VkDescriptorImageInfo info = {};
11110 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011111
11112 VkWriteDescriptorSet descriptor_write;
11113 memset(&descriptor_write, 0, sizeof(descriptor_write));
11114 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011115 descriptor_write.dstSet = descriptorSet;
11116 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011117 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011118 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011119 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011120 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011121
11122 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11123
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011124 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011125
Chia-I Wuf7458c52015-10-26 21:10:41 +080011126 vkDestroySampler(m_device->device(), sampler, NULL);
11127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011129}
11130
Karl Schultz6addd812016-02-02 17:17:23 -070011131TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11132 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11133 // types
11134 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 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 -060011137
Tobin Ehlis3b780662015-05-28 12:11:26 -060011138 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011139
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011140 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011141 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11142 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011143
11144 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011145 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11146 ds_pool_ci.pNext = NULL;
11147 ds_pool_ci.maxSets = 1;
11148 ds_pool_ci.poolSizeCount = 1;
11149 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011150
Tobin Ehlis3b780662015-05-28 12:11:26 -060011151 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011153 ASSERT_VK_SUCCESS(err);
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;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011160
Tony Barboureb254902015-07-15 12:50:33 -060011161 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
Tony Barboureb254902015-07-15 12:50:33 -060011180 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011181 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11182 sampler_ci.pNext = NULL;
11183 sampler_ci.magFilter = VK_FILTER_NEAREST;
11184 sampler_ci.minFilter = VK_FILTER_NEAREST;
11185 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11186 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11187 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11188 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11189 sampler_ci.mipLodBias = 1.0;
11190 sampler_ci.anisotropyEnable = VK_FALSE;
11191 sampler_ci.maxAnisotropy = 1;
11192 sampler_ci.compareEnable = VK_FALSE;
11193 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11194 sampler_ci.minLod = 1.0;
11195 sampler_ci.maxLod = 1.0;
11196 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11197 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011198 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011199 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011200 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011201
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011202 VkDescriptorImageInfo info = {};
11203 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011204
11205 VkWriteDescriptorSet descriptor_write;
11206 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011207 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011208 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011209 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011210 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011211 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011212 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011213
11214 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011216 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011217
Chia-I Wuf7458c52015-10-26 21:10:41 +080011218 vkDestroySampler(m_device->device(), sampler, NULL);
11219 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11220 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011221}
11222
Karl Schultz6addd812016-02-02 17:17:23 -070011223TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011224 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011225 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11228 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011229
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011230 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011231 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11232 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011233 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011234 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11235 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011236
11237 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011238 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11239 ds_pool_ci.pNext = NULL;
11240 ds_pool_ci.maxSets = 1;
11241 ds_pool_ci.poolSizeCount = 1;
11242 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011243
11244 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011246 ASSERT_VK_SUCCESS(err);
11247
11248 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011249 dsl_binding.binding = 0;
11250 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11251 dsl_binding.descriptorCount = 1;
11252 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11253 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011254
11255 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011256 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11257 ds_layout_ci.pNext = NULL;
11258 ds_layout_ci.bindingCount = 1;
11259 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011260 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011262 ASSERT_VK_SUCCESS(err);
11263
11264 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011265 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011266 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011267 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011268 alloc_info.descriptorPool = ds_pool;
11269 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011270 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011271 ASSERT_VK_SUCCESS(err);
11272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011274
11275 VkDescriptorImageInfo descriptor_info;
11276 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11277 descriptor_info.sampler = sampler;
11278
11279 VkWriteDescriptorSet descriptor_write;
11280 memset(&descriptor_write, 0, sizeof(descriptor_write));
11281 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011282 descriptor_write.dstSet = descriptorSet;
11283 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011284 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011285 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11286 descriptor_write.pImageInfo = &descriptor_info;
11287
11288 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11289
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011290 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011291
Chia-I Wuf7458c52015-10-26 21:10:41 +080011292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011294}
11295
Karl Schultz6addd812016-02-02 17:17:23 -070011296TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11297 // Create a single combined Image/Sampler descriptor and send it an invalid
11298 // imageView
11299 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11302 "image sampler descriptor failed due "
11303 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011304
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011305 ASSERT_NO_FATAL_FAILURE(InitState());
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_COMBINED_IMAGE_SAMPLER;
11308 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -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;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011316
11317 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011318 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011319 ASSERT_VK_SUCCESS(err);
11320
11321 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011322 dsl_binding.binding = 0;
11323 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11324 dsl_binding.descriptorCount = 1;
11325 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11326 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011327
11328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11330 ds_layout_ci.pNext = NULL;
11331 ds_layout_ci.bindingCount = 1;
11332 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011333 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -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;
Tobin Ehlisa1c28562015-10-23 16:00:08 -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 Ehlisa1c28562015-10-23 16:00:08 -060011344 ASSERT_VK_SUCCESS(err);
11345
11346 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 Ehlisa1c28562015-10-23 16:00:08 -060011364
11365 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011366 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011367 ASSERT_VK_SUCCESS(err);
11368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011370
11371 VkDescriptorImageInfo descriptor_info;
11372 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11373 descriptor_info.sampler = sampler;
11374 descriptor_info.imageView = view;
11375
11376 VkWriteDescriptorSet descriptor_write;
11377 memset(&descriptor_write, 0, sizeof(descriptor_write));
11378 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011379 descriptor_write.dstSet = descriptorSet;
11380 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011381 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011382 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11383 descriptor_write.pImageInfo = &descriptor_info;
11384
11385 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11386
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011387 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011388
Chia-I Wuf7458c52015-10-26 21:10:41 +080011389 vkDestroySampler(m_device->device(), sampler, NULL);
11390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011392}
11393
Karl Schultz6addd812016-02-02 17:17:23 -070011394TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11395 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11396 // into the other
11397 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11400 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11401 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011402
Tobin Ehlis04356f92015-10-27 16:35:27 -060011403 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011404 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011405 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011406 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11407 ds_type_count[0].descriptorCount = 1;
11408 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11409 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011410
11411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11413 ds_pool_ci.pNext = NULL;
11414 ds_pool_ci.maxSets = 1;
11415 ds_pool_ci.poolSizeCount = 2;
11416 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011417
11418 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011419 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011420 ASSERT_VK_SUCCESS(err);
11421 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011422 dsl_binding[0].binding = 0;
11423 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11424 dsl_binding[0].descriptorCount = 1;
11425 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11426 dsl_binding[0].pImmutableSamplers = NULL;
11427 dsl_binding[1].binding = 1;
11428 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11429 dsl_binding[1].descriptorCount = 1;
11430 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11431 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011432
11433 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011434 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11435 ds_layout_ci.pNext = NULL;
11436 ds_layout_ci.bindingCount = 2;
11437 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011438
11439 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011440 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011441 ASSERT_VK_SUCCESS(err);
11442
11443 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011444 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011445 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011446 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011447 alloc_info.descriptorPool = ds_pool;
11448 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011450 ASSERT_VK_SUCCESS(err);
11451
11452 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011453 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11454 sampler_ci.pNext = NULL;
11455 sampler_ci.magFilter = VK_FILTER_NEAREST;
11456 sampler_ci.minFilter = VK_FILTER_NEAREST;
11457 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11458 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11459 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11460 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11461 sampler_ci.mipLodBias = 1.0;
11462 sampler_ci.anisotropyEnable = VK_FALSE;
11463 sampler_ci.maxAnisotropy = 1;
11464 sampler_ci.compareEnable = VK_FALSE;
11465 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11466 sampler_ci.minLod = 1.0;
11467 sampler_ci.maxLod = 1.0;
11468 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11469 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011470
11471 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011472 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011473 ASSERT_VK_SUCCESS(err);
11474
11475 VkDescriptorImageInfo info = {};
11476 info.sampler = sampler;
11477
11478 VkWriteDescriptorSet descriptor_write;
11479 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11480 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011481 descriptor_write.dstSet = descriptorSet;
11482 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011483 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011484 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11485 descriptor_write.pImageInfo = &info;
11486 // This write update should succeed
11487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11488 // Now perform a copy update that fails due to type mismatch
11489 VkCopyDescriptorSet copy_ds_update;
11490 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11491 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11492 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011493 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011494 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011495 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011496 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011497 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11498
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011499 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011500 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011501 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 -060011502 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11503 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11504 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011506 copy_ds_update.dstSet = descriptorSet;
11507 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011508 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011509 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11510
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011511 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011512
Tobin Ehlis04356f92015-10-27 16:35:27 -060011513 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11515 "update array offset of 0 and update of "
11516 "5 descriptors oversteps total number "
11517 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011518
Tobin Ehlis04356f92015-10-27 16:35:27 -060011519 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11520 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11521 copy_ds_update.srcSet = descriptorSet;
11522 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011523 copy_ds_update.dstSet = descriptorSet;
11524 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011525 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011526 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11527
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011528 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011529
Chia-I Wuf7458c52015-10-26 21:10:41 +080011530 vkDestroySampler(m_device->device(), sampler, NULL);
11531 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11532 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011533}
11534
Karl Schultz6addd812016-02-02 17:17:23 -070011535TEST_F(VkLayerTest, NumSamplesMismatch) {
11536 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11537 // sampleCount
11538 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011541
Tobin Ehlis3b780662015-05-28 12:11:26 -060011542 ASSERT_NO_FATAL_FAILURE(InitState());
11543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011544 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011545 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011546 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011547
11548 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011549 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11550 ds_pool_ci.pNext = NULL;
11551 ds_pool_ci.maxSets = 1;
11552 ds_pool_ci.poolSizeCount = 1;
11553 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011554
Tobin Ehlis3b780662015-05-28 12:11:26 -060011555 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011556 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011557 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011558
Tony Barboureb254902015-07-15 12:50:33 -060011559 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011560 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011561 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011562 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011563 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11564 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011565
Tony Barboureb254902015-07-15 12:50:33 -060011566 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11567 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11568 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011569 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011570 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011571
Tobin Ehlis3b780662015-05-28 12:11:26 -060011572 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011574 ASSERT_VK_SUCCESS(err);
11575
11576 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011577 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011579 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011580 alloc_info.descriptorPool = ds_pool;
11581 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011582 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011583 ASSERT_VK_SUCCESS(err);
11584
Tony Barboureb254902015-07-15 12:50:33 -060011585 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011586 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011587 pipe_ms_state_ci.pNext = NULL;
11588 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11589 pipe_ms_state_ci.sampleShadingEnable = 0;
11590 pipe_ms_state_ci.minSampleShading = 1.0;
11591 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011592
Tony Barboureb254902015-07-15 12:50:33 -060011593 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011594 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11595 pipeline_layout_ci.pNext = NULL;
11596 pipeline_layout_ci.setLayoutCount = 1;
11597 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011598
11599 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011600 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011601 ASSERT_VK_SUCCESS(err);
11602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011603 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11604 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11605 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011606 VkPipelineObj pipe(m_device);
11607 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011608 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011609 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011610 pipe.SetMSAA(&pipe_ms_state_ci);
11611 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011612
Tony Barbourfe3351b2015-07-28 10:17:20 -060011613 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011615
Mark Young29927482016-05-04 14:38:51 -060011616 // Render triangle (the error should trigger on the attempt to draw).
11617 Draw(3, 1, 0, 0);
11618
11619 // Finalize recording of the command buffer
11620 EndCommandBuffer();
11621
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011622 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011623
Chia-I Wuf7458c52015-10-26 21:10:41 +080011624 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011627}
Mark Young29927482016-05-04 14:38:51 -060011628
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011629TEST_F(VkLayerTest, RenderPassIncompatible) {
11630 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11631 "Initial case is drawing with an active renderpass that's "
11632 "not compatible with the bound PSO's creation renderpass");
11633 VkResult err;
11634
11635 ASSERT_NO_FATAL_FAILURE(InitState());
11636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11637
11638 VkDescriptorSetLayoutBinding dsl_binding = {};
11639 dsl_binding.binding = 0;
11640 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11641 dsl_binding.descriptorCount = 1;
11642 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11643 dsl_binding.pImmutableSamplers = NULL;
11644
11645 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11646 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11647 ds_layout_ci.pNext = NULL;
11648 ds_layout_ci.bindingCount = 1;
11649 ds_layout_ci.pBindings = &dsl_binding;
11650
11651 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011652 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011653 ASSERT_VK_SUCCESS(err);
11654
11655 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11656 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11657 pipeline_layout_ci.pNext = NULL;
11658 pipeline_layout_ci.setLayoutCount = 1;
11659 pipeline_layout_ci.pSetLayouts = &ds_layout;
11660
11661 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011662 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011663 ASSERT_VK_SUCCESS(err);
11664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11666 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11667 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011668 // Create a renderpass that will be incompatible with default renderpass
11669 VkAttachmentReference attach = {};
11670 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11671 VkAttachmentReference color_att = {};
11672 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11673 VkSubpassDescription subpass = {};
11674 subpass.inputAttachmentCount = 1;
11675 subpass.pInputAttachments = &attach;
11676 subpass.colorAttachmentCount = 1;
11677 subpass.pColorAttachments = &color_att;
11678 VkRenderPassCreateInfo rpci = {};
11679 rpci.subpassCount = 1;
11680 rpci.pSubpasses = &subpass;
11681 rpci.attachmentCount = 1;
11682 VkAttachmentDescription attach_desc = {};
11683 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011684 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11685 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011686 rpci.pAttachments = &attach_desc;
11687 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11688 VkRenderPass rp;
11689 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11690 VkPipelineObj pipe(m_device);
11691 pipe.AddShader(&vs);
11692 pipe.AddShader(&fs);
11693 pipe.AddColorAttachment();
11694 VkViewport view_port = {};
11695 m_viewports.push_back(view_port);
11696 pipe.SetViewport(m_viewports);
11697 VkRect2D rect = {};
11698 m_scissors.push_back(rect);
11699 pipe.SetScissor(m_scissors);
11700 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11701
11702 VkCommandBufferInheritanceInfo cbii = {};
11703 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11704 cbii.renderPass = rp;
11705 cbii.subpass = 0;
11706 VkCommandBufferBeginInfo cbbi = {};
11707 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11708 cbbi.pInheritanceInfo = &cbii;
11709 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11710 VkRenderPassBeginInfo rpbi = {};
11711 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11712 rpbi.framebuffer = m_framebuffer;
11713 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011714 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11715 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011716
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011718 // Render triangle (the error should trigger on the attempt to draw).
11719 Draw(3, 1, 0, 0);
11720
11721 // Finalize recording of the command buffer
11722 EndCommandBuffer();
11723
11724 m_errorMonitor->VerifyFound();
11725
11726 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11727 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11728 vkDestroyRenderPass(m_device->device(), rp, NULL);
11729}
11730
Mark Youngc89c6312016-03-31 16:03:20 -060011731TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11732 // Create Pipeline where the number of blend attachments doesn't match the
11733 // number of color attachments. In this case, we don't add any color
11734 // blend attachments even though we have a color attachment.
11735 VkResult err;
11736
11737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011738 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011739
11740 ASSERT_NO_FATAL_FAILURE(InitState());
11741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11742 VkDescriptorPoolSize ds_type_count = {};
11743 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11744 ds_type_count.descriptorCount = 1;
11745
11746 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11747 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11748 ds_pool_ci.pNext = NULL;
11749 ds_pool_ci.maxSets = 1;
11750 ds_pool_ci.poolSizeCount = 1;
11751 ds_pool_ci.pPoolSizes = &ds_type_count;
11752
11753 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011754 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011755 ASSERT_VK_SUCCESS(err);
11756
11757 VkDescriptorSetLayoutBinding dsl_binding = {};
11758 dsl_binding.binding = 0;
11759 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11760 dsl_binding.descriptorCount = 1;
11761 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11762 dsl_binding.pImmutableSamplers = NULL;
11763
11764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11766 ds_layout_ci.pNext = NULL;
11767 ds_layout_ci.bindingCount = 1;
11768 ds_layout_ci.pBindings = &dsl_binding;
11769
11770 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011772 ASSERT_VK_SUCCESS(err);
11773
11774 VkDescriptorSet descriptorSet;
11775 VkDescriptorSetAllocateInfo alloc_info = {};
11776 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11777 alloc_info.descriptorSetCount = 1;
11778 alloc_info.descriptorPool = ds_pool;
11779 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011780 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011781 ASSERT_VK_SUCCESS(err);
11782
11783 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011784 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011785 pipe_ms_state_ci.pNext = NULL;
11786 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11787 pipe_ms_state_ci.sampleShadingEnable = 0;
11788 pipe_ms_state_ci.minSampleShading = 1.0;
11789 pipe_ms_state_ci.pSampleMask = NULL;
11790
11791 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11792 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11793 pipeline_layout_ci.pNext = NULL;
11794 pipeline_layout_ci.setLayoutCount = 1;
11795 pipeline_layout_ci.pSetLayouts = &ds_layout;
11796
11797 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011798 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011799 ASSERT_VK_SUCCESS(err);
11800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011801 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11802 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11803 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011804 VkPipelineObj pipe(m_device);
11805 pipe.AddShader(&vs);
11806 pipe.AddShader(&fs);
11807 pipe.SetMSAA(&pipe_ms_state_ci);
11808 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11809
11810 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011811 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011812
Mark Young29927482016-05-04 14:38:51 -060011813 // Render triangle (the error should trigger on the attempt to draw).
11814 Draw(3, 1, 0, 0);
11815
11816 // Finalize recording of the command buffer
11817 EndCommandBuffer();
11818
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011819 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011820
11821 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11823 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11824}
Mark Young29927482016-05-04 14:38:51 -060011825
Mark Muellerd4914412016-06-13 17:52:06 -060011826TEST_F(VkLayerTest, MissingClearAttachment) {
11827 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11828 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011829 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011831 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011832
11833 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11834 m_errorMonitor->VerifyFound();
11835}
11836
Karl Schultz6addd812016-02-02 17:17:23 -070011837TEST_F(VkLayerTest, ClearCmdNoDraw) {
11838 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
11839 // to issuing a Draw
11840 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11843 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011844
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011845 ASSERT_NO_FATAL_FAILURE(InitState());
11846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011847
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011848 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011849 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11850 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011851
11852 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011853 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11854 ds_pool_ci.pNext = NULL;
11855 ds_pool_ci.maxSets = 1;
11856 ds_pool_ci.poolSizeCount = 1;
11857 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011858
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011859 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011860 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011861 ASSERT_VK_SUCCESS(err);
11862
Tony Barboureb254902015-07-15 12:50:33 -060011863 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011864 dsl_binding.binding = 0;
11865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11866 dsl_binding.descriptorCount = 1;
11867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11868 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011869
Tony Barboureb254902015-07-15 12:50:33 -060011870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11872 ds_layout_ci.pNext = NULL;
11873 ds_layout_ci.bindingCount = 1;
11874 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011875
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011876 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011878 ASSERT_VK_SUCCESS(err);
11879
11880 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011881 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011882 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011883 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011884 alloc_info.descriptorPool = ds_pool;
11885 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011887 ASSERT_VK_SUCCESS(err);
11888
Tony Barboureb254902015-07-15 12:50:33 -060011889 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011890 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011891 pipe_ms_state_ci.pNext = NULL;
11892 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11893 pipe_ms_state_ci.sampleShadingEnable = 0;
11894 pipe_ms_state_ci.minSampleShading = 1.0;
11895 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011896
Tony Barboureb254902015-07-15 12:50:33 -060011897 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011898 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11899 pipeline_layout_ci.pNext = NULL;
11900 pipeline_layout_ci.setLayoutCount = 1;
11901 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011902
11903 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011904 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011905 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011907 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011908 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011909 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011910 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011911
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011912 VkPipelineObj pipe(m_device);
11913 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011914 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011915 pipe.SetMSAA(&pipe_ms_state_ci);
11916 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011917
11918 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011919
Karl Schultz6addd812016-02-02 17:17:23 -070011920 // Main thing we care about for this test is that the VkImage obj we're
11921 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011922 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011923 VkClearAttachment color_attachment;
11924 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11925 color_attachment.clearValue.color.float32[0] = 1.0;
11926 color_attachment.clearValue.color.float32[1] = 1.0;
11927 color_attachment.clearValue.color.float32[2] = 1.0;
11928 color_attachment.clearValue.color.float32[3] = 1.0;
11929 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011930 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011932 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011933
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011934 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011935
Chia-I Wuf7458c52015-10-26 21:10:41 +080011936 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11937 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11938 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011939}
11940
Karl Schultz6addd812016-02-02 17:17:23 -070011941TEST_F(VkLayerTest, VtxBufferBadIndex) {
11942 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11945 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011946
Tobin Ehlis502480b2015-06-24 15:53:07 -060011947 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011948 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011950
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011951 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011952 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11953 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011954
11955 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011956 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11957 ds_pool_ci.pNext = NULL;
11958 ds_pool_ci.maxSets = 1;
11959 ds_pool_ci.poolSizeCount = 1;
11960 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011961
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011962 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011964 ASSERT_VK_SUCCESS(err);
11965
Tony Barboureb254902015-07-15 12:50:33 -060011966 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011967 dsl_binding.binding = 0;
11968 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11969 dsl_binding.descriptorCount = 1;
11970 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11971 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011972
Tony Barboureb254902015-07-15 12:50:33 -060011973 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011974 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11975 ds_layout_ci.pNext = NULL;
11976 ds_layout_ci.bindingCount = 1;
11977 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011978
Tobin Ehlis502480b2015-06-24 15:53:07 -060011979 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011981 ASSERT_VK_SUCCESS(err);
11982
11983 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011984 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011985 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011986 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011987 alloc_info.descriptorPool = ds_pool;
11988 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011990 ASSERT_VK_SUCCESS(err);
11991
Tony Barboureb254902015-07-15 12:50:33 -060011992 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011993 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011994 pipe_ms_state_ci.pNext = NULL;
11995 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11996 pipe_ms_state_ci.sampleShadingEnable = 0;
11997 pipe_ms_state_ci.minSampleShading = 1.0;
11998 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011999
Tony Barboureb254902015-07-15 12:50:33 -060012000 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012001 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12002 pipeline_layout_ci.pNext = NULL;
12003 pipeline_layout_ci.setLayoutCount = 1;
12004 pipeline_layout_ci.pSetLayouts = &ds_layout;
12005 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012007 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012008 ASSERT_VK_SUCCESS(err);
12009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012010 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12011 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
12012 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012013 VkPipelineObj pipe(m_device);
12014 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012015 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012016 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012017 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012018 pipe.SetViewport(m_viewports);
12019 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012020 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012021
12022 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012024 // Don't care about actual data, just need to get to draw to flag error
12025 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012027 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012028 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012029
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012030 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012031
Chia-I Wuf7458c52015-10-26 21:10:41 +080012032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012035}
Mark Muellerdfe37552016-07-07 14:47:42 -060012036
Mark Mueller2ee294f2016-08-04 12:59:48 -060012037TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
12038 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
12039 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060012040 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012042 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
12043 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012045 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
12046 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012048 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060012051 // The following test fails with recent NVidia drivers.
12052 // By the time core_validation is reached, the NVidia
12053 // driver has sanitized the invalid condition and core_validation
12054 // is not introduced to the failure condition. This is not the case
12055 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012056 // uint32_t count = static_cast<uint32_t>(~0);
12057 // VkPhysicalDevice physical_device;
12058 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12059 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012062 float queue_priority = 0.0;
12063
12064 VkDeviceQueueCreateInfo queue_create_info = {};
12065 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12066 queue_create_info.queueCount = 1;
12067 queue_create_info.pQueuePriorities = &queue_priority;
12068 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12069
12070 VkPhysicalDeviceFeatures features = m_device->phy().features();
12071 VkDevice testDevice;
12072 VkDeviceCreateInfo device_create_info = {};
12073 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12074 device_create_info.queueCreateInfoCount = 1;
12075 device_create_info.pQueueCreateInfos = &queue_create_info;
12076 device_create_info.pEnabledFeatures = &features;
12077 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12078 m_errorMonitor->VerifyFound();
12079
12080 queue_create_info.queueFamilyIndex = 1;
12081
12082 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12083 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12084 for (unsigned i = 0; i < feature_count; i++) {
12085 if (VK_FALSE == feature_array[i]) {
12086 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012088 device_create_info.pEnabledFeatures = &features;
12089 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12090 m_errorMonitor->VerifyFound();
12091 break;
12092 }
12093 }
12094}
12095
12096TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12097 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12098 "End a command buffer with a query still in progress.");
12099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012100 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12101 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12102 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012104 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012107
12108 ASSERT_NO_FATAL_FAILURE(InitState());
12109
12110 VkEvent event;
12111 VkEventCreateInfo event_create_info{};
12112 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12113 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12114
Mark Mueller2ee294f2016-08-04 12:59:48 -060012115 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012116 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012117
12118 BeginCommandBuffer();
12119
12120 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012121 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 -060012122 ASSERT_TRUE(image.initialized());
12123 VkImageMemoryBarrier img_barrier = {};
12124 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12125 img_barrier.pNext = NULL;
12126 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12127 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12128 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12129 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12130 img_barrier.image = image.handle();
12131 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012132
12133 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12134 // that layer validation catches the case when it is not.
12135 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012136 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12137 img_barrier.subresourceRange.baseArrayLayer = 0;
12138 img_barrier.subresourceRange.baseMipLevel = 0;
12139 img_barrier.subresourceRange.layerCount = 1;
12140 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012141 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12142 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012143 m_errorMonitor->VerifyFound();
12144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012146
12147 VkQueryPool query_pool;
12148 VkQueryPoolCreateInfo query_pool_create_info = {};
12149 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12150 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12151 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012152 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012154 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012155 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12156
12157 vkEndCommandBuffer(m_commandBuffer->handle());
12158 m_errorMonitor->VerifyFound();
12159
12160 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12161 vkDestroyEvent(m_device->device(), event, nullptr);
12162}
12163
Mark Muellerdfe37552016-07-07 14:47:42 -060012164TEST_F(VkLayerTest, VertexBufferInvalid) {
12165 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12166 "delete a buffer twice, use an invalid offset for each "
12167 "buffer type, and attempt to bind a null buffer");
12168
12169 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12170 "using deleted buffer ";
12171 const char *double_destroy_message = "Cannot free buffer 0x";
12172 const char *invalid_offset_message = "vkBindBufferMemory(): "
12173 "memoryOffset is 0x";
12174 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12175 "storage memoryOffset "
12176 "is 0x";
12177 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12178 "texel memoryOffset "
12179 "is 0x";
12180 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12181 "uniform memoryOffset "
12182 "is 0x";
12183 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12184 " to Bind Obj(0x";
12185 const char *free_invalid_buffer_message = "Request to delete memory "
12186 "object 0x";
12187
12188 ASSERT_NO_FATAL_FAILURE(InitState());
12189 ASSERT_NO_FATAL_FAILURE(InitViewport());
12190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12191
12192 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012193 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012194 pipe_ms_state_ci.pNext = NULL;
12195 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12196 pipe_ms_state_ci.sampleShadingEnable = 0;
12197 pipe_ms_state_ci.minSampleShading = 1.0;
12198 pipe_ms_state_ci.pSampleMask = nullptr;
12199
12200 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12201 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12202 VkPipelineLayout pipeline_layout;
12203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012204 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012205 ASSERT_VK_SUCCESS(err);
12206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12208 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012209 VkPipelineObj pipe(m_device);
12210 pipe.AddShader(&vs);
12211 pipe.AddShader(&fs);
12212 pipe.AddColorAttachment();
12213 pipe.SetMSAA(&pipe_ms_state_ci);
12214 pipe.SetViewport(m_viewports);
12215 pipe.SetScissor(m_scissors);
12216 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12217
12218 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012219 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012220
12221 {
12222 // Create and bind a vertex buffer in a reduced scope, which will cause
12223 // it to be deleted upon leaving this scope
12224 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012225 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012226 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12227 draw_verticies.AddVertexInputToPipe(pipe);
12228 }
12229
12230 Draw(1, 0, 0, 0);
12231
12232 EndCommandBuffer();
12233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012235 QueueCommandBuffer(false);
12236 m_errorMonitor->VerifyFound();
12237
12238 {
12239 // Create and bind a vertex buffer in a reduced scope, and delete it
12240 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012243 buffer_test.TestDoubleDestroy();
12244 }
12245 m_errorMonitor->VerifyFound();
12246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012247 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012248 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12250 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12251 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012252 m_errorMonitor->VerifyFound();
12253 }
12254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012255 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12256 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012257 // Create and bind a memory buffer with an invalid offset again,
12258 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12260 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12261 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012262 m_errorMonitor->VerifyFound();
12263 }
12264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012266 // Create and bind a memory buffer with an invalid offset again, but
12267 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12269 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12270 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012271 m_errorMonitor->VerifyFound();
12272 }
12273
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012274 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012275 // Create and bind a memory buffer with an invalid offset again, but
12276 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12278 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12279 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012280 m_errorMonitor->VerifyFound();
12281 }
12282
12283 {
12284 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12286 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12287 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012288 m_errorMonitor->VerifyFound();
12289 }
12290
12291 {
12292 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12294 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12295 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012296 }
12297 m_errorMonitor->VerifyFound();
12298
12299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12300}
12301
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012302// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12303TEST_F(VkLayerTest, InvalidImageLayout) {
12304 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012305 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12306 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012307 // 3 in ValidateCmdBufImageLayouts
12308 // * -1 Attempt to submit cmd buf w/ deleted image
12309 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12310 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12312 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012313
12314 ASSERT_NO_FATAL_FAILURE(InitState());
12315 // Create src & dst images to use for copy operations
12316 VkImage src_image;
12317 VkImage dst_image;
12318
12319 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12320 const int32_t tex_width = 32;
12321 const int32_t tex_height = 32;
12322
12323 VkImageCreateInfo image_create_info = {};
12324 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12325 image_create_info.pNext = NULL;
12326 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12327 image_create_info.format = tex_format;
12328 image_create_info.extent.width = tex_width;
12329 image_create_info.extent.height = tex_height;
12330 image_create_info.extent.depth = 1;
12331 image_create_info.mipLevels = 1;
12332 image_create_info.arrayLayers = 4;
12333 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12334 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12336 image_create_info.flags = 0;
12337
12338 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12339 ASSERT_VK_SUCCESS(err);
12340 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12341 ASSERT_VK_SUCCESS(err);
12342
12343 BeginCommandBuffer();
12344 VkImageCopy copyRegion;
12345 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12346 copyRegion.srcSubresource.mipLevel = 0;
12347 copyRegion.srcSubresource.baseArrayLayer = 0;
12348 copyRegion.srcSubresource.layerCount = 1;
12349 copyRegion.srcOffset.x = 0;
12350 copyRegion.srcOffset.y = 0;
12351 copyRegion.srcOffset.z = 0;
12352 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12353 copyRegion.dstSubresource.mipLevel = 0;
12354 copyRegion.dstSubresource.baseArrayLayer = 0;
12355 copyRegion.dstSubresource.layerCount = 1;
12356 copyRegion.dstOffset.x = 0;
12357 copyRegion.dstOffset.y = 0;
12358 copyRegion.dstOffset.z = 0;
12359 copyRegion.extent.width = 1;
12360 copyRegion.extent.height = 1;
12361 copyRegion.extent.depth = 1;
12362 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12363 m_errorMonitor->VerifyFound();
12364 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12366 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12367 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012368 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12369 m_errorMonitor->VerifyFound();
12370 // Final src error is due to bad layout type
12371 m_errorMonitor->SetDesiredFailureMsg(
12372 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12373 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12374 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12375 m_errorMonitor->VerifyFound();
12376 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12378 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012379 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12380 m_errorMonitor->VerifyFound();
12381 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12383 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12384 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012385 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12386 m_errorMonitor->VerifyFound();
12387 m_errorMonitor->SetDesiredFailureMsg(
12388 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12389 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12390 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12391 m_errorMonitor->VerifyFound();
12392 // Now cause error due to bad image layout transition in PipelineBarrier
12393 VkImageMemoryBarrier image_barrier[1] = {};
12394 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12395 image_barrier[0].image = src_image;
12396 image_barrier[0].subresourceRange.layerCount = 2;
12397 image_barrier[0].subresourceRange.levelCount = 2;
12398 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12400 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12401 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12402 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12403 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012404 m_errorMonitor->VerifyFound();
12405
12406 // Finally some layout errors at RenderPass create time
12407 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12408 VkAttachmentReference attach = {};
12409 // perf warning for GENERAL layout w/ non-DS input attachment
12410 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12411 VkSubpassDescription subpass = {};
12412 subpass.inputAttachmentCount = 1;
12413 subpass.pInputAttachments = &attach;
12414 VkRenderPassCreateInfo rpci = {};
12415 rpci.subpassCount = 1;
12416 rpci.pSubpasses = &subpass;
12417 rpci.attachmentCount = 1;
12418 VkAttachmentDescription attach_desc = {};
12419 attach_desc.format = VK_FORMAT_UNDEFINED;
12420 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012421 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012422 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12424 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012425 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12426 m_errorMonitor->VerifyFound();
12427 // error w/ non-general layout
12428 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12429
12430 m_errorMonitor->SetDesiredFailureMsg(
12431 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12432 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12433 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12434 m_errorMonitor->VerifyFound();
12435 subpass.inputAttachmentCount = 0;
12436 subpass.colorAttachmentCount = 1;
12437 subpass.pColorAttachments = &attach;
12438 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12439 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12441 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012442 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12443 m_errorMonitor->VerifyFound();
12444 // error w/ non-color opt or GENERAL layout for color attachment
12445 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12446 m_errorMonitor->SetDesiredFailureMsg(
12447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12448 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12449 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12450 m_errorMonitor->VerifyFound();
12451 subpass.colorAttachmentCount = 0;
12452 subpass.pDepthStencilAttachment = &attach;
12453 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12454 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12456 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012457 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12458 m_errorMonitor->VerifyFound();
12459 // error w/ non-ds opt or GENERAL layout for color attachment
12460 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12462 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12463 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012464 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12465 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012466 // For this error we need a valid renderpass so create default one
12467 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12468 attach.attachment = 0;
12469 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12470 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12471 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12472 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12473 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12474 // Can't do a CLEAR load on READ_ONLY initialLayout
12475 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12476 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12477 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12479 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12480 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012481 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12482 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012483
12484 vkDestroyImage(m_device->device(), src_image, NULL);
12485 vkDestroyImage(m_device->device(), dst_image, NULL);
12486}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012487
12488TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12489 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12490 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12491 "has a valid layout, and a second subpass then uses a "
12492 "valid *READ_ONLY* layout.");
12493 m_errorMonitor->ExpectSuccess();
12494 ASSERT_NO_FATAL_FAILURE(InitState());
12495
12496 VkAttachmentReference attach[2] = {};
12497 attach[0].attachment = 0;
12498 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12499 attach[1].attachment = 0;
12500 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12501 VkSubpassDescription subpasses[2] = {};
12502 // First subpass clears DS attach on load
12503 subpasses[0].pDepthStencilAttachment = &attach[0];
12504 // 2nd subpass reads in DS as input attachment
12505 subpasses[1].inputAttachmentCount = 1;
12506 subpasses[1].pInputAttachments = &attach[1];
12507 VkAttachmentDescription attach_desc = {};
12508 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12509 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12510 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12511 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12512 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12513 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012514 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012515 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12516 VkRenderPassCreateInfo rpci = {};
12517 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12518 rpci.attachmentCount = 1;
12519 rpci.pAttachments = &attach_desc;
12520 rpci.subpassCount = 2;
12521 rpci.pSubpasses = subpasses;
12522
12523 // Now create RenderPass and verify no errors
12524 VkRenderPass rp;
12525 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12526 m_errorMonitor->VerifyNotFound();
12527
12528 vkDestroyRenderPass(m_device->device(), rp, NULL);
12529}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012530
Mark Mueller93b938f2016-08-18 10:27:40 -060012531TEST_F(VkLayerTest, SimultaneousUse) {
12532 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12533 "in primary and secondary command buffers.");
12534
12535 ASSERT_NO_FATAL_FAILURE(InitState());
12536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12539 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12540 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012541
12542 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012543 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012544 command_buffer_allocate_info.commandPool = m_commandPool;
12545 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12546 command_buffer_allocate_info.commandBufferCount = 1;
12547
12548 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012549 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012550 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12551 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012552 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012553 command_buffer_inheritance_info.renderPass = m_renderPass;
12554 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12555 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012556 command_buffer_begin_info.flags =
12557 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012558 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12559
12560 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012561 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12562 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012563 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012564 vkEndCommandBuffer(secondary_command_buffer);
12565
Mark Mueller93b938f2016-08-18 10:27:40 -060012566 VkSubmitInfo submit_info = {};
12567 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12568 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012569 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012571
Mark Mueller4042b652016-09-05 22:52:21 -060012572 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012573 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12575 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012576 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012577 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12578 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012579
12580 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12582
Mark Mueller4042b652016-09-05 22:52:21 -060012583 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012584 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012585 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012586
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12588 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012589 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012590 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12591 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012592}
12593
Mark Mueller917f6bc2016-08-30 10:57:19 -060012594TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12595 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12596 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012597 "Delete objects that are inuse. Call VkQueueSubmit "
12598 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012599
12600 ASSERT_NO_FATAL_FAILURE(InitState());
12601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012603 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12604 const char *cannot_delete_event_message = "Cannot delete event 0x";
12605 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12606 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012607
12608 BeginCommandBuffer();
12609
12610 VkEvent event;
12611 VkEventCreateInfo event_create_info = {};
12612 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12613 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012614 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012615
Mark Muellerc8d441e2016-08-23 17:36:00 -060012616 EndCommandBuffer();
12617 vkDestroyEvent(m_device->device(), event, nullptr);
12618
12619 VkSubmitInfo submit_info = {};
12620 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12621 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012622 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12625 m_errorMonitor->VerifyFound();
12626
12627 m_errorMonitor->SetDesiredFailureMsg(0, "");
12628 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12629
12630 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12631
Mark Mueller917f6bc2016-08-30 10:57:19 -060012632 VkSemaphoreCreateInfo semaphore_create_info = {};
12633 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12634 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012635 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012636 VkFenceCreateInfo fence_create_info = {};
12637 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12638 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012639 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012640
12641 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012642 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012643 descriptor_pool_type_count.descriptorCount = 1;
12644
12645 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12646 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12647 descriptor_pool_create_info.maxSets = 1;
12648 descriptor_pool_create_info.poolSizeCount = 1;
12649 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012650 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012651
12652 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012653 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012654
12655 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012656 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012657 descriptorset_layout_binding.descriptorCount = 1;
12658 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12659
12660 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012661 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012662 descriptorset_layout_create_info.bindingCount = 1;
12663 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12664
12665 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012666 ASSERT_VK_SUCCESS(
12667 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012668
12669 VkDescriptorSet descriptorset;
12670 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012671 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012672 descriptorset_allocate_info.descriptorSetCount = 1;
12673 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12674 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012675 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012676
Mark Mueller4042b652016-09-05 22:52:21 -060012677 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12678
12679 VkDescriptorBufferInfo buffer_info = {};
12680 buffer_info.buffer = buffer_test.GetBuffer();
12681 buffer_info.offset = 0;
12682 buffer_info.range = 1024;
12683
12684 VkWriteDescriptorSet write_descriptor_set = {};
12685 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12686 write_descriptor_set.dstSet = descriptorset;
12687 write_descriptor_set.descriptorCount = 1;
12688 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12689 write_descriptor_set.pBufferInfo = &buffer_info;
12690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012691 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012693 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12694 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012695
12696 VkPipelineObj pipe(m_device);
12697 pipe.AddColorAttachment();
12698 pipe.AddShader(&vs);
12699 pipe.AddShader(&fs);
12700
12701 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012702 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012703 pipeline_layout_create_info.setLayoutCount = 1;
12704 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12705
12706 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012707 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012708
12709 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12710
Mark Muellerc8d441e2016-08-23 17:36:00 -060012711 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012712 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012713
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012714 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12715 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12716 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012717
Mark Muellerc8d441e2016-08-23 17:36:00 -060012718 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012719
Mark Mueller917f6bc2016-08-30 10:57:19 -060012720 submit_info.signalSemaphoreCount = 1;
12721 submit_info.pSignalSemaphores = &semaphore;
12722 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012725 vkDestroyEvent(m_device->device(), event, nullptr);
12726 m_errorMonitor->VerifyFound();
12727
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012729 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12730 m_errorMonitor->VerifyFound();
12731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012733 vkDestroyFence(m_device->device(), fence, nullptr);
12734 m_errorMonitor->VerifyFound();
12735
Tobin Ehlis122207b2016-09-01 08:50:06 -070012736 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012737 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12738 vkDestroyFence(m_device->device(), fence, nullptr);
12739 vkDestroyEvent(m_device->device(), event, nullptr);
12740 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012741 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012742 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12743}
12744
Tobin Ehlis2adda372016-09-01 08:51:06 -070012745TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12746 TEST_DESCRIPTION("Delete in-use query pool.");
12747
12748 ASSERT_NO_FATAL_FAILURE(InitState());
12749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12750
12751 VkQueryPool query_pool;
12752 VkQueryPoolCreateInfo query_pool_ci{};
12753 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12754 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12755 query_pool_ci.queryCount = 1;
12756 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12757 BeginCommandBuffer();
12758 // Reset query pool to create binding with cmd buffer
12759 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12760
12761 EndCommandBuffer();
12762
12763 VkSubmitInfo submit_info = {};
12764 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12765 submit_info.commandBufferCount = 1;
12766 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12767 // Submit cmd buffer and then destroy query pool while in-flight
12768 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012771 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12772 m_errorMonitor->VerifyFound();
12773
12774 vkQueueWaitIdle(m_device->m_queue);
12775 // Now that cmd buffer done we can safely destroy query_pool
12776 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12777}
12778
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012779TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12780 TEST_DESCRIPTION("Delete in-use pipeline.");
12781
12782 ASSERT_NO_FATAL_FAILURE(InitState());
12783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12784
12785 // Empty pipeline layout used for binding PSO
12786 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12787 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12788 pipeline_layout_ci.setLayoutCount = 0;
12789 pipeline_layout_ci.pSetLayouts = NULL;
12790
12791 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012792 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012793 ASSERT_VK_SUCCESS(err);
12794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012796 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012797 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12798 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012799 // Store pipeline handle so we can actually delete it before test finishes
12800 VkPipeline delete_this_pipeline;
12801 { // Scope pipeline so it will be auto-deleted
12802 VkPipelineObj pipe(m_device);
12803 pipe.AddShader(&vs);
12804 pipe.AddShader(&fs);
12805 pipe.AddColorAttachment();
12806 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12807 delete_this_pipeline = pipe.handle();
12808
12809 BeginCommandBuffer();
12810 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012811 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012812
12813 EndCommandBuffer();
12814
12815 VkSubmitInfo submit_info = {};
12816 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12817 submit_info.commandBufferCount = 1;
12818 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12819 // Submit cmd buffer and then pipeline destroyed while in-flight
12820 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12821 } // Pipeline deletion triggered here
12822 m_errorMonitor->VerifyFound();
12823 // Make sure queue finished and then actually delete pipeline
12824 vkQueueWaitIdle(m_device->m_queue);
12825 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12826 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12827}
12828
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012829TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12830 TEST_DESCRIPTION("Delete in-use imageView.");
12831
12832 ASSERT_NO_FATAL_FAILURE(InitState());
12833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12834
12835 VkDescriptorPoolSize ds_type_count;
12836 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12837 ds_type_count.descriptorCount = 1;
12838
12839 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12840 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12841 ds_pool_ci.maxSets = 1;
12842 ds_pool_ci.poolSizeCount = 1;
12843 ds_pool_ci.pPoolSizes = &ds_type_count;
12844
12845 VkDescriptorPool ds_pool;
12846 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12847 ASSERT_VK_SUCCESS(err);
12848
12849 VkSamplerCreateInfo sampler_ci = {};
12850 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12851 sampler_ci.pNext = NULL;
12852 sampler_ci.magFilter = VK_FILTER_NEAREST;
12853 sampler_ci.minFilter = VK_FILTER_NEAREST;
12854 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12855 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12856 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12857 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12858 sampler_ci.mipLodBias = 1.0;
12859 sampler_ci.anisotropyEnable = VK_FALSE;
12860 sampler_ci.maxAnisotropy = 1;
12861 sampler_ci.compareEnable = VK_FALSE;
12862 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12863 sampler_ci.minLod = 1.0;
12864 sampler_ci.maxLod = 1.0;
12865 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12866 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12867 VkSampler sampler;
12868
12869 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12870 ASSERT_VK_SUCCESS(err);
12871
12872 VkDescriptorSetLayoutBinding layout_binding;
12873 layout_binding.binding = 0;
12874 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12875 layout_binding.descriptorCount = 1;
12876 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12877 layout_binding.pImmutableSamplers = NULL;
12878
12879 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12880 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12881 ds_layout_ci.bindingCount = 1;
12882 ds_layout_ci.pBindings = &layout_binding;
12883 VkDescriptorSetLayout ds_layout;
12884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12885 ASSERT_VK_SUCCESS(err);
12886
12887 VkDescriptorSetAllocateInfo alloc_info = {};
12888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12889 alloc_info.descriptorSetCount = 1;
12890 alloc_info.descriptorPool = ds_pool;
12891 alloc_info.pSetLayouts = &ds_layout;
12892 VkDescriptorSet descriptor_set;
12893 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12894 ASSERT_VK_SUCCESS(err);
12895
12896 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12897 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12898 pipeline_layout_ci.pNext = NULL;
12899 pipeline_layout_ci.setLayoutCount = 1;
12900 pipeline_layout_ci.pSetLayouts = &ds_layout;
12901
12902 VkPipelineLayout pipeline_layout;
12903 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12904 ASSERT_VK_SUCCESS(err);
12905
12906 VkImageObj image(m_device);
12907 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12908 ASSERT_TRUE(image.initialized());
12909
12910 VkImageView view;
12911 VkImageViewCreateInfo ivci = {};
12912 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12913 ivci.image = image.handle();
12914 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12915 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12916 ivci.subresourceRange.layerCount = 1;
12917 ivci.subresourceRange.baseMipLevel = 0;
12918 ivci.subresourceRange.levelCount = 1;
12919 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12920
12921 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12922 ASSERT_VK_SUCCESS(err);
12923
12924 VkDescriptorImageInfo image_info{};
12925 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12926 image_info.imageView = view;
12927 image_info.sampler = sampler;
12928
12929 VkWriteDescriptorSet descriptor_write = {};
12930 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12931 descriptor_write.dstSet = descriptor_set;
12932 descriptor_write.dstBinding = 0;
12933 descriptor_write.descriptorCount = 1;
12934 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12935 descriptor_write.pImageInfo = &image_info;
12936
12937 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12938
12939 // Create PSO to use the sampler
12940 char const *vsSource = "#version 450\n"
12941 "\n"
12942 "out gl_PerVertex { \n"
12943 " vec4 gl_Position;\n"
12944 "};\n"
12945 "void main(){\n"
12946 " gl_Position = vec4(1);\n"
12947 "}\n";
12948 char const *fsSource = "#version 450\n"
12949 "\n"
12950 "layout(set=0, binding=0) uniform sampler2D s;\n"
12951 "layout(location=0) out vec4 x;\n"
12952 "void main(){\n"
12953 " x = texture(s, vec2(1));\n"
12954 "}\n";
12955 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12956 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12957 VkPipelineObj pipe(m_device);
12958 pipe.AddShader(&vs);
12959 pipe.AddShader(&fs);
12960 pipe.AddColorAttachment();
12961 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12962
12963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
12964
12965 BeginCommandBuffer();
12966 // Bind pipeline to cmd buffer
12967 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12968 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12969 &descriptor_set, 0, nullptr);
12970 Draw(1, 0, 0, 0);
12971 EndCommandBuffer();
12972 // Submit cmd buffer then destroy sampler
12973 VkSubmitInfo submit_info = {};
12974 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12975 submit_info.commandBufferCount = 1;
12976 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12977 // Submit cmd buffer and then destroy imageView while in-flight
12978 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12979
12980 vkDestroyImageView(m_device->device(), view, nullptr);
12981 m_errorMonitor->VerifyFound();
12982 vkQueueWaitIdle(m_device->m_queue);
12983 // Now we can actually destroy imageView
12984 vkDestroyImageView(m_device->device(), view, NULL);
12985 vkDestroySampler(m_device->device(), sampler, nullptr);
12986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12989}
12990
Tobin Ehlis209532e2016-09-07 13:52:18 -060012991TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12992 TEST_DESCRIPTION("Delete in-use sampler.");
12993
12994 ASSERT_NO_FATAL_FAILURE(InitState());
12995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12996
12997 VkDescriptorPoolSize ds_type_count;
12998 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12999 ds_type_count.descriptorCount = 1;
13000
13001 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13002 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13003 ds_pool_ci.maxSets = 1;
13004 ds_pool_ci.poolSizeCount = 1;
13005 ds_pool_ci.pPoolSizes = &ds_type_count;
13006
13007 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013009 ASSERT_VK_SUCCESS(err);
13010
13011 VkSamplerCreateInfo sampler_ci = {};
13012 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13013 sampler_ci.pNext = NULL;
13014 sampler_ci.magFilter = VK_FILTER_NEAREST;
13015 sampler_ci.minFilter = VK_FILTER_NEAREST;
13016 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13017 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13018 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13019 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13020 sampler_ci.mipLodBias = 1.0;
13021 sampler_ci.anisotropyEnable = VK_FALSE;
13022 sampler_ci.maxAnisotropy = 1;
13023 sampler_ci.compareEnable = VK_FALSE;
13024 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13025 sampler_ci.minLod = 1.0;
13026 sampler_ci.maxLod = 1.0;
13027 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13028 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13029 VkSampler sampler;
13030
13031 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13032 ASSERT_VK_SUCCESS(err);
13033
13034 VkDescriptorSetLayoutBinding layout_binding;
13035 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013036 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013037 layout_binding.descriptorCount = 1;
13038 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13039 layout_binding.pImmutableSamplers = NULL;
13040
13041 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13042 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13043 ds_layout_ci.bindingCount = 1;
13044 ds_layout_ci.pBindings = &layout_binding;
13045 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013047 ASSERT_VK_SUCCESS(err);
13048
13049 VkDescriptorSetAllocateInfo alloc_info = {};
13050 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13051 alloc_info.descriptorSetCount = 1;
13052 alloc_info.descriptorPool = ds_pool;
13053 alloc_info.pSetLayouts = &ds_layout;
13054 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013056 ASSERT_VK_SUCCESS(err);
13057
13058 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13059 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13060 pipeline_layout_ci.pNext = NULL;
13061 pipeline_layout_ci.setLayoutCount = 1;
13062 pipeline_layout_ci.pSetLayouts = &ds_layout;
13063
13064 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013065 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013066 ASSERT_VK_SUCCESS(err);
13067
13068 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013069 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 -060013070 ASSERT_TRUE(image.initialized());
13071
13072 VkImageView view;
13073 VkImageViewCreateInfo ivci = {};
13074 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13075 ivci.image = image.handle();
13076 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13077 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13078 ivci.subresourceRange.layerCount = 1;
13079 ivci.subresourceRange.baseMipLevel = 0;
13080 ivci.subresourceRange.levelCount = 1;
13081 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13082
13083 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13084 ASSERT_VK_SUCCESS(err);
13085
13086 VkDescriptorImageInfo image_info{};
13087 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13088 image_info.imageView = view;
13089 image_info.sampler = sampler;
13090
13091 VkWriteDescriptorSet descriptor_write = {};
13092 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13093 descriptor_write.dstSet = descriptor_set;
13094 descriptor_write.dstBinding = 0;
13095 descriptor_write.descriptorCount = 1;
13096 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13097 descriptor_write.pImageInfo = &image_info;
13098
13099 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13100
13101 // Create PSO to use the sampler
13102 char const *vsSource = "#version 450\n"
13103 "\n"
13104 "out gl_PerVertex { \n"
13105 " vec4 gl_Position;\n"
13106 "};\n"
13107 "void main(){\n"
13108 " gl_Position = vec4(1);\n"
13109 "}\n";
13110 char const *fsSource = "#version 450\n"
13111 "\n"
13112 "layout(set=0, binding=0) uniform sampler2D s;\n"
13113 "layout(location=0) out vec4 x;\n"
13114 "void main(){\n"
13115 " x = texture(s, vec2(1));\n"
13116 "}\n";
13117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13119 VkPipelineObj pipe(m_device);
13120 pipe.AddShader(&vs);
13121 pipe.AddShader(&fs);
13122 pipe.AddColorAttachment();
13123 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060013126
13127 BeginCommandBuffer();
13128 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013129 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13130 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13131 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013132 Draw(1, 0, 0, 0);
13133 EndCommandBuffer();
13134 // Submit cmd buffer then destroy sampler
13135 VkSubmitInfo submit_info = {};
13136 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13137 submit_info.commandBufferCount = 1;
13138 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13139 // Submit cmd buffer and then destroy sampler while in-flight
13140 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13141
13142 vkDestroySampler(m_device->device(), sampler, nullptr);
13143 m_errorMonitor->VerifyFound();
13144 vkQueueWaitIdle(m_device->m_queue);
13145 // Now we can actually destroy sampler
13146 vkDestroySampler(m_device->device(), sampler, nullptr);
13147 vkDestroyImageView(m_device->device(), view, NULL);
13148 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13149 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13150 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13151}
13152
Mark Mueller1cd9f412016-08-25 13:23:52 -060013153TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060013154 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060013155 "signaled but not waited on by the queue. Wait on a "
13156 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013157
13158 ASSERT_NO_FATAL_FAILURE(InitState());
13159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013161 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
13162 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
13163 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013164
13165 BeginCommandBuffer();
13166 EndCommandBuffer();
13167
13168 VkSemaphoreCreateInfo semaphore_create_info = {};
13169 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13170 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013171 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013172 VkSubmitInfo submit_info = {};
13173 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13174 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013175 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013176 submit_info.signalSemaphoreCount = 1;
13177 submit_info.pSignalSemaphores = &semaphore;
13178 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13179 m_errorMonitor->SetDesiredFailureMsg(0, "");
13180 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
13181 BeginCommandBuffer();
13182 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013184 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13185 m_errorMonitor->VerifyFound();
13186
Mark Mueller1cd9f412016-08-25 13:23:52 -060013187 VkFenceCreateInfo fence_create_info = {};
13188 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13189 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013190 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013193 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13194 m_errorMonitor->VerifyFound();
13195
Mark Mueller4042b652016-09-05 22:52:21 -060013196 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013197 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013198 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13199}
13200
Tobin Ehlis4af23302016-07-19 10:50:30 -060013201TEST_F(VkLayerTest, FramebufferIncompatible) {
13202 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
13203 "that does not match the framebuffer for the active "
13204 "renderpass.");
13205 ASSERT_NO_FATAL_FAILURE(InitState());
13206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13207
13208 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013209 VkAttachmentDescription attachment = {0,
13210 VK_FORMAT_B8G8R8A8_UNORM,
13211 VK_SAMPLE_COUNT_1_BIT,
13212 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13213 VK_ATTACHMENT_STORE_OP_STORE,
13214 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13215 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13216 VK_IMAGE_LAYOUT_UNDEFINED,
13217 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013219 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013221 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013224
13225 VkRenderPass rp;
13226 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13227 ASSERT_VK_SUCCESS(err);
13228
13229 // A compatible framebuffer.
13230 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 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 -060013232 ASSERT_TRUE(image.initialized());
13233
13234 VkImageViewCreateInfo ivci = {
13235 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13236 nullptr,
13237 0,
13238 image.handle(),
13239 VK_IMAGE_VIEW_TYPE_2D,
13240 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13242 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013243 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13244 };
13245 VkImageView view;
13246 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13247 ASSERT_VK_SUCCESS(err);
13248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013249 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013250 VkFramebuffer fb;
13251 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13252 ASSERT_VK_SUCCESS(err);
13253
13254 VkCommandBufferAllocateInfo cbai = {};
13255 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13256 cbai.commandPool = m_commandPool;
13257 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13258 cbai.commandBufferCount = 1;
13259
13260 VkCommandBuffer sec_cb;
13261 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13262 ASSERT_VK_SUCCESS(err);
13263 VkCommandBufferBeginInfo cbbi = {};
13264 VkCommandBufferInheritanceInfo cbii = {};
13265 cbii.renderPass = renderPass();
13266 cbii.framebuffer = fb;
13267 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13268 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013269 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 -060013270 cbbi.pInheritanceInfo = &cbii;
13271 vkBeginCommandBuffer(sec_cb, &cbbi);
13272 vkEndCommandBuffer(sec_cb);
13273
Chris Forbes3400bc52016-09-13 18:10:34 +120013274 VkCommandBufferBeginInfo cbbi2 = {
13275 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13276 0, nullptr
13277 };
13278 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13279 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13282 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013283 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13284 m_errorMonitor->VerifyFound();
13285 // Cleanup
13286 vkDestroyImageView(m_device->device(), view, NULL);
13287 vkDestroyRenderPass(m_device->device(), rp, NULL);
13288 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13289}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013290
13291TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13292 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13293 "invalid value. If logicOp is not available, attempt to "
13294 "use it and verify that we see the correct error.");
13295 ASSERT_NO_FATAL_FAILURE(InitState());
13296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13297
13298 auto features = m_device->phy().features();
13299 // Set the expected error depending on whether or not logicOp available
13300 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13302 "enabled, logicOpEnable must be "
13303 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013304 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013306 }
13307 // Create a pipeline using logicOp
13308 VkResult err;
13309
13310 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13311 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13312
13313 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013314 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013315 ASSERT_VK_SUCCESS(err);
13316
13317 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13318 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13319 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013321 vp_state_ci.pViewports = &vp;
13322 vp_state_ci.scissorCount = 1;
13323 VkRect2D scissors = {}; // Dummy scissors to point to
13324 vp_state_ci.pScissors = &scissors;
13325 // No dynamic state
13326 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13327 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13328
13329 VkPipelineShaderStageCreateInfo shaderStages[2];
13330 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013332 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13333 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013334 shaderStages[0] = vs.GetStageCreateInfo();
13335 shaderStages[1] = fs.GetStageCreateInfo();
13336
13337 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13338 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13339
13340 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13341 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13342 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13343
13344 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13345 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13346
13347 VkPipelineColorBlendAttachmentState att = {};
13348 att.blendEnable = VK_FALSE;
13349 att.colorWriteMask = 0xf;
13350
13351 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13352 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13353 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13354 cb_ci.logicOpEnable = VK_TRUE;
13355 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13356 cb_ci.attachmentCount = 1;
13357 cb_ci.pAttachments = &att;
13358
13359 VkGraphicsPipelineCreateInfo gp_ci = {};
13360 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13361 gp_ci.stageCount = 2;
13362 gp_ci.pStages = shaderStages;
13363 gp_ci.pVertexInputState = &vi_ci;
13364 gp_ci.pInputAssemblyState = &ia_ci;
13365 gp_ci.pViewportState = &vp_state_ci;
13366 gp_ci.pRasterizationState = &rs_ci;
13367 gp_ci.pColorBlendState = &cb_ci;
13368 gp_ci.pDynamicState = &dyn_state_ci;
13369 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13370 gp_ci.layout = pipeline_layout;
13371 gp_ci.renderPass = renderPass();
13372
13373 VkPipelineCacheCreateInfo pc_ci = {};
13374 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13375
13376 VkPipeline pipeline;
13377 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013378 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013379 ASSERT_VK_SUCCESS(err);
13380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013381 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013382 m_errorMonitor->VerifyFound();
13383 if (VK_SUCCESS == err) {
13384 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13385 }
13386 m_errorMonitor->VerifyFound();
13387 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13388 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13389}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013390#endif // DRAW_STATE_TESTS
13391
Tobin Ehlis0788f522015-05-26 16:11:58 -060013392#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013393#if GTEST_IS_THREADSAFE
13394struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013395 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013396 VkEvent event;
13397 bool bailout;
13398};
13399
Karl Schultz6addd812016-02-02 17:17:23 -070013400extern "C" void *AddToCommandBuffer(void *arg) {
13401 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013402
Mike Stroyana6d14942016-07-13 15:10:05 -060013403 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013404 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013405 if (data->bailout) {
13406 break;
13407 }
13408 }
13409 return NULL;
13410}
13411
Karl Schultz6addd812016-02-02 17:17:23 -070013412TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013413 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013414
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013416
Mike Stroyanaccf7692015-05-12 16:00:45 -060013417 ASSERT_NO_FATAL_FAILURE(InitState());
13418 ASSERT_NO_FATAL_FAILURE(InitViewport());
13419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13420
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013421 // Calls AllocateCommandBuffers
13422 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013423
13424 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013425 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013426
13427 VkEventCreateInfo event_info;
13428 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013429 VkResult err;
13430
13431 memset(&event_info, 0, sizeof(event_info));
13432 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13433
Chia-I Wuf7458c52015-10-26 21:10:41 +080013434 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013435 ASSERT_VK_SUCCESS(err);
13436
Mike Stroyanaccf7692015-05-12 16:00:45 -060013437 err = vkResetEvent(device(), event);
13438 ASSERT_VK_SUCCESS(err);
13439
13440 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013441 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013442 data.event = event;
13443 data.bailout = false;
13444 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013445
13446 // First do some correct operations using multiple threads.
13447 // Add many entries to command buffer from another thread.
13448 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13449 // Make non-conflicting calls from this thread at the same time.
13450 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013451 uint32_t count;
13452 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013453 }
13454 test_platform_thread_join(thread, NULL);
13455
13456 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013457 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013458 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013459 // Add many entries to command buffer from this thread at the same time.
13460 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013461
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013462 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013463 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013464
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013465 m_errorMonitor->SetBailout(NULL);
13466
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013467 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013468
Chia-I Wuf7458c52015-10-26 21:10:41 +080013469 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013470}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013471#endif // GTEST_IS_THREADSAFE
13472#endif // THREADING_TESTS
13473
Chris Forbes9f7ff632015-05-25 11:13:08 +120013474#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013475TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013476 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13477 "with an impossible code size");
13478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013480
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013481 ASSERT_NO_FATAL_FAILURE(InitState());
13482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13483
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013484 VkShaderModule module;
13485 VkShaderModuleCreateInfo moduleCreateInfo;
13486 struct icd_spv_header spv;
13487
13488 spv.magic = ICD_SPV_MAGIC;
13489 spv.version = ICD_SPV_VERSION;
13490 spv.gen_magic = 0;
13491
13492 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13493 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013494 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013495 moduleCreateInfo.codeSize = 4;
13496 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013497 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013498
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013499 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013500}
13501
Karl Schultz6addd812016-02-02 17:17:23 -070013502TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013503 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13504 "with a bad magic number");
13505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013507
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013508 ASSERT_NO_FATAL_FAILURE(InitState());
13509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13510
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013511 VkShaderModule module;
13512 VkShaderModuleCreateInfo moduleCreateInfo;
13513 struct icd_spv_header spv;
13514
13515 spv.magic = ~ICD_SPV_MAGIC;
13516 spv.version = ICD_SPV_VERSION;
13517 spv.gen_magic = 0;
13518
13519 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13520 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013521 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013522 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13523 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013524 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013526 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013527}
13528
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013529#if 0
13530// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013531TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013533 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013534
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013535 ASSERT_NO_FATAL_FAILURE(InitState());
13536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13537
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013538 VkShaderModule module;
13539 VkShaderModuleCreateInfo moduleCreateInfo;
13540 struct icd_spv_header spv;
13541
13542 spv.magic = ICD_SPV_MAGIC;
13543 spv.version = ~ICD_SPV_VERSION;
13544 spv.gen_magic = 0;
13545
13546 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13547 moduleCreateInfo.pNext = NULL;
13548
Karl Schultz6addd812016-02-02 17:17:23 -070013549 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013550 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13551 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013552 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013553
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013554 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013555}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013556#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013557
Karl Schultz6addd812016-02-02 17:17:23 -070013558TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013559 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13560 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013562
Chris Forbes9f7ff632015-05-25 11:13:08 +120013563 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013566 char const *vsSource = "#version 450\n"
13567 "\n"
13568 "layout(location=0) out float x;\n"
13569 "out gl_PerVertex {\n"
13570 " vec4 gl_Position;\n"
13571 "};\n"
13572 "void main(){\n"
13573 " gl_Position = vec4(1);\n"
13574 " x = 0;\n"
13575 "}\n";
13576 char const *fsSource = "#version 450\n"
13577 "\n"
13578 "layout(location=0) out vec4 color;\n"
13579 "void main(){\n"
13580 " color = vec4(1);\n"
13581 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013582
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013583 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13584 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013585
13586 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013587 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013588 pipe.AddShader(&vs);
13589 pipe.AddShader(&fs);
13590
Chris Forbes9f7ff632015-05-25 11:13:08 +120013591 VkDescriptorSetObj descriptorSet(m_device);
13592 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013593 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013594
Tony Barbour5781e8f2015-08-04 16:23:11 -060013595 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013596
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013597 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013598}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013599
Karl Schultz6addd812016-02-02 17:17:23 -070013600TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013601 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13602 "which is not present in the outputs of the previous stage");
13603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013605
Chris Forbes59cb88d2015-05-25 11:13:13 +120013606 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013609 char const *vsSource = "#version 450\n"
13610 "\n"
13611 "out gl_PerVertex {\n"
13612 " vec4 gl_Position;\n"
13613 "};\n"
13614 "void main(){\n"
13615 " gl_Position = vec4(1);\n"
13616 "}\n";
13617 char const *fsSource = "#version 450\n"
13618 "\n"
13619 "layout(location=0) in float x;\n"
13620 "layout(location=0) out vec4 color;\n"
13621 "void main(){\n"
13622 " color = vec4(x);\n"
13623 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013624
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13626 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013627
13628 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013629 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013630 pipe.AddShader(&vs);
13631 pipe.AddShader(&fs);
13632
Chris Forbes59cb88d2015-05-25 11:13:13 +120013633 VkDescriptorSetObj descriptorSet(m_device);
13634 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013635 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013636
Tony Barbour5781e8f2015-08-04 16:23:11 -060013637 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013638
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013639 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013640}
13641
Karl Schultz6addd812016-02-02 17:17:23 -070013642TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013643 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13644 "within an interace block, which is not present in the outputs "
13645 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013647
13648 ASSERT_NO_FATAL_FAILURE(InitState());
13649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013651 char const *vsSource = "#version 450\n"
13652 "\n"
13653 "out gl_PerVertex {\n"
13654 " vec4 gl_Position;\n"
13655 "};\n"
13656 "void main(){\n"
13657 " gl_Position = vec4(1);\n"
13658 "}\n";
13659 char const *fsSource = "#version 450\n"
13660 "\n"
13661 "in block { layout(location=0) float x; } ins;\n"
13662 "layout(location=0) out vec4 color;\n"
13663 "void main(){\n"
13664 " color = vec4(ins.x);\n"
13665 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013666
13667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13669
13670 VkPipelineObj pipe(m_device);
13671 pipe.AddColorAttachment();
13672 pipe.AddShader(&vs);
13673 pipe.AddShader(&fs);
13674
13675 VkDescriptorSetObj descriptorSet(m_device);
13676 descriptorSet.AppendDummy();
13677 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13678
13679 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13680
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013681 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013682}
13683
Karl Schultz6addd812016-02-02 17:17:23 -070013684TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013685 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13686 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13688 "output arr[2] of float32' vs 'ptr to "
13689 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013690
13691 ASSERT_NO_FATAL_FAILURE(InitState());
13692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013694 char const *vsSource = "#version 450\n"
13695 "\n"
13696 "layout(location=0) out float x[2];\n"
13697 "out gl_PerVertex {\n"
13698 " vec4 gl_Position;\n"
13699 "};\n"
13700 "void main(){\n"
13701 " x[0] = 0; x[1] = 0;\n"
13702 " gl_Position = vec4(1);\n"
13703 "}\n";
13704 char const *fsSource = "#version 450\n"
13705 "\n"
13706 "layout(location=0) in float x[3];\n"
13707 "layout(location=0) out vec4 color;\n"
13708 "void main(){\n"
13709 " color = vec4(x[0] + x[1] + x[2]);\n"
13710 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013711
13712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13714
13715 VkPipelineObj pipe(m_device);
13716 pipe.AddColorAttachment();
13717 pipe.AddShader(&vs);
13718 pipe.AddShader(&fs);
13719
13720 VkDescriptorSetObj descriptorSet(m_device);
13721 descriptorSet.AppendDummy();
13722 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13723
13724 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13725
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013726 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013727}
13728
Karl Schultz6addd812016-02-02 17:17:23 -070013729TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013730 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13731 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013733
Chris Forbesb56af562015-05-25 11:13:17 +120013734 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013736
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013737 char const *vsSource = "#version 450\n"
13738 "\n"
13739 "layout(location=0) out int x;\n"
13740 "out gl_PerVertex {\n"
13741 " vec4 gl_Position;\n"
13742 "};\n"
13743 "void main(){\n"
13744 " x = 0;\n"
13745 " gl_Position = vec4(1);\n"
13746 "}\n";
13747 char const *fsSource = "#version 450\n"
13748 "\n"
13749 "layout(location=0) in float x;\n" /* VS writes int */
13750 "layout(location=0) out vec4 color;\n"
13751 "void main(){\n"
13752 " color = vec4(x);\n"
13753 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013754
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013757
13758 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013759 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013760 pipe.AddShader(&vs);
13761 pipe.AddShader(&fs);
13762
Chris Forbesb56af562015-05-25 11:13:17 +120013763 VkDescriptorSetObj descriptorSet(m_device);
13764 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013765 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013766
Tony Barbour5781e8f2015-08-04 16:23:11 -060013767 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013768
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013769 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013770}
13771
Karl Schultz6addd812016-02-02 17:17:23 -070013772TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013773 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13774 "the VS->FS interface, when the variable is contained within "
13775 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013777
13778 ASSERT_NO_FATAL_FAILURE(InitState());
13779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013781 char const *vsSource = "#version 450\n"
13782 "\n"
13783 "out block { layout(location=0) int x; } outs;\n"
13784 "out gl_PerVertex {\n"
13785 " vec4 gl_Position;\n"
13786 "};\n"
13787 "void main(){\n"
13788 " outs.x = 0;\n"
13789 " gl_Position = vec4(1);\n"
13790 "}\n";
13791 char const *fsSource = "#version 450\n"
13792 "\n"
13793 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13794 "layout(location=0) out vec4 color;\n"
13795 "void main(){\n"
13796 " color = vec4(ins.x);\n"
13797 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013798
13799 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13801
13802 VkPipelineObj pipe(m_device);
13803 pipe.AddColorAttachment();
13804 pipe.AddShader(&vs);
13805 pipe.AddShader(&fs);
13806
13807 VkDescriptorSetObj descriptorSet(m_device);
13808 descriptorSet.AppendDummy();
13809 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13810
13811 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13812
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013813 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013814}
13815
13816TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013817 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13818 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13819 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013820 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 +130013821
13822 ASSERT_NO_FATAL_FAILURE(InitState());
13823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013825 char const *vsSource = "#version 450\n"
13826 "\n"
13827 "out block { layout(location=1) float x; } outs;\n"
13828 "out gl_PerVertex {\n"
13829 " vec4 gl_Position;\n"
13830 "};\n"
13831 "void main(){\n"
13832 " outs.x = 0;\n"
13833 " gl_Position = vec4(1);\n"
13834 "}\n";
13835 char const *fsSource = "#version 450\n"
13836 "\n"
13837 "in block { layout(location=0) float x; } ins;\n"
13838 "layout(location=0) out vec4 color;\n"
13839 "void main(){\n"
13840 " color = vec4(ins.x);\n"
13841 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013842
13843 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13844 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13845
13846 VkPipelineObj pipe(m_device);
13847 pipe.AddColorAttachment();
13848 pipe.AddShader(&vs);
13849 pipe.AddShader(&fs);
13850
13851 VkDescriptorSetObj descriptorSet(m_device);
13852 descriptorSet.AppendDummy();
13853 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13854
13855 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13856
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013857 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013858}
13859
13860TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013861 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
13862 "VS->FS interface. It's not enough to have the same set of locations in "
13863 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013864 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 +130013865
13866 ASSERT_NO_FATAL_FAILURE(InitState());
13867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 char const *vsSource = "#version 450\n"
13870 "\n"
13871 "out block { layout(location=0, component=0) float x; } outs;\n"
13872 "out gl_PerVertex {\n"
13873 " vec4 gl_Position;\n"
13874 "};\n"
13875 "void main(){\n"
13876 " outs.x = 0;\n"
13877 " gl_Position = vec4(1);\n"
13878 "}\n";
13879 char const *fsSource = "#version 450\n"
13880 "\n"
13881 "in block { layout(location=0, component=1) float x; } ins;\n"
13882 "layout(location=0) out vec4 color;\n"
13883 "void main(){\n"
13884 " color = vec4(ins.x);\n"
13885 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013886
13887 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13888 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13889
13890 VkPipelineObj pipe(m_device);
13891 pipe.AddColorAttachment();
13892 pipe.AddShader(&vs);
13893 pipe.AddShader(&fs);
13894
13895 VkDescriptorSetObj descriptorSet(m_device);
13896 descriptorSet.AppendDummy();
13897 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13898
13899 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13900
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013901 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013902}
13903
Karl Schultz6addd812016-02-02 17:17:23 -070013904TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013905 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13906 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013908
Chris Forbesde136e02015-05-25 11:13:28 +120013909 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013911
13912 VkVertexInputBindingDescription input_binding;
13913 memset(&input_binding, 0, sizeof(input_binding));
13914
13915 VkVertexInputAttributeDescription input_attrib;
13916 memset(&input_attrib, 0, sizeof(input_attrib));
13917 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013919 char const *vsSource = "#version 450\n"
13920 "\n"
13921 "out gl_PerVertex {\n"
13922 " vec4 gl_Position;\n"
13923 "};\n"
13924 "void main(){\n"
13925 " gl_Position = vec4(1);\n"
13926 "}\n";
13927 char const *fsSource = "#version 450\n"
13928 "\n"
13929 "layout(location=0) out vec4 color;\n"
13930 "void main(){\n"
13931 " color = vec4(1);\n"
13932 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013933
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013936
13937 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013938 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013939 pipe.AddShader(&vs);
13940 pipe.AddShader(&fs);
13941
13942 pipe.AddVertexInputBindings(&input_binding, 1);
13943 pipe.AddVertexInputAttribs(&input_attrib, 1);
13944
Chris Forbesde136e02015-05-25 11:13:28 +120013945 VkDescriptorSetObj descriptorSet(m_device);
13946 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013948
Tony Barbour5781e8f2015-08-04 16:23:11 -060013949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013950
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013951 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013952}
13953
Karl Schultz6addd812016-02-02 17:17:23 -070013954TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013955 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13956 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013958
13959 ASSERT_NO_FATAL_FAILURE(InitState());
13960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13961
13962 VkVertexInputBindingDescription input_binding;
13963 memset(&input_binding, 0, sizeof(input_binding));
13964
13965 VkVertexInputAttributeDescription input_attrib;
13966 memset(&input_attrib, 0, sizeof(input_attrib));
13967 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013969 char const *vsSource = "#version 450\n"
13970 "\n"
13971 "layout(location=1) in float x;\n"
13972 "out gl_PerVertex {\n"
13973 " vec4 gl_Position;\n"
13974 "};\n"
13975 "void main(){\n"
13976 " gl_Position = vec4(x);\n"
13977 "}\n";
13978 char const *fsSource = "#version 450\n"
13979 "\n"
13980 "layout(location=0) out vec4 color;\n"
13981 "void main(){\n"
13982 " color = vec4(1);\n"
13983 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013984
13985 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13986 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13987
13988 VkPipelineObj pipe(m_device);
13989 pipe.AddColorAttachment();
13990 pipe.AddShader(&vs);
13991 pipe.AddShader(&fs);
13992
13993 pipe.AddVertexInputBindings(&input_binding, 1);
13994 pipe.AddVertexInputAttribs(&input_attrib, 1);
13995
13996 VkDescriptorSetObj descriptorSet(m_device);
13997 descriptorSet.AppendDummy();
13998 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13999
14000 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14001
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014002 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014003}
14004
Karl Schultz6addd812016-02-02 17:17:23 -070014005TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014006 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
14007 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014008 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 -060014009
Chris Forbes62e8e502015-05-25 11:13:29 +120014010 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 char const *vsSource = "#version 450\n"
14014 "\n"
14015 "layout(location=0) in vec4 x;\n" /* not provided */
14016 "out gl_PerVertex {\n"
14017 " vec4 gl_Position;\n"
14018 "};\n"
14019 "void main(){\n"
14020 " gl_Position = x;\n"
14021 "}\n";
14022 char const *fsSource = "#version 450\n"
14023 "\n"
14024 "layout(location=0) out vec4 color;\n"
14025 "void main(){\n"
14026 " color = vec4(1);\n"
14027 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014028
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014029 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14030 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014031
14032 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014033 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014034 pipe.AddShader(&vs);
14035 pipe.AddShader(&fs);
14036
Chris Forbes62e8e502015-05-25 11:13:29 +120014037 VkDescriptorSetObj descriptorSet(m_device);
14038 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014039 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014040
Tony Barbour5781e8f2015-08-04 16:23:11 -060014041 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014042
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014043 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014044}
14045
Karl Schultz6addd812016-02-02 17:17:23 -070014046TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014047 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
14048 "fundamental type (float/int/uint) of an attribute and the "
14049 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014051
Chris Forbesc97d98e2015-05-25 11:13:31 +120014052 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014054
14055 VkVertexInputBindingDescription input_binding;
14056 memset(&input_binding, 0, sizeof(input_binding));
14057
14058 VkVertexInputAttributeDescription input_attrib;
14059 memset(&input_attrib, 0, sizeof(input_attrib));
14060 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014062 char const *vsSource = "#version 450\n"
14063 "\n"
14064 "layout(location=0) in int x;\n" /* attrib provided float */
14065 "out gl_PerVertex {\n"
14066 " vec4 gl_Position;\n"
14067 "};\n"
14068 "void main(){\n"
14069 " gl_Position = vec4(x);\n"
14070 "}\n";
14071 char const *fsSource = "#version 450\n"
14072 "\n"
14073 "layout(location=0) out vec4 color;\n"
14074 "void main(){\n"
14075 " color = vec4(1);\n"
14076 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014077
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014078 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14079 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014080
14081 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014082 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014083 pipe.AddShader(&vs);
14084 pipe.AddShader(&fs);
14085
14086 pipe.AddVertexInputBindings(&input_binding, 1);
14087 pipe.AddVertexInputAttribs(&input_attrib, 1);
14088
Chris Forbesc97d98e2015-05-25 11:13:31 +120014089 VkDescriptorSetObj descriptorSet(m_device);
14090 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014091 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014092
Tony Barbour5781e8f2015-08-04 16:23:11 -060014093 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014094
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014095 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014096}
14097
Chris Forbesc68b43c2016-04-06 11:18:47 +120014098TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014099 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
14100 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14102 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014103
14104 ASSERT_NO_FATAL_FAILURE(InitState());
14105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014107 char const *vsSource = "#version 450\n"
14108 "\n"
14109 "out gl_PerVertex {\n"
14110 " vec4 gl_Position;\n"
14111 "};\n"
14112 "void main(){\n"
14113 " gl_Position = vec4(1);\n"
14114 "}\n";
14115 char const *fsSource = "#version 450\n"
14116 "\n"
14117 "layout(location=0) out vec4 color;\n"
14118 "void main(){\n"
14119 " color = vec4(1);\n"
14120 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014121
14122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14124
14125 VkPipelineObj pipe(m_device);
14126 pipe.AddColorAttachment();
14127 pipe.AddShader(&vs);
14128 pipe.AddShader(&vs);
14129 pipe.AddShader(&fs);
14130
14131 VkDescriptorSetObj descriptorSet(m_device);
14132 descriptorSet.AppendDummy();
14133 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14134
14135 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14136
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014137 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014138}
14139
Karl Schultz6addd812016-02-02 17:17:23 -070014140TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014141 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
14142 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014143 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014144
14145 ASSERT_NO_FATAL_FAILURE(InitState());
14146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14147
14148 VkVertexInputBindingDescription input_binding;
14149 memset(&input_binding, 0, sizeof(input_binding));
14150
14151 VkVertexInputAttributeDescription input_attribs[2];
14152 memset(input_attribs, 0, sizeof(input_attribs));
14153
14154 for (int i = 0; i < 2; i++) {
14155 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14156 input_attribs[i].location = i;
14157 }
14158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159 char const *vsSource = "#version 450\n"
14160 "\n"
14161 "layout(location=0) in mat2x4 x;\n"
14162 "out gl_PerVertex {\n"
14163 " vec4 gl_Position;\n"
14164 "};\n"
14165 "void main(){\n"
14166 " gl_Position = x[0] + x[1];\n"
14167 "}\n";
14168 char const *fsSource = "#version 450\n"
14169 "\n"
14170 "layout(location=0) out vec4 color;\n"
14171 "void main(){\n"
14172 " color = vec4(1);\n"
14173 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014174
14175 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14176 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14177
14178 VkPipelineObj pipe(m_device);
14179 pipe.AddColorAttachment();
14180 pipe.AddShader(&vs);
14181 pipe.AddShader(&fs);
14182
14183 pipe.AddVertexInputBindings(&input_binding, 1);
14184 pipe.AddVertexInputAttribs(input_attribs, 2);
14185
14186 VkDescriptorSetObj descriptorSet(m_device);
14187 descriptorSet.AppendDummy();
14188 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14189
14190 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14191
14192 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014193 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014194}
14195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014196TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014197 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014198
14199 ASSERT_NO_FATAL_FAILURE(InitState());
14200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14201
14202 VkVertexInputBindingDescription input_binding;
14203 memset(&input_binding, 0, sizeof(input_binding));
14204
14205 VkVertexInputAttributeDescription input_attribs[2];
14206 memset(input_attribs, 0, sizeof(input_attribs));
14207
14208 for (int i = 0; i < 2; i++) {
14209 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14210 input_attribs[i].location = i;
14211 }
14212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014213 char const *vsSource = "#version 450\n"
14214 "\n"
14215 "layout(location=0) in vec4 x[2];\n"
14216 "out gl_PerVertex {\n"
14217 " vec4 gl_Position;\n"
14218 "};\n"
14219 "void main(){\n"
14220 " gl_Position = x[0] + x[1];\n"
14221 "}\n";
14222 char const *fsSource = "#version 450\n"
14223 "\n"
14224 "layout(location=0) out vec4 color;\n"
14225 "void main(){\n"
14226 " color = vec4(1);\n"
14227 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014228
14229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14230 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14231
14232 VkPipelineObj pipe(m_device);
14233 pipe.AddColorAttachment();
14234 pipe.AddShader(&vs);
14235 pipe.AddShader(&fs);
14236
14237 pipe.AddVertexInputBindings(&input_binding, 1);
14238 pipe.AddVertexInputAttribs(input_attribs, 2);
14239
14240 VkDescriptorSetObj descriptorSet(m_device);
14241 descriptorSet.AppendDummy();
14242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14243
14244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014246 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014247}
Chris Forbes2682b242015-11-24 11:13:14 +130014248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014249TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014250 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14251 "through multiple VS inputs, each consuming a different subset of the "
14252 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014253 m_errorMonitor->ExpectSuccess();
14254
14255 ASSERT_NO_FATAL_FAILURE(InitState());
14256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14257
14258 VkVertexInputBindingDescription input_binding;
14259 memset(&input_binding, 0, sizeof(input_binding));
14260
14261 VkVertexInputAttributeDescription input_attribs[3];
14262 memset(input_attribs, 0, sizeof(input_attribs));
14263
14264 for (int i = 0; i < 3; i++) {
14265 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14266 input_attribs[i].location = i;
14267 }
14268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014269 char const *vsSource = "#version 450\n"
14270 "\n"
14271 "layout(location=0) in vec4 x;\n"
14272 "layout(location=1) in vec3 y1;\n"
14273 "layout(location=1, component=3) in float y2;\n"
14274 "layout(location=2) in vec4 z;\n"
14275 "out gl_PerVertex {\n"
14276 " vec4 gl_Position;\n"
14277 "};\n"
14278 "void main(){\n"
14279 " gl_Position = x + vec4(y1, y2) + z;\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 Forbesbc290ce2016-07-06 12:01:49 +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(&fs);
14295
14296 pipe.AddVertexInputBindings(&input_binding, 1);
14297 pipe.AddVertexInputAttribs(input_attribs, 3);
14298
14299 VkDescriptorSetObj descriptorSet(m_device);
14300 descriptorSet.AppendDummy();
14301 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14302
14303 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14304
14305 m_errorMonitor->VerifyNotFound();
14306}
14307
Chris Forbes82ff92a2016-09-09 10:50:24 +120014308TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14310 "No entrypoint found named `foo`");
14311
14312 ASSERT_NO_FATAL_FAILURE(InitState());
14313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14314
14315 char const *vsSource = "#version 450\n"
14316 "out gl_PerVertex {\n"
14317 " vec4 gl_Position;\n"
14318 "};\n"
14319 "void main(){\n"
14320 " gl_Position = vec4(0);\n"
14321 "}\n";
14322 char const *fsSource = "#version 450\n"
14323 "\n"
14324 "layout(location=0) out vec4 color;\n"
14325 "void main(){\n"
14326 " color = vec4(1);\n"
14327 "}\n";
14328
14329 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14330 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14331
14332 VkPipelineObj pipe(m_device);
14333 pipe.AddColorAttachment();
14334 pipe.AddShader(&vs);
14335 pipe.AddShader(&fs);
14336
14337 VkDescriptorSetObj descriptorSet(m_device);
14338 descriptorSet.AppendDummy();
14339 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14340
14341 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14342
14343 m_errorMonitor->VerifyFound();
14344}
14345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014346TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014347 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014348
14349 ASSERT_NO_FATAL_FAILURE(InitState());
14350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014352 char const *vsSource = "#version 450\n"
14353 "out gl_PerVertex {\n"
14354 " vec4 gl_Position;\n"
14355 "};\n"
14356 "void main(){\n"
14357 " gl_Position = vec4(0);\n"
14358 "}\n";
14359 char const *fsSource = "#version 450\n"
14360 "\n"
14361 "layout(location=0) out vec4 color;\n"
14362 "void main(){\n"
14363 " color = vec4(1);\n"
14364 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014365
14366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14368
14369 VkPipelineObj pipe(m_device);
14370 pipe.AddColorAttachment();
14371 pipe.AddShader(&vs);
14372 pipe.AddShader(&fs);
14373
14374 VkDescriptorSetObj descriptorSet(m_device);
14375 descriptorSet.AppendDummy();
14376 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14377
14378 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014380 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014381}
14382
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014383TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14384 m_errorMonitor->SetDesiredFailureMsg(
14385 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14386 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14387 "uses a depth/stencil attachment");
14388
14389 ASSERT_NO_FATAL_FAILURE(InitState());
14390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14391
14392 char const *vsSource = "#version 450\n"
14393 "void main(){ gl_Position = vec4(0); }\n";
14394 char const *fsSource = "#version 450\n"
14395 "\n"
14396 "layout(location=0) out vec4 color;\n"
14397 "void main(){\n"
14398 " color = vec4(1);\n"
14399 "}\n";
14400
14401 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14402 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14403
14404 VkPipelineObj pipe(m_device);
14405 pipe.AddColorAttachment();
14406 pipe.AddShader(&vs);
14407 pipe.AddShader(&fs);
14408
14409 VkDescriptorSetObj descriptorSet(m_device);
14410 descriptorSet.AppendDummy();
14411 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14412
14413 VkAttachmentDescription attachments[] = {
14414 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14415 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14416 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14417 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14418 },
14419 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14420 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14421 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14422 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14423 },
14424 };
14425 VkAttachmentReference refs[] = {
14426 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14427 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14428 };
14429 VkSubpassDescription subpass = {
14430 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14431 1, &refs[0], nullptr, &refs[1],
14432 0, nullptr
14433 };
14434 VkRenderPassCreateInfo rpci = {
14435 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14436 0, 2, attachments, 1, &subpass, 0, nullptr
14437 };
14438 VkRenderPass rp;
14439 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14440 ASSERT_VK_SUCCESS(err);
14441
14442 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14443
14444 m_errorMonitor->VerifyFound();
14445
14446 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14447}
14448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014449TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014450 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14451 "set out in 14.1.3: fundamental type must match, and producer side must "
14452 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014453 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014454
14455 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14456
14457 ASSERT_NO_FATAL_FAILURE(InitState());
14458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014460 char const *vsSource = "#version 450\n"
14461 "out gl_PerVertex {\n"
14462 " vec4 gl_Position;\n"
14463 "};\n"
14464 "layout(location=0) out vec3 x;\n"
14465 "layout(location=1) out ivec3 y;\n"
14466 "layout(location=2) out vec3 z;\n"
14467 "void main(){\n"
14468 " gl_Position = vec4(0);\n"
14469 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14470 "}\n";
14471 char const *fsSource = "#version 450\n"
14472 "\n"
14473 "layout(location=0) out vec4 color;\n"
14474 "layout(location=0) in float x;\n"
14475 "layout(location=1) flat in int y;\n"
14476 "layout(location=2) in vec2 z;\n"
14477 "void main(){\n"
14478 " color = vec4(1 + x + y + z.x);\n"
14479 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014480
14481 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14482 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14483
14484 VkPipelineObj pipe(m_device);
14485 pipe.AddColorAttachment();
14486 pipe.AddShader(&vs);
14487 pipe.AddShader(&fs);
14488
14489 VkDescriptorSetObj descriptorSet(m_device);
14490 descriptorSet.AppendDummy();
14491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14492
Mike Stroyan255e9582016-06-24 09:49:32 -060014493 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014494 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014495 ASSERT_VK_SUCCESS(err);
14496
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014497 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014498}
14499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014500TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014501 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14502 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014503 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014504
14505 ASSERT_NO_FATAL_FAILURE(InitState());
14506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14507
Chris Forbesc1e852d2016-04-04 19:26:42 +120014508 if (!m_device->phy().features().tessellationShader) {
14509 printf("Device does not support tessellation shaders; skipped.\n");
14510 return;
14511 }
14512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014513 char const *vsSource = "#version 450\n"
14514 "void main(){}\n";
14515 char const *tcsSource = "#version 450\n"
14516 "layout(location=0) out int x[];\n"
14517 "layout(vertices=3) out;\n"
14518 "void main(){\n"
14519 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14520 " gl_TessLevelInner[0] = 1;\n"
14521 " x[gl_InvocationID] = gl_InvocationID;\n"
14522 "}\n";
14523 char const *tesSource = "#version 450\n"
14524 "layout(triangles, equal_spacing, cw) in;\n"
14525 "layout(location=0) in int x[];\n"
14526 "out gl_PerVertex { vec4 gl_Position; };\n"
14527 "void main(){\n"
14528 " gl_Position.xyz = gl_TessCoord;\n"
14529 " gl_Position.w = x[0] + x[1] + x[2];\n"
14530 "}\n";
14531 char const *fsSource = "#version 450\n"
14532 "layout(location=0) out vec4 color;\n"
14533 "void main(){\n"
14534 " color = vec4(1);\n"
14535 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014536
14537 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14538 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14539 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014542 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14543 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014545 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014546
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014547 VkPipelineObj pipe(m_device);
14548 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014549 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014550 pipe.AddColorAttachment();
14551 pipe.AddShader(&vs);
14552 pipe.AddShader(&tcs);
14553 pipe.AddShader(&tes);
14554 pipe.AddShader(&fs);
14555
14556 VkDescriptorSetObj descriptorSet(m_device);
14557 descriptorSet.AppendDummy();
14558 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14559
14560 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14561
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014562 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014563}
14564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014565TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014566 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14567 "interface block passed into the geometry shader. This "
14568 "is interesting because the 'extra' array level is not "
14569 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014570 m_errorMonitor->ExpectSuccess();
14571
14572 ASSERT_NO_FATAL_FAILURE(InitState());
14573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14574
14575 if (!m_device->phy().features().geometryShader) {
14576 printf("Device does not support geometry shaders; skipped.\n");
14577 return;
14578 }
14579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014580 char const *vsSource = "#version 450\n"
14581 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14582 "void main(){\n"
14583 " vs_out.x = vec4(1);\n"
14584 "}\n";
14585 char const *gsSource = "#version 450\n"
14586 "layout(triangles) in;\n"
14587 "layout(triangle_strip, max_vertices=3) out;\n"
14588 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14589 "out gl_PerVertex { vec4 gl_Position; };\n"
14590 "void main() {\n"
14591 " gl_Position = gs_in[0].x;\n"
14592 " EmitVertex();\n"
14593 "}\n";
14594 char const *fsSource = "#version 450\n"
14595 "layout(location=0) out vec4 color;\n"
14596 "void main(){\n"
14597 " color = vec4(1);\n"
14598 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014599
14600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14601 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14602 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14603
14604 VkPipelineObj pipe(m_device);
14605 pipe.AddColorAttachment();
14606 pipe.AddShader(&vs);
14607 pipe.AddShader(&gs);
14608 pipe.AddShader(&fs);
14609
14610 VkDescriptorSetObj descriptorSet(m_device);
14611 descriptorSet.AppendDummy();
14612 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14613
14614 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14615
14616 m_errorMonitor->VerifyNotFound();
14617}
14618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014619TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014620 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14621 "the TCS without the patch decoration, but consumed in the TES "
14622 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14624 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014625
14626 ASSERT_NO_FATAL_FAILURE(InitState());
14627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14628
Chris Forbesc1e852d2016-04-04 19:26:42 +120014629 if (!m_device->phy().features().tessellationShader) {
14630 printf("Device does not support tessellation shaders; skipped.\n");
14631 return;
14632 }
14633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 char const *vsSource = "#version 450\n"
14635 "void main(){}\n";
14636 char const *tcsSource = "#version 450\n"
14637 "layout(location=0) out int x[];\n"
14638 "layout(vertices=3) out;\n"
14639 "void main(){\n"
14640 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14641 " gl_TessLevelInner[0] = 1;\n"
14642 " x[gl_InvocationID] = gl_InvocationID;\n"
14643 "}\n";
14644 char const *tesSource = "#version 450\n"
14645 "layout(triangles, equal_spacing, cw) in;\n"
14646 "layout(location=0) patch in int x;\n"
14647 "out gl_PerVertex { vec4 gl_Position; };\n"
14648 "void main(){\n"
14649 " gl_Position.xyz = gl_TessCoord;\n"
14650 " gl_Position.w = x;\n"
14651 "}\n";
14652 char const *fsSource = "#version 450\n"
14653 "layout(location=0) out vec4 color;\n"
14654 "void main(){\n"
14655 " color = vec4(1);\n"
14656 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014657
14658 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14659 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14660 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14661 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014663 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14664 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014666 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014667
14668 VkPipelineObj pipe(m_device);
14669 pipe.SetInputAssembly(&iasci);
14670 pipe.SetTessellation(&tsci);
14671 pipe.AddColorAttachment();
14672 pipe.AddShader(&vs);
14673 pipe.AddShader(&tcs);
14674 pipe.AddShader(&tes);
14675 pipe.AddShader(&fs);
14676
14677 VkDescriptorSetObj descriptorSet(m_device);
14678 descriptorSet.AppendDummy();
14679 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14680
14681 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14682
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014683 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014684}
14685
Karl Schultz6addd812016-02-02 17:17:23 -070014686TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014687 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14688 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14690 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014691
Chris Forbes280ba2c2015-06-12 11:16:41 +120014692 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014694
14695 /* Two binding descriptions for binding 0 */
14696 VkVertexInputBindingDescription input_bindings[2];
14697 memset(input_bindings, 0, sizeof(input_bindings));
14698
14699 VkVertexInputAttributeDescription input_attrib;
14700 memset(&input_attrib, 0, sizeof(input_attrib));
14701 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014703 char const *vsSource = "#version 450\n"
14704 "\n"
14705 "layout(location=0) in float x;\n" /* attrib provided float */
14706 "out gl_PerVertex {\n"
14707 " vec4 gl_Position;\n"
14708 "};\n"
14709 "void main(){\n"
14710 " gl_Position = vec4(x);\n"
14711 "}\n";
14712 char const *fsSource = "#version 450\n"
14713 "\n"
14714 "layout(location=0) out vec4 color;\n"
14715 "void main(){\n"
14716 " color = vec4(1);\n"
14717 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014718
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014719 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14720 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014721
14722 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014723 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014724 pipe.AddShader(&vs);
14725 pipe.AddShader(&fs);
14726
14727 pipe.AddVertexInputBindings(input_bindings, 2);
14728 pipe.AddVertexInputAttribs(&input_attrib, 1);
14729
Chris Forbes280ba2c2015-06-12 11:16:41 +120014730 VkDescriptorSetObj descriptorSet(m_device);
14731 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014732 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014733
Tony Barbour5781e8f2015-08-04 16:23:11 -060014734 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014736 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014737}
Chris Forbes8f68b562015-05-25 11:13:32 +120014738
Chris Forbes35efec72016-04-21 14:32:08 +120014739TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014740 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14741 "attributes. This is interesting because they consume multiple "
14742 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014743 m_errorMonitor->ExpectSuccess();
14744
14745 ASSERT_NO_FATAL_FAILURE(InitState());
14746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14747
Chris Forbes91cf3a82016-06-28 17:51:35 +120014748 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014749 printf("Device does not support 64bit vertex attributes; skipped.\n");
14750 return;
14751 }
14752
14753 VkVertexInputBindingDescription input_bindings[1];
14754 memset(input_bindings, 0, sizeof(input_bindings));
14755
14756 VkVertexInputAttributeDescription input_attribs[4];
14757 memset(input_attribs, 0, sizeof(input_attribs));
14758 input_attribs[0].location = 0;
14759 input_attribs[0].offset = 0;
14760 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14761 input_attribs[1].location = 2;
14762 input_attribs[1].offset = 32;
14763 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14764 input_attribs[2].location = 4;
14765 input_attribs[2].offset = 64;
14766 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14767 input_attribs[3].location = 6;
14768 input_attribs[3].offset = 96;
14769 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014771 char const *vsSource = "#version 450\n"
14772 "\n"
14773 "layout(location=0) in dmat4 x;\n"
14774 "out gl_PerVertex {\n"
14775 " vec4 gl_Position;\n"
14776 "};\n"
14777 "void main(){\n"
14778 " gl_Position = vec4(x[0][0]);\n"
14779 "}\n";
14780 char const *fsSource = "#version 450\n"
14781 "\n"
14782 "layout(location=0) out vec4 color;\n"
14783 "void main(){\n"
14784 " color = vec4(1);\n"
14785 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014786
14787 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14788 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14789
14790 VkPipelineObj pipe(m_device);
14791 pipe.AddColorAttachment();
14792 pipe.AddShader(&vs);
14793 pipe.AddShader(&fs);
14794
14795 pipe.AddVertexInputBindings(input_bindings, 1);
14796 pipe.AddVertexInputAttribs(input_attribs, 4);
14797
14798 VkDescriptorSetObj descriptorSet(m_device);
14799 descriptorSet.AppendDummy();
14800 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14801
14802 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14803
14804 m_errorMonitor->VerifyNotFound();
14805}
14806
Karl Schultz6addd812016-02-02 17:17:23 -070014807TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014808 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14809 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014811
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014812 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014814 char const *vsSource = "#version 450\n"
14815 "\n"
14816 "out gl_PerVertex {\n"
14817 " vec4 gl_Position;\n"
14818 "};\n"
14819 "void main(){\n"
14820 " gl_Position = vec4(1);\n"
14821 "}\n";
14822 char const *fsSource = "#version 450\n"
14823 "\n"
14824 "void main(){\n"
14825 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014826
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014827 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14828 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014829
14830 VkPipelineObj pipe(m_device);
14831 pipe.AddShader(&vs);
14832 pipe.AddShader(&fs);
14833
Chia-I Wu08accc62015-07-07 11:50:03 +080014834 /* set up CB 0, not written */
14835 pipe.AddColorAttachment();
14836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014837
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014838 VkDescriptorSetObj descriptorSet(m_device);
14839 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014841
Tony Barbour5781e8f2015-08-04 16:23:11 -060014842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014844 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014845}
14846
Karl Schultz6addd812016-02-02 17:17:23 -070014847TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014848 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
14849 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
14851 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014852
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014853 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014855 char const *vsSource = "#version 450\n"
14856 "\n"
14857 "out gl_PerVertex {\n"
14858 " vec4 gl_Position;\n"
14859 "};\n"
14860 "void main(){\n"
14861 " gl_Position = vec4(1);\n"
14862 "}\n";
14863 char const *fsSource = "#version 450\n"
14864 "\n"
14865 "layout(location=0) out vec4 x;\n"
14866 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14867 "void main(){\n"
14868 " x = vec4(1);\n"
14869 " y = vec4(1);\n"
14870 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014871
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014874
14875 VkPipelineObj pipe(m_device);
14876 pipe.AddShader(&vs);
14877 pipe.AddShader(&fs);
14878
Chia-I Wu08accc62015-07-07 11:50:03 +080014879 /* set up CB 0, not written */
14880 pipe.AddColorAttachment();
14881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014882 /* FS writes CB 1, but we don't configure it */
14883
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014884 VkDescriptorSetObj descriptorSet(m_device);
14885 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014887
Tony Barbour5781e8f2015-08-04 16:23:11 -060014888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014889
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014890 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014891}
14892
Karl Schultz6addd812016-02-02 17:17:23 -070014893TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014894 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
14895 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014897
Chris Forbesa36d69e2015-05-25 11:13:44 +120014898 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014900 char const *vsSource = "#version 450\n"
14901 "\n"
14902 "out gl_PerVertex {\n"
14903 " vec4 gl_Position;\n"
14904 "};\n"
14905 "void main(){\n"
14906 " gl_Position = vec4(1);\n"
14907 "}\n";
14908 char const *fsSource = "#version 450\n"
14909 "\n"
14910 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14911 "void main(){\n"
14912 " x = ivec4(1);\n"
14913 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014914
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014915 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14916 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014917
14918 VkPipelineObj pipe(m_device);
14919 pipe.AddShader(&vs);
14920 pipe.AddShader(&fs);
14921
Chia-I Wu08accc62015-07-07 11:50:03 +080014922 /* set up CB 0; type is UNORM by default */
14923 pipe.AddColorAttachment();
14924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014925
Chris Forbesa36d69e2015-05-25 11:13:44 +120014926 VkDescriptorSetObj descriptorSet(m_device);
14927 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014928 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014929
Tony Barbour5781e8f2015-08-04 16:23:11 -060014930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014931
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014932 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014933}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014934
Karl Schultz6addd812016-02-02 17:17:23 -070014935TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014936 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
14937 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014939
Chris Forbes556c76c2015-08-14 12:04:59 +120014940 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 char const *vsSource = "#version 450\n"
14943 "\n"
14944 "out gl_PerVertex {\n"
14945 " vec4 gl_Position;\n"
14946 "};\n"
14947 "void main(){\n"
14948 " gl_Position = vec4(1);\n"
14949 "}\n";
14950 char const *fsSource = "#version 450\n"
14951 "\n"
14952 "layout(location=0) out vec4 x;\n"
14953 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14954 "void main(){\n"
14955 " x = vec4(bar.y);\n"
14956 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014957
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014958 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14959 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014960
Chris Forbes556c76c2015-08-14 12:04:59 +120014961 VkPipelineObj pipe(m_device);
14962 pipe.AddShader(&vs);
14963 pipe.AddShader(&fs);
14964
14965 /* set up CB 0; type is UNORM by default */
14966 pipe.AddColorAttachment();
14967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14968
14969 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014970 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014971
14972 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14973
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014974 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014975}
14976
Chris Forbes5c59e902016-02-26 16:56:09 +130014977TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014978 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
14979 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014981
14982 ASSERT_NO_FATAL_FAILURE(InitState());
14983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 char const *vsSource = "#version 450\n"
14985 "\n"
14986 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14987 "out gl_PerVertex {\n"
14988 " vec4 gl_Position;\n"
14989 "};\n"
14990 "void main(){\n"
14991 " gl_Position = vec4(consts.x);\n"
14992 "}\n";
14993 char const *fsSource = "#version 450\n"
14994 "\n"
14995 "layout(location=0) out vec4 x;\n"
14996 "void main(){\n"
14997 " x = vec4(1);\n"
14998 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014999
15000 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15001 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15002
15003 VkPipelineObj pipe(m_device);
15004 pipe.AddShader(&vs);
15005 pipe.AddShader(&fs);
15006
15007 /* set up CB 0; type is UNORM by default */
15008 pipe.AddColorAttachment();
15009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15010
15011 VkDescriptorSetObj descriptorSet(m_device);
15012 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15013
15014 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15015
15016 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015017 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015018}
15019
Chris Forbes3fb17902016-08-22 14:57:55 +120015020TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
15021 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15022 "which is not included in the subpass description");
15023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15024 "consumes input attachment index 0 but not provided in subpass");
15025
15026 ASSERT_NO_FATAL_FAILURE(InitState());
15027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015028 char const *vsSource = "#version 450\n"
15029 "\n"
15030 "out gl_PerVertex {\n"
15031 " vec4 gl_Position;\n"
15032 "};\n"
15033 "void main(){\n"
15034 " gl_Position = vec4(1);\n"
15035 "}\n";
15036 char const *fsSource = "#version 450\n"
15037 "\n"
15038 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15039 "layout(location=0) out vec4 color;\n"
15040 "void main() {\n"
15041 " color = subpassLoad(x);\n"
15042 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015043
15044 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15045 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15046
15047 VkPipelineObj pipe(m_device);
15048 pipe.AddShader(&vs);
15049 pipe.AddShader(&fs);
15050 pipe.AddColorAttachment();
15051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15054 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015055 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015056 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015057 ASSERT_VK_SUCCESS(err);
15058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015059 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015060 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015061 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015062 ASSERT_VK_SUCCESS(err);
15063
15064 // error here.
15065 pipe.CreateVKPipeline(pl, renderPass());
15066
15067 m_errorMonitor->VerifyFound();
15068
15069 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15070 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15071}
15072
Chris Forbes663b5a82016-08-22 16:14:06 +120015073TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
15074 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
15075 m_errorMonitor->ExpectSuccess();
15076
15077 ASSERT_NO_FATAL_FAILURE(InitState());
15078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015079 char const *vsSource = "#version 450\n"
15080 "\n"
15081 "out gl_PerVertex {\n"
15082 " vec4 gl_Position;\n"
15083 "};\n"
15084 "void main(){\n"
15085 " gl_Position = vec4(1);\n"
15086 "}\n";
15087 char const *fsSource = "#version 450\n"
15088 "\n"
15089 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15090 "layout(location=0) out vec4 color;\n"
15091 "void main() {\n"
15092 " color = subpassLoad(x);\n"
15093 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120015094
15095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15097
15098 VkPipelineObj pipe(m_device);
15099 pipe.AddShader(&vs);
15100 pipe.AddShader(&fs);
15101 pipe.AddColorAttachment();
15102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15105 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120015106 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015107 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015108 ASSERT_VK_SUCCESS(err);
15109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015110 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015111 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015113 ASSERT_VK_SUCCESS(err);
15114
15115 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15117 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15118 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15119 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15120 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 +120015121 };
15122 VkAttachmentReference color = {
15123 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15124 };
15125 VkAttachmentReference input = {
15126 1, VK_IMAGE_LAYOUT_GENERAL,
15127 };
15128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015132 VkRenderPass rp;
15133 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15134 ASSERT_VK_SUCCESS(err);
15135
15136 // should be OK. would go wrong here if it's going to...
15137 pipe.CreateVKPipeline(pl, rp);
15138
15139 m_errorMonitor->VerifyNotFound();
15140
15141 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15142 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15143 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15144}
15145
Chris Forbes5a9a0472016-08-22 16:02:09 +120015146TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
15147 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15148 "with a format having a different fundamental type");
15149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15150 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15151
15152 ASSERT_NO_FATAL_FAILURE(InitState());
15153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015154 char const *vsSource = "#version 450\n"
15155 "\n"
15156 "out gl_PerVertex {\n"
15157 " vec4 gl_Position;\n"
15158 "};\n"
15159 "void main(){\n"
15160 " gl_Position = vec4(1);\n"
15161 "}\n";
15162 char const *fsSource = "#version 450\n"
15163 "\n"
15164 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15165 "layout(location=0) out vec4 color;\n"
15166 "void main() {\n"
15167 " color = subpassLoad(x);\n"
15168 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015169
15170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15172
15173 VkPipelineObj pipe(m_device);
15174 pipe.AddShader(&vs);
15175 pipe.AddShader(&fs);
15176 pipe.AddColorAttachment();
15177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15180 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015181 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015183 ASSERT_VK_SUCCESS(err);
15184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015186 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015188 ASSERT_VK_SUCCESS(err);
15189
15190 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015191 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15192 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15193 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15194 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15195 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 +120015196 };
15197 VkAttachmentReference color = {
15198 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15199 };
15200 VkAttachmentReference input = {
15201 1, VK_IMAGE_LAYOUT_GENERAL,
15202 };
15203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015204 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015207 VkRenderPass rp;
15208 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15209 ASSERT_VK_SUCCESS(err);
15210
15211 // error here.
15212 pipe.CreateVKPipeline(pl, rp);
15213
15214 m_errorMonitor->VerifyFound();
15215
15216 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15217 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15218 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15219}
15220
Chris Forbes541f7b02016-08-22 15:30:27 +120015221TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
15222 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15223 "which is not included in the subpass description -- array case");
15224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15225 "consumes input attachment index 1 but not provided in subpass");
15226
15227 ASSERT_NO_FATAL_FAILURE(InitState());
15228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015229 char const *vsSource = "#version 450\n"
15230 "\n"
15231 "out gl_PerVertex {\n"
15232 " vec4 gl_Position;\n"
15233 "};\n"
15234 "void main(){\n"
15235 " gl_Position = vec4(1);\n"
15236 "}\n";
15237 char const *fsSource = "#version 450\n"
15238 "\n"
15239 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15240 "layout(location=0) out vec4 color;\n"
15241 "void main() {\n"
15242 " color = subpassLoad(xs[1]);\n"
15243 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015244
15245 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15246 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15247
15248 VkPipelineObj pipe(m_device);
15249 pipe.AddShader(&vs);
15250 pipe.AddShader(&fs);
15251 pipe.AddColorAttachment();
15252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015254 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15255 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015256 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015257 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015258 ASSERT_VK_SUCCESS(err);
15259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015261 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015262 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015263 ASSERT_VK_SUCCESS(err);
15264
15265 // error here.
15266 pipe.CreateVKPipeline(pl, renderPass());
15267
15268 m_errorMonitor->VerifyFound();
15269
15270 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15271 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15272}
15273
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015274TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015275 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15276 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015278
15279 ASSERT_NO_FATAL_FAILURE(InitState());
15280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 char const *csSource = "#version 450\n"
15282 "\n"
15283 "layout(local_size_x=1) in;\n"
15284 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15285 "void main(){\n"
15286 " x = vec4(1);\n"
15287 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015288
15289 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15290
15291 VkDescriptorSetObj descriptorSet(m_device);
15292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015294 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15295 nullptr,
15296 0,
15297 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15298 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15299 descriptorSet.GetPipelineLayout(),
15300 VK_NULL_HANDLE,
15301 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015302
15303 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015304 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015305
15306 m_errorMonitor->VerifyFound();
15307
15308 if (err == VK_SUCCESS) {
15309 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15310 }
15311}
15312
15313TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015314 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15315 "descriptor-backed resource which is not provided, but the shader does not "
15316 "statically use it. This is interesting because it requires compute pipelines "
15317 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015318 m_errorMonitor->ExpectSuccess();
15319
15320 ASSERT_NO_FATAL_FAILURE(InitState());
15321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015322 char const *csSource = "#version 450\n"
15323 "\n"
15324 "layout(local_size_x=1) in;\n"
15325 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15326 "void main(){\n"
15327 " // x is not used.\n"
15328 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015329
15330 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15331
15332 VkDescriptorSetObj descriptorSet(m_device);
15333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015335 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15336 nullptr,
15337 0,
15338 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15339 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15340 descriptorSet.GetPipelineLayout(),
15341 VK_NULL_HANDLE,
15342 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015343
15344 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015345 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015346
15347 m_errorMonitor->VerifyNotFound();
15348
15349 if (err == VK_SUCCESS) {
15350 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15351 }
15352}
15353
Chris Forbes22a9b092016-07-19 14:34:05 +120015354TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015355 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15356 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15358 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015359
15360 ASSERT_NO_FATAL_FAILURE(InitState());
15361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015362 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15363 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015364 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015365 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015366 ASSERT_VK_SUCCESS(err);
15367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015368 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015369 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015371 ASSERT_VK_SUCCESS(err);
15372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015373 char const *csSource = "#version 450\n"
15374 "\n"
15375 "layout(local_size_x=1) in;\n"
15376 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15377 "void main() {\n"
15378 " x.x = 1.0f;\n"
15379 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015380 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015382 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15383 nullptr,
15384 0,
15385 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15386 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15387 pl,
15388 VK_NULL_HANDLE,
15389 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015390
15391 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015393
15394 m_errorMonitor->VerifyFound();
15395
15396 if (err == VK_SUCCESS) {
15397 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15398 }
15399
15400 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15401 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15402}
15403
Chris Forbese10a51f2016-07-19 14:42:51 +120015404TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015405 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15406 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015407 m_errorMonitor->ExpectSuccess();
15408
15409 ASSERT_NO_FATAL_FAILURE(InitState());
15410
15411 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015412 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15413 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15414 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015415 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015416 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015417 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015418 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015419 ASSERT_VK_SUCCESS(err);
15420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015421 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015422 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015423 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015424 ASSERT_VK_SUCCESS(err);
15425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015426 char const *csSource = "#version 450\n"
15427 "\n"
15428 "layout(local_size_x=1) in;\n"
15429 "layout(set=0, binding=0) uniform sampler s;\n"
15430 "layout(set=0, binding=1) uniform texture2D t;\n"
15431 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15432 "void main() {\n"
15433 " x = texture(sampler2D(t, s), vec2(0));\n"
15434 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015435 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015437 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15438 nullptr,
15439 0,
15440 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15441 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15442 pl,
15443 VK_NULL_HANDLE,
15444 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015445
15446 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015447 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015448
15449 m_errorMonitor->VerifyNotFound();
15450
15451 if (err == VK_SUCCESS) {
15452 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15453 }
15454
15455 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15456 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15457}
15458
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015459TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015460 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15461 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015462 m_errorMonitor->ExpectSuccess();
15463
15464 ASSERT_NO_FATAL_FAILURE(InitState());
15465
15466 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015467 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15468 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15469 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015470 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015471 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015472 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015473 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015474 ASSERT_VK_SUCCESS(err);
15475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015476 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015477 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015478 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015479 ASSERT_VK_SUCCESS(err);
15480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015481 char const *csSource = "#version 450\n"
15482 "\n"
15483 "layout(local_size_x=1) in;\n"
15484 "layout(set=0, binding=0) uniform texture2D t;\n"
15485 "layout(set=0, binding=1) uniform sampler s;\n"
15486 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15487 "void main() {\n"
15488 " x = texture(sampler2D(t, s), vec2(0));\n"
15489 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015490 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015492 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15493 nullptr,
15494 0,
15495 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15496 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15497 pl,
15498 VK_NULL_HANDLE,
15499 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015500
15501 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015502 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015503
15504 m_errorMonitor->VerifyNotFound();
15505
15506 if (err == VK_SUCCESS) {
15507 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15508 }
15509
15510 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15511 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15512}
15513
Chris Forbes6a4991a2016-07-19 15:07:32 +120015514TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015515 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15516 "both the sampler and the image of a combined image+sampler "
15517 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015518 m_errorMonitor->ExpectSuccess();
15519
15520 ASSERT_NO_FATAL_FAILURE(InitState());
15521
15522 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015523 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15524 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015525 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015526 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015527 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015528 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015529 ASSERT_VK_SUCCESS(err);
15530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015531 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015532 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015533 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015534 ASSERT_VK_SUCCESS(err);
15535
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015536 char const *csSource = "#version 450\n"
15537 "\n"
15538 "layout(local_size_x=1) in;\n"
15539 "layout(set=0, binding=0) uniform texture2D t;\n"
15540 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15541 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15542 "void main() {\n"
15543 " x = texture(sampler2D(t, s), vec2(0));\n"
15544 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015545 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015547 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15548 nullptr,
15549 0,
15550 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15551 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15552 pl,
15553 VK_NULL_HANDLE,
15554 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015555
15556 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015557 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015558
15559 m_errorMonitor->VerifyNotFound();
15560
15561 if (err == VK_SUCCESS) {
15562 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15563 }
15564
15565 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15566 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15567}
15568
Chris Forbes50020592016-07-27 13:52:41 +120015569TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15570 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15571 "does not match the dimensionality declared in the shader");
15572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015573 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 +120015574
15575 ASSERT_NO_FATAL_FAILURE(InitState());
15576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015578 char const *vsSource = "#version 450\n"
15579 "\n"
15580 "out gl_PerVertex { vec4 gl_Position; };\n"
15581 "void main() { gl_Position = vec4(0); }\n";
15582 char const *fsSource = "#version 450\n"
15583 "\n"
15584 "layout(set=0, binding=0) uniform sampler3D s;\n"
15585 "layout(location=0) out vec4 color;\n"
15586 "void main() {\n"
15587 " color = texture(s, vec3(0));\n"
15588 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015589 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15590 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15591
15592 VkPipelineObj pipe(m_device);
15593 pipe.AddShader(&vs);
15594 pipe.AddShader(&fs);
15595 pipe.AddColorAttachment();
15596
15597 VkTextureObj texture(m_device, nullptr);
15598 VkSamplerObj sampler(m_device);
15599
15600 VkDescriptorSetObj descriptorSet(m_device);
15601 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15602 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15603
15604 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15605 ASSERT_VK_SUCCESS(err);
15606
15607 BeginCommandBuffer();
15608
15609 m_commandBuffer->BindPipeline(pipe);
15610 m_commandBuffer->BindDescriptorSet(descriptorSet);
15611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015613 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015614 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015615 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15616
15617 // error produced here.
15618 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15619
15620 m_errorMonitor->VerifyFound();
15621
15622 EndCommandBuffer();
15623}
15624
Chris Forbes5533bfc2016-07-27 14:12:34 +120015625TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15626 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15627 "are consumed via singlesample images types in the shader, or vice versa.");
15628
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015630
15631 ASSERT_NO_FATAL_FAILURE(InitState());
15632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015634 char const *vsSource = "#version 450\n"
15635 "\n"
15636 "out gl_PerVertex { vec4 gl_Position; };\n"
15637 "void main() { gl_Position = vec4(0); }\n";
15638 char const *fsSource = "#version 450\n"
15639 "\n"
15640 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15641 "layout(location=0) out vec4 color;\n"
15642 "void main() {\n"
15643 " color = texelFetch(s, ivec2(0), 0);\n"
15644 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015645 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15646 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15647
15648 VkPipelineObj pipe(m_device);
15649 pipe.AddShader(&vs);
15650 pipe.AddShader(&fs);
15651 pipe.AddColorAttachment();
15652
15653 VkTextureObj texture(m_device, nullptr);
15654 VkSamplerObj sampler(m_device);
15655
15656 VkDescriptorSetObj descriptorSet(m_device);
15657 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15658 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15659
15660 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15661 ASSERT_VK_SUCCESS(err);
15662
15663 BeginCommandBuffer();
15664
15665 m_commandBuffer->BindPipeline(pipe);
15666 m_commandBuffer->BindDescriptorSet(descriptorSet);
15667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015668 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015669 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015670 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015671 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15672
15673 // error produced here.
15674 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15675
15676 m_errorMonitor->VerifyFound();
15677
15678 EndCommandBuffer();
15679}
15680
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015681#endif // SHADER_CHECKER_TESTS
15682
15683#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015684TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015686
15687 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015688
15689 // Create an image
15690 VkImage image;
15691
Karl Schultz6addd812016-02-02 17:17:23 -070015692 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15693 const int32_t tex_width = 32;
15694 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015695
15696 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015697 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15698 image_create_info.pNext = NULL;
15699 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15700 image_create_info.format = tex_format;
15701 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015702 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015703 image_create_info.extent.depth = 1;
15704 image_create_info.mipLevels = 1;
15705 image_create_info.arrayLayers = 1;
15706 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15707 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15708 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15709 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015710
15711 // Introduce error by sending down a bogus width extent
15712 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015713 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015714
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015715 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015716}
15717
Mark Youngc48c4c12016-04-11 14:26:49 -060015718TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15720 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015721
15722 ASSERT_NO_FATAL_FAILURE(InitState());
15723
15724 // Create an image
15725 VkImage image;
15726
15727 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15728 const int32_t tex_width = 32;
15729 const int32_t tex_height = 32;
15730
15731 VkImageCreateInfo image_create_info = {};
15732 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15733 image_create_info.pNext = NULL;
15734 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15735 image_create_info.format = tex_format;
15736 image_create_info.extent.width = tex_width;
15737 image_create_info.extent.height = tex_height;
15738 image_create_info.extent.depth = 1;
15739 image_create_info.mipLevels = 1;
15740 image_create_info.arrayLayers = 1;
15741 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15742 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15743 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15744 image_create_info.flags = 0;
15745
15746 // Introduce error by sending down a bogus width extent
15747 image_create_info.extent.width = 0;
15748 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15749
15750 m_errorMonitor->VerifyFound();
15751}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015752#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015753
Tobin Ehliscde08892015-09-22 10:11:37 -060015754#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015755TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15756 TEST_DESCRIPTION("Create a render pass with an attachment description "
15757 "format set to VK_FORMAT_UNDEFINED");
15758
15759 ASSERT_NO_FATAL_FAILURE(InitState());
15760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015763
15764 VkAttachmentReference color_attach = {};
15765 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15766 color_attach.attachment = 0;
15767 VkSubpassDescription subpass = {};
15768 subpass.colorAttachmentCount = 1;
15769 subpass.pColorAttachments = &color_attach;
15770
15771 VkRenderPassCreateInfo rpci = {};
15772 rpci.subpassCount = 1;
15773 rpci.pSubpasses = &subpass;
15774 rpci.attachmentCount = 1;
15775 VkAttachmentDescription attach_desc = {};
15776 attach_desc.format = VK_FORMAT_UNDEFINED;
15777 rpci.pAttachments = &attach_desc;
15778 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15779 VkRenderPass rp;
15780 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15781
15782 m_errorMonitor->VerifyFound();
15783
15784 if (result == VK_SUCCESS) {
15785 vkDestroyRenderPass(m_device->device(), rp, NULL);
15786 }
15787}
15788
Karl Schultz6addd812016-02-02 17:17:23 -070015789TEST_F(VkLayerTest, InvalidImageView) {
15790 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015793
Tobin Ehliscde08892015-09-22 10:11:37 -060015794 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015795
Mike Stroyana3082432015-09-25 13:39:21 -060015796 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015797 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015798
Karl Schultz6addd812016-02-02 17:17:23 -070015799 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15800 const int32_t tex_width = 32;
15801 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015802
15803 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015804 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15805 image_create_info.pNext = NULL;
15806 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15807 image_create_info.format = tex_format;
15808 image_create_info.extent.width = tex_width;
15809 image_create_info.extent.height = tex_height;
15810 image_create_info.extent.depth = 1;
15811 image_create_info.mipLevels = 1;
15812 image_create_info.arrayLayers = 1;
15813 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15814 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15815 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15816 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015817
Chia-I Wuf7458c52015-10-26 21:10:41 +080015818 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015819 ASSERT_VK_SUCCESS(err);
15820
15821 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015822 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15823 image_view_create_info.image = image;
15824 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15825 image_view_create_info.format = tex_format;
15826 image_view_create_info.subresourceRange.layerCount = 1;
15827 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15828 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015829 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015830
15831 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015832 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015833
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015835 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015836}
Mike Stroyana3082432015-09-25 13:39:21 -060015837
Mark Youngd339ba32016-05-30 13:28:35 -060015838TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15839 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15841 " used with no memory bound. Memory should be bound by calling vkBindImageMemory() and ");
Mark Youngd339ba32016-05-30 13:28:35 -060015842
15843 ASSERT_NO_FATAL_FAILURE(InitState());
15844
15845 // Create an image and try to create a view with no memory backing the image
15846 VkImage image;
15847
15848 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15849 const int32_t tex_width = 32;
15850 const int32_t tex_height = 32;
15851
15852 VkImageCreateInfo image_create_info = {};
15853 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15854 image_create_info.pNext = NULL;
15855 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15856 image_create_info.format = tex_format;
15857 image_create_info.extent.width = tex_width;
15858 image_create_info.extent.height = tex_height;
15859 image_create_info.extent.depth = 1;
15860 image_create_info.mipLevels = 1;
15861 image_create_info.arrayLayers = 1;
15862 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15863 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15864 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15865 image_create_info.flags = 0;
15866
15867 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15868 ASSERT_VK_SUCCESS(err);
15869
15870 VkImageViewCreateInfo image_view_create_info = {};
15871 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15872 image_view_create_info.image = image;
15873 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15874 image_view_create_info.format = tex_format;
15875 image_view_create_info.subresourceRange.layerCount = 1;
15876 image_view_create_info.subresourceRange.baseMipLevel = 0;
15877 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015878 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015879
15880 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015881 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015882
15883 m_errorMonitor->VerifyFound();
15884 vkDestroyImage(m_device->device(), image, NULL);
15885 // If last error is success, it still created the view, so delete it.
15886 if (err == VK_SUCCESS) {
15887 vkDestroyImageView(m_device->device(), view, NULL);
15888 }
Mark Youngd339ba32016-05-30 13:28:35 -060015889}
15890
Karl Schultz6addd812016-02-02 17:17:23 -070015891TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015892 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
15893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
15894 "formats must have ONLY the "
15895 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015896
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015897 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015898
Karl Schultz6addd812016-02-02 17:17:23 -070015899 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015900 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015901 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015902 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015903
15904 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015905 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015906 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015907 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15908 image_view_create_info.format = tex_format;
15909 image_view_create_info.subresourceRange.baseMipLevel = 0;
15910 image_view_create_info.subresourceRange.levelCount = 1;
15911 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015912 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015913
15914 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015915 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015916
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015917 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015918}
15919
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015920TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015921 VkResult err;
15922 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15925 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015926
Mike Stroyana3082432015-09-25 13:39:21 -060015927 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015928
15929 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015930 VkImage srcImage;
15931 VkImage dstImage;
15932 VkDeviceMemory srcMem;
15933 VkDeviceMemory destMem;
15934 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015935
15936 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015937 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15938 image_create_info.pNext = NULL;
15939 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15940 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15941 image_create_info.extent.width = 32;
15942 image_create_info.extent.height = 32;
15943 image_create_info.extent.depth = 1;
15944 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015945 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015946 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15947 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15948 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15949 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015950
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015951 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015952 ASSERT_VK_SUCCESS(err);
15953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015954 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015955 ASSERT_VK_SUCCESS(err);
15956
15957 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015958 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015959 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15960 memAlloc.pNext = NULL;
15961 memAlloc.allocationSize = 0;
15962 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015963
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015964 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015965 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015966 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015967 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015968 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015969 ASSERT_VK_SUCCESS(err);
15970
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015971 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015972 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015973 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015974 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015975 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015976 ASSERT_VK_SUCCESS(err);
15977
15978 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15979 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015980 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015981 ASSERT_VK_SUCCESS(err);
15982
15983 BeginCommandBuffer();
15984 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015985 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015986 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015987 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015988 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015989 copyRegion.srcOffset.x = 0;
15990 copyRegion.srcOffset.y = 0;
15991 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015992 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015993 copyRegion.dstSubresource.mipLevel = 0;
15994 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015995 // Introduce failure by forcing the dst layerCount to differ from src
15996 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015997 copyRegion.dstOffset.x = 0;
15998 copyRegion.dstOffset.y = 0;
15999 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016000 copyRegion.extent.width = 1;
16001 copyRegion.extent.height = 1;
16002 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016003 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016004 EndCommandBuffer();
16005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016006 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016007
Chia-I Wuf7458c52015-10-26 21:10:41 +080016008 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016009 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016010 vkFreeMemory(m_device->device(), srcMem, NULL);
16011 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016012}
16013
Tony Barbourd6673642016-05-05 14:46:39 -060016014TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
16015
16016 TEST_DESCRIPTION("Creating images with unsuported formats ");
16017
16018 ASSERT_NO_FATAL_FAILURE(InitState());
16019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16020 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016021 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 -060016022 VK_IMAGE_TILING_OPTIMAL, 0);
16023 ASSERT_TRUE(image.initialized());
16024
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016025 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
16026 VkImageCreateInfo image_create_info;
16027 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16028 image_create_info.pNext = NULL;
16029 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16030 image_create_info.format = VK_FORMAT_UNDEFINED;
16031 image_create_info.extent.width = 32;
16032 image_create_info.extent.height = 32;
16033 image_create_info.extent.depth = 1;
16034 image_create_info.mipLevels = 1;
16035 image_create_info.arrayLayers = 1;
16036 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16037 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16038 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16039 image_create_info.flags = 0;
16040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16042 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016043
16044 VkImage localImage;
16045 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
16046 m_errorMonitor->VerifyFound();
16047
Tony Barbourd6673642016-05-05 14:46:39 -060016048 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016049 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060016050 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16051 VkFormat format = static_cast<VkFormat>(f);
16052 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016053 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016054 unsupported = format;
16055 break;
16056 }
16057 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016058
Tony Barbourd6673642016-05-05 14:46:39 -060016059 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016060 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016062
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016063 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016064 m_errorMonitor->VerifyFound();
16065 }
16066}
16067
16068TEST_F(VkLayerTest, ImageLayerViewTests) {
16069 VkResult ret;
16070 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16071
16072 ASSERT_NO_FATAL_FAILURE(InitState());
16073
16074 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016075 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 -060016076 VK_IMAGE_TILING_OPTIMAL, 0);
16077 ASSERT_TRUE(image.initialized());
16078
16079 VkImageView imgView;
16080 VkImageViewCreateInfo imgViewInfo = {};
16081 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16082 imgViewInfo.image = image.handle();
16083 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16084 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16085 imgViewInfo.subresourceRange.layerCount = 1;
16086 imgViewInfo.subresourceRange.baseMipLevel = 0;
16087 imgViewInfo.subresourceRange.levelCount = 1;
16088 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060016091 // View can't have baseMipLevel >= image's mipLevels - Expect
16092 // VIEW_CREATE_ERROR
16093 imgViewInfo.subresourceRange.baseMipLevel = 1;
16094 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16095 m_errorMonitor->VerifyFound();
16096 imgViewInfo.subresourceRange.baseMipLevel = 0;
16097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060016099 // View can't have baseArrayLayer >= image's arraySize - Expect
16100 // VIEW_CREATE_ERROR
16101 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16102 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16103 m_errorMonitor->VerifyFound();
16104 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16107 "pCreateInfo->subresourceRange."
16108 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016109 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16110 imgViewInfo.subresourceRange.levelCount = 0;
16111 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16112 m_errorMonitor->VerifyFound();
16113 imgViewInfo.subresourceRange.levelCount = 1;
16114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16116 "pCreateInfo->subresourceRange."
16117 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016118 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16119 imgViewInfo.subresourceRange.layerCount = 0;
16120 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16121 m_errorMonitor->VerifyFound();
16122 imgViewInfo.subresourceRange.layerCount = 1;
16123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060016125 // Can't use depth format for view into color image - Expect INVALID_FORMAT
16126 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
16127 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16128 m_errorMonitor->VerifyFound();
16129 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
16132 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16133 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016134 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16135 // VIEW_CREATE_ERROR
16136 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16137 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16138 m_errorMonitor->VerifyFound();
16139 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
16142 "differing formats but they must be "
16143 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060016144 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16145 // VIEW_CREATE_ERROR
16146 VkImageCreateInfo mutImgInfo = image.create_info();
16147 VkImage mutImage;
16148 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016149 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016150 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16151 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16152 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16153 ASSERT_VK_SUCCESS(ret);
16154 imgViewInfo.image = mutImage;
16155 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16156 m_errorMonitor->VerifyFound();
16157 imgViewInfo.image = image.handle();
16158 vkDestroyImage(m_device->handle(), mutImage, NULL);
16159}
16160
16161TEST_F(VkLayerTest, MiscImageLayerTests) {
16162
16163 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16164
16165 ASSERT_NO_FATAL_FAILURE(InitState());
16166
16167 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016168 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 -060016169 VK_IMAGE_TILING_OPTIMAL, 0);
16170 ASSERT_TRUE(image.initialized());
16171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060016173 vk_testing::Buffer buffer;
16174 VkMemoryPropertyFlags reqs = 0;
16175 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
16176 VkBufferImageCopy region = {};
16177 region.bufferRowLength = 128;
16178 region.bufferImageHeight = 128;
16179 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16180 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16181 region.imageSubresource.layerCount = 0;
16182 region.imageExtent.height = 4;
16183 region.imageExtent.width = 4;
16184 region.imageExtent.depth = 1;
16185 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016186 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16187 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016188 m_errorMonitor->VerifyFound();
16189 region.imageSubresource.layerCount = 1;
16190
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016191 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16192 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
16193 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
16195 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16196 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016197 m_errorMonitor->VerifyFound();
16198
16199 // BufferOffset must be a multiple of 4
16200 // Introduce failure by setting bufferOffset to a value not divisible by 4
16201 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
16203 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16204 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016205 m_errorMonitor->VerifyFound();
16206
16207 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16208 region.bufferOffset = 0;
16209 region.imageExtent.height = 128;
16210 region.imageExtent.width = 128;
16211 // Introduce failure by setting bufferRowLength > 0 but less than width
16212 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16214 "must be zero or greater-than-or-equal-to imageExtent.width");
16215 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16216 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016217 m_errorMonitor->VerifyFound();
16218
16219 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16220 region.bufferRowLength = 128;
16221 // Introduce failure by setting bufferRowHeight > 0 but less than height
16222 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16224 "must be zero or greater-than-or-equal-to imageExtent.height");
16225 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16226 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016227 m_errorMonitor->VerifyFound();
16228
16229 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
16231 "specify only COLOR or DEPTH or "
16232 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060016233 // Expect MISMATCHED_IMAGE_ASPECT
16234 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016235 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16236 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016237 m_errorMonitor->VerifyFound();
16238 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16241 "If the format of srcImage is a depth, stencil, depth stencil or "
16242 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016243 // Expect INVALID_FILTER
16244 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016245 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 -060016246 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016247 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 -060016248 VkImageBlit blitRegion = {};
16249 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16250 blitRegion.srcSubresource.baseArrayLayer = 0;
16251 blitRegion.srcSubresource.layerCount = 1;
16252 blitRegion.srcSubresource.mipLevel = 0;
16253 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16254 blitRegion.dstSubresource.baseArrayLayer = 0;
16255 blitRegion.dstSubresource.layerCount = 1;
16256 blitRegion.dstSubresource.mipLevel = 0;
16257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016258 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16259 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016260 m_errorMonitor->VerifyFound();
16261
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016262 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16264 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16265 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016266 m_errorMonitor->VerifyFound();
16267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016269 VkImageMemoryBarrier img_barrier;
16270 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16271 img_barrier.pNext = NULL;
16272 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16273 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16274 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16275 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16276 img_barrier.image = image.handle();
16277 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16278 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16279 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16280 img_barrier.subresourceRange.baseArrayLayer = 0;
16281 img_barrier.subresourceRange.baseMipLevel = 0;
16282 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16283 img_barrier.subresourceRange.layerCount = 0;
16284 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016285 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16286 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016287 m_errorMonitor->VerifyFound();
16288 img_barrier.subresourceRange.layerCount = 1;
16289}
16290
16291TEST_F(VkLayerTest, ImageFormatLimits) {
16292
16293 TEST_DESCRIPTION("Exceed the limits of image format ");
16294
Cody Northropc31a84f2016-08-22 10:41:47 -060016295 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016297 VkImageCreateInfo image_create_info = {};
16298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16299 image_create_info.pNext = NULL;
16300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16301 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16302 image_create_info.extent.width = 32;
16303 image_create_info.extent.height = 32;
16304 image_create_info.extent.depth = 1;
16305 image_create_info.mipLevels = 1;
16306 image_create_info.arrayLayers = 1;
16307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16308 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16309 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16310 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16311 image_create_info.flags = 0;
16312
16313 VkImage nullImg;
16314 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016315 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16316 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016317 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16318 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16319 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16320 m_errorMonitor->VerifyFound();
16321 image_create_info.extent.depth = 1;
16322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016324 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16325 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16326 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16327 m_errorMonitor->VerifyFound();
16328 image_create_info.mipLevels = 1;
16329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016331 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16332 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16333 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16334 m_errorMonitor->VerifyFound();
16335 image_create_info.arrayLayers = 1;
16336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016338 int samples = imgFmtProps.sampleCounts >> 1;
16339 image_create_info.samples = (VkSampleCountFlagBits)samples;
16340 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16341 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16342 m_errorMonitor->VerifyFound();
16343 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16346 "VK_IMAGE_LAYOUT_UNDEFINED or "
16347 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016348 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16349 // Expect INVALID_LAYOUT
16350 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16351 m_errorMonitor->VerifyFound();
16352 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16353}
16354
Karl Schultz6addd812016-02-02 17:17:23 -070016355TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016356 VkResult err;
16357 bool pass;
16358
16359 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16361 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016362
16363 ASSERT_NO_FATAL_FAILURE(InitState());
16364
16365 // Create two images of different types and try to copy between them
16366 VkImage srcImage;
16367 VkImage dstImage;
16368 VkDeviceMemory srcMem;
16369 VkDeviceMemory destMem;
16370 VkMemoryRequirements memReqs;
16371
16372 VkImageCreateInfo image_create_info = {};
16373 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16374 image_create_info.pNext = NULL;
16375 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16376 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16377 image_create_info.extent.width = 32;
16378 image_create_info.extent.height = 32;
16379 image_create_info.extent.depth = 1;
16380 image_create_info.mipLevels = 1;
16381 image_create_info.arrayLayers = 1;
16382 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16383 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16384 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16385 image_create_info.flags = 0;
16386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016387 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016388 ASSERT_VK_SUCCESS(err);
16389
16390 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16391 // Introduce failure by creating second image with a different-sized format.
16392 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016394 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016395 ASSERT_VK_SUCCESS(err);
16396
16397 // Allocate memory
16398 VkMemoryAllocateInfo memAlloc = {};
16399 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16400 memAlloc.pNext = NULL;
16401 memAlloc.allocationSize = 0;
16402 memAlloc.memoryTypeIndex = 0;
16403
16404 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16405 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016406 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016407 ASSERT_TRUE(pass);
16408 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16409 ASSERT_VK_SUCCESS(err);
16410
16411 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16412 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016413 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016414 ASSERT_TRUE(pass);
16415 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16416 ASSERT_VK_SUCCESS(err);
16417
16418 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16419 ASSERT_VK_SUCCESS(err);
16420 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16421 ASSERT_VK_SUCCESS(err);
16422
16423 BeginCommandBuffer();
16424 VkImageCopy copyRegion;
16425 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16426 copyRegion.srcSubresource.mipLevel = 0;
16427 copyRegion.srcSubresource.baseArrayLayer = 0;
16428 copyRegion.srcSubresource.layerCount = 0;
16429 copyRegion.srcOffset.x = 0;
16430 copyRegion.srcOffset.y = 0;
16431 copyRegion.srcOffset.z = 0;
16432 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16433 copyRegion.dstSubresource.mipLevel = 0;
16434 copyRegion.dstSubresource.baseArrayLayer = 0;
16435 copyRegion.dstSubresource.layerCount = 0;
16436 copyRegion.dstOffset.x = 0;
16437 copyRegion.dstOffset.y = 0;
16438 copyRegion.dstOffset.z = 0;
16439 copyRegion.extent.width = 1;
16440 copyRegion.extent.height = 1;
16441 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016442 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016443 EndCommandBuffer();
16444
16445 m_errorMonitor->VerifyFound();
16446
16447 vkDestroyImage(m_device->device(), srcImage, NULL);
16448 vkDestroyImage(m_device->device(), dstImage, NULL);
16449 vkFreeMemory(m_device->device(), srcMem, NULL);
16450 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016451}
16452
Karl Schultz6addd812016-02-02 17:17:23 -070016453TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16454 VkResult err;
16455 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016456
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016457 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16459 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016460
Mike Stroyana3082432015-09-25 13:39:21 -060016461 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016462
16463 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016464 VkImage srcImage;
16465 VkImage dstImage;
16466 VkDeviceMemory srcMem;
16467 VkDeviceMemory destMem;
16468 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016469
16470 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016471 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16472 image_create_info.pNext = NULL;
16473 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16474 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16475 image_create_info.extent.width = 32;
16476 image_create_info.extent.height = 32;
16477 image_create_info.extent.depth = 1;
16478 image_create_info.mipLevels = 1;
16479 image_create_info.arrayLayers = 1;
16480 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16481 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16482 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16483 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016484
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016485 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016486 ASSERT_VK_SUCCESS(err);
16487
Karl Schultzbdb75952016-04-19 11:36:49 -060016488 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16489
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016490 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016491 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016492 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16493 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016495 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016496 ASSERT_VK_SUCCESS(err);
16497
16498 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016499 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016500 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16501 memAlloc.pNext = NULL;
16502 memAlloc.allocationSize = 0;
16503 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016504
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016505 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016506 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016507 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016508 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016509 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016510 ASSERT_VK_SUCCESS(err);
16511
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016512 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016513 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016514 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016515 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016516 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016517 ASSERT_VK_SUCCESS(err);
16518
16519 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16520 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016521 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016522 ASSERT_VK_SUCCESS(err);
16523
16524 BeginCommandBuffer();
16525 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016526 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016527 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016528 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016529 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016530 copyRegion.srcOffset.x = 0;
16531 copyRegion.srcOffset.y = 0;
16532 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016533 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016534 copyRegion.dstSubresource.mipLevel = 0;
16535 copyRegion.dstSubresource.baseArrayLayer = 0;
16536 copyRegion.dstSubresource.layerCount = 0;
16537 copyRegion.dstOffset.x = 0;
16538 copyRegion.dstOffset.y = 0;
16539 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016540 copyRegion.extent.width = 1;
16541 copyRegion.extent.height = 1;
16542 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016543 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016544 EndCommandBuffer();
16545
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016546 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016547
Chia-I Wuf7458c52015-10-26 21:10:41 +080016548 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016549 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016550 vkFreeMemory(m_device->device(), srcMem, NULL);
16551 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016552}
16553
Karl Schultz6addd812016-02-02 17:17:23 -070016554TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16555 VkResult err;
16556 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16559 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016560
Mike Stroyana3082432015-09-25 13:39:21 -060016561 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016562
16563 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016564 VkImage srcImage;
16565 VkImage dstImage;
16566 VkDeviceMemory srcMem;
16567 VkDeviceMemory destMem;
16568 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016569
16570 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016571 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16572 image_create_info.pNext = NULL;
16573 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16574 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16575 image_create_info.extent.width = 32;
16576 image_create_info.extent.height = 1;
16577 image_create_info.extent.depth = 1;
16578 image_create_info.mipLevels = 1;
16579 image_create_info.arrayLayers = 1;
16580 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16581 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16582 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16583 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016584
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016585 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016586 ASSERT_VK_SUCCESS(err);
16587
Karl Schultz6addd812016-02-02 17:17:23 -070016588 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016590 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016591 ASSERT_VK_SUCCESS(err);
16592
16593 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016594 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016595 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16596 memAlloc.pNext = NULL;
16597 memAlloc.allocationSize = 0;
16598 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016599
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016600 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016601 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016602 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016603 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016604 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016605 ASSERT_VK_SUCCESS(err);
16606
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016607 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016608 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016609 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016610 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016611 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016612 ASSERT_VK_SUCCESS(err);
16613
16614 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16615 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016616 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016617 ASSERT_VK_SUCCESS(err);
16618
16619 BeginCommandBuffer();
16620 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016621 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16622 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016623 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016624 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016625 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016626 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016627 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016628 resolveRegion.srcOffset.x = 0;
16629 resolveRegion.srcOffset.y = 0;
16630 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016631 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016632 resolveRegion.dstSubresource.mipLevel = 0;
16633 resolveRegion.dstSubresource.baseArrayLayer = 0;
16634 resolveRegion.dstSubresource.layerCount = 0;
16635 resolveRegion.dstOffset.x = 0;
16636 resolveRegion.dstOffset.y = 0;
16637 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016638 resolveRegion.extent.width = 1;
16639 resolveRegion.extent.height = 1;
16640 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016641 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016642 EndCommandBuffer();
16643
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016644 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016645
Chia-I Wuf7458c52015-10-26 21:10:41 +080016646 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016647 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016648 vkFreeMemory(m_device->device(), srcMem, NULL);
16649 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016650}
16651
Karl Schultz6addd812016-02-02 17:17:23 -070016652TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16653 VkResult err;
16654 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16657 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016658
Mike Stroyana3082432015-09-25 13:39:21 -060016659 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016660
Chris Forbesa7530692016-05-08 12:35:39 +120016661 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016662 VkImage srcImage;
16663 VkImage dstImage;
16664 VkDeviceMemory srcMem;
16665 VkDeviceMemory destMem;
16666 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016667
16668 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016669 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16670 image_create_info.pNext = NULL;
16671 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16672 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16673 image_create_info.extent.width = 32;
16674 image_create_info.extent.height = 1;
16675 image_create_info.extent.depth = 1;
16676 image_create_info.mipLevels = 1;
16677 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016678 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016679 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16680 // Note: Some implementations expect color attachment usage for any
16681 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016682 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016683 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016685 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016686 ASSERT_VK_SUCCESS(err);
16687
Karl Schultz6addd812016-02-02 17:17:23 -070016688 // Note: Some implementations expect color attachment usage for any
16689 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016692 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016693 ASSERT_VK_SUCCESS(err);
16694
16695 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016696 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016697 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16698 memAlloc.pNext = NULL;
16699 memAlloc.allocationSize = 0;
16700 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016701
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016702 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016703 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016704 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016705 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016706 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016707 ASSERT_VK_SUCCESS(err);
16708
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016709 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016710 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016711 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016712 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016713 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016714 ASSERT_VK_SUCCESS(err);
16715
16716 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16717 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016718 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016719 ASSERT_VK_SUCCESS(err);
16720
16721 BeginCommandBuffer();
16722 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016723 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16724 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016725 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016726 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016727 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016728 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016729 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016730 resolveRegion.srcOffset.x = 0;
16731 resolveRegion.srcOffset.y = 0;
16732 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016733 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016734 resolveRegion.dstSubresource.mipLevel = 0;
16735 resolveRegion.dstSubresource.baseArrayLayer = 0;
16736 resolveRegion.dstSubresource.layerCount = 0;
16737 resolveRegion.dstOffset.x = 0;
16738 resolveRegion.dstOffset.y = 0;
16739 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016740 resolveRegion.extent.width = 1;
16741 resolveRegion.extent.height = 1;
16742 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016743 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016744 EndCommandBuffer();
16745
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016746 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016747
Chia-I Wuf7458c52015-10-26 21:10:41 +080016748 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016749 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016750 vkFreeMemory(m_device->device(), srcMem, NULL);
16751 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016752}
16753
Karl Schultz6addd812016-02-02 17:17:23 -070016754TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16755 VkResult err;
16756 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16759 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016760
Mike Stroyana3082432015-09-25 13:39:21 -060016761 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016762
16763 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016764 VkImage srcImage;
16765 VkImage dstImage;
16766 VkDeviceMemory srcMem;
16767 VkDeviceMemory destMem;
16768 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016769
16770 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016771 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16772 image_create_info.pNext = NULL;
16773 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16774 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16775 image_create_info.extent.width = 32;
16776 image_create_info.extent.height = 1;
16777 image_create_info.extent.depth = 1;
16778 image_create_info.mipLevels = 1;
16779 image_create_info.arrayLayers = 1;
16780 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16781 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16782 // Note: Some implementations expect color attachment usage for any
16783 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016784 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016785 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016787 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016788 ASSERT_VK_SUCCESS(err);
16789
Karl Schultz6addd812016-02-02 17:17:23 -070016790 // Set format to something other than source image
16791 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16792 // Note: Some implementations expect color attachment usage for any
16793 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016794 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016795 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016797 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016798 ASSERT_VK_SUCCESS(err);
16799
16800 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016801 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016802 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16803 memAlloc.pNext = NULL;
16804 memAlloc.allocationSize = 0;
16805 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016806
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016807 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016808 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016809 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016810 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016811 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016812 ASSERT_VK_SUCCESS(err);
16813
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016814 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016815 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016816 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016817 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016818 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016819 ASSERT_VK_SUCCESS(err);
16820
16821 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16822 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016823 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016824 ASSERT_VK_SUCCESS(err);
16825
16826 BeginCommandBuffer();
16827 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016828 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16829 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016830 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016831 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016832 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016833 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016834 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016835 resolveRegion.srcOffset.x = 0;
16836 resolveRegion.srcOffset.y = 0;
16837 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016838 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016839 resolveRegion.dstSubresource.mipLevel = 0;
16840 resolveRegion.dstSubresource.baseArrayLayer = 0;
16841 resolveRegion.dstSubresource.layerCount = 0;
16842 resolveRegion.dstOffset.x = 0;
16843 resolveRegion.dstOffset.y = 0;
16844 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016845 resolveRegion.extent.width = 1;
16846 resolveRegion.extent.height = 1;
16847 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016848 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016849 EndCommandBuffer();
16850
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016851 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016852
Chia-I Wuf7458c52015-10-26 21:10:41 +080016853 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016854 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016855 vkFreeMemory(m_device->device(), srcMem, NULL);
16856 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016857}
16858
Karl Schultz6addd812016-02-02 17:17:23 -070016859TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16860 VkResult err;
16861 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16864 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016865
Mike Stroyana3082432015-09-25 13:39:21 -060016866 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016867
16868 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016869 VkImage srcImage;
16870 VkImage dstImage;
16871 VkDeviceMemory srcMem;
16872 VkDeviceMemory destMem;
16873 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016874
16875 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016876 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16877 image_create_info.pNext = NULL;
16878 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16879 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16880 image_create_info.extent.width = 32;
16881 image_create_info.extent.height = 1;
16882 image_create_info.extent.depth = 1;
16883 image_create_info.mipLevels = 1;
16884 image_create_info.arrayLayers = 1;
16885 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16886 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16887 // Note: Some implementations expect color attachment usage for any
16888 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016889 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016890 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016892 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016893 ASSERT_VK_SUCCESS(err);
16894
Karl Schultz6addd812016-02-02 17:17:23 -070016895 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16896 // Note: Some implementations expect color attachment usage for any
16897 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016898 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016899 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016901 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016902 ASSERT_VK_SUCCESS(err);
16903
16904 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016905 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016906 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16907 memAlloc.pNext = NULL;
16908 memAlloc.allocationSize = 0;
16909 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016910
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016911 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016912 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016913 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016914 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016915 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016916 ASSERT_VK_SUCCESS(err);
16917
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016918 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016919 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016920 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016921 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016922 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016923 ASSERT_VK_SUCCESS(err);
16924
16925 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16926 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016927 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016928 ASSERT_VK_SUCCESS(err);
16929
16930 BeginCommandBuffer();
16931 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016932 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16933 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016934 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016935 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016936 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016937 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016938 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016939 resolveRegion.srcOffset.x = 0;
16940 resolveRegion.srcOffset.y = 0;
16941 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016942 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016943 resolveRegion.dstSubresource.mipLevel = 0;
16944 resolveRegion.dstSubresource.baseArrayLayer = 0;
16945 resolveRegion.dstSubresource.layerCount = 0;
16946 resolveRegion.dstOffset.x = 0;
16947 resolveRegion.dstOffset.y = 0;
16948 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016949 resolveRegion.extent.width = 1;
16950 resolveRegion.extent.height = 1;
16951 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016952 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016953 EndCommandBuffer();
16954
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016955 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016956
Chia-I Wuf7458c52015-10-26 21:10:41 +080016957 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016958 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016959 vkFreeMemory(m_device->device(), srcMem, NULL);
16960 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016961}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016962
Karl Schultz6addd812016-02-02 17:17:23 -070016963TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016964 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016965 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16966 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016967 // The image format check comes 2nd in validation so we trigger it first,
16968 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016969 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16972 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016973
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016974 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016975
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016976 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016977 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16978 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016979
16980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16982 ds_pool_ci.pNext = NULL;
16983 ds_pool_ci.maxSets = 1;
16984 ds_pool_ci.poolSizeCount = 1;
16985 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016986
16987 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016988 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016989 ASSERT_VK_SUCCESS(err);
16990
16991 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016992 dsl_binding.binding = 0;
16993 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16994 dsl_binding.descriptorCount = 1;
16995 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16996 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016997
16998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17000 ds_layout_ci.pNext = NULL;
17001 ds_layout_ci.bindingCount = 1;
17002 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017003 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017005 ASSERT_VK_SUCCESS(err);
17006
17007 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017008 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017010 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017011 alloc_info.descriptorPool = ds_pool;
17012 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017014 ASSERT_VK_SUCCESS(err);
17015
Karl Schultz6addd812016-02-02 17:17:23 -070017016 VkImage image_bad;
17017 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017018 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017019 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017020 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017021 const int32_t tex_width = 32;
17022 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017023
17024 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017025 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17026 image_create_info.pNext = NULL;
17027 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17028 image_create_info.format = tex_format_bad;
17029 image_create_info.extent.width = tex_width;
17030 image_create_info.extent.height = tex_height;
17031 image_create_info.extent.depth = 1;
17032 image_create_info.mipLevels = 1;
17033 image_create_info.arrayLayers = 1;
17034 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17035 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017036 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017037 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017039 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017040 ASSERT_VK_SUCCESS(err);
17041 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017042 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17043 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017044 ASSERT_VK_SUCCESS(err);
17045
17046 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017047 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17048 image_view_create_info.image = image_bad;
17049 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17050 image_view_create_info.format = tex_format_bad;
17051 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17052 image_view_create_info.subresourceRange.baseMipLevel = 0;
17053 image_view_create_info.subresourceRange.layerCount = 1;
17054 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017055 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017056
17057 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017058 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017059
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017060 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017061
Chia-I Wuf7458c52015-10-26 21:10:41 +080017062 vkDestroyImage(m_device->device(), image_bad, NULL);
17063 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017064 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17065 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017066}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017067
17068TEST_F(VkLayerTest, ClearImageErrors) {
17069 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
17070 "ClearDepthStencilImage with a color image.");
17071
17072 ASSERT_NO_FATAL_FAILURE(InitState());
17073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17074
17075 // Renderpass is started here so end it as Clear cmds can't be in renderpass
17076 BeginCommandBuffer();
17077 m_commandBuffer->EndRenderPass();
17078
17079 // Color image
17080 VkClearColorValue clear_color;
17081 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17082 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17083 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17084 const int32_t img_width = 32;
17085 const int32_t img_height = 32;
17086 VkImageCreateInfo image_create_info = {};
17087 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17088 image_create_info.pNext = NULL;
17089 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17090 image_create_info.format = color_format;
17091 image_create_info.extent.width = img_width;
17092 image_create_info.extent.height = img_height;
17093 image_create_info.extent.depth = 1;
17094 image_create_info.mipLevels = 1;
17095 image_create_info.arrayLayers = 1;
17096 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17097 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17098 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17099
17100 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017101 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017103 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017104
17105 // Depth/Stencil image
17106 VkClearDepthStencilValue clear_value = {0};
17107 reqs = 0; // don't need HOST_VISIBLE DS image
17108 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17109 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17110 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17111 ds_image_create_info.extent.width = 64;
17112 ds_image_create_info.extent.height = 64;
17113 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17114 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
17115
17116 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017117 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017119 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 -060017120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017123 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017124 &color_range);
17125
17126 m_errorMonitor->VerifyFound();
17127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
17129 "image created without "
17130 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017132 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017133 &color_range);
17134
17135 m_errorMonitor->VerifyFound();
17136
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017137 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17139 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017141 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
17142 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017143
17144 m_errorMonitor->VerifyFound();
17145}
Tobin Ehliscde08892015-09-22 10:11:37 -060017146#endif // IMAGE_TESTS
17147
Cody Northrop1242dfd2016-07-13 17:24:59 -060017148#if defined(ANDROID) && defined(VALIDATION_APK)
17149static bool initialized = false;
17150static bool active = false;
17151
17152// Convert Intents to argv
17153// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017154std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017155 std::vector<std::string> args;
17156 JavaVM &vm = *app.activity->vm;
17157 JNIEnv *p_env;
17158 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
17159 return args;
17160
17161 JNIEnv &env = *p_env;
17162 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017163 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017164 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017165 jmethodID get_string_extra_method =
17166 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017167 jvalue get_string_extra_args;
17168 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017169 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060017170
17171 std::string args_str;
17172 if (extra_str) {
17173 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
17174 args_str = extra_utf;
17175 env.ReleaseStringUTFChars(extra_str, extra_utf);
17176 env.DeleteLocalRef(extra_str);
17177 }
17178
17179 env.DeleteLocalRef(get_string_extra_args.l);
17180 env.DeleteLocalRef(intent);
17181 vm.DetachCurrentThread();
17182
17183 // split args_str
17184 std::stringstream ss(args_str);
17185 std::string arg;
17186 while (std::getline(ss, arg, ' ')) {
17187 if (!arg.empty())
17188 args.push_back(arg);
17189 }
17190
17191 return args;
17192}
17193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017194static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017196static void processCommand(struct android_app *app, int32_t cmd) {
17197 switch (cmd) {
17198 case APP_CMD_INIT_WINDOW: {
17199 if (app->window) {
17200 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017201 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017202 break;
17203 }
17204 case APP_CMD_GAINED_FOCUS: {
17205 active = true;
17206 break;
17207 }
17208 case APP_CMD_LOST_FOCUS: {
17209 active = false;
17210 break;
17211 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017212 }
17213}
17214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017215void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017216 app_dummy();
17217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017218 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060017219
17220 int vulkanSupport = InitVulkan();
17221 if (vulkanSupport == 0) {
17222 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
17223 return;
17224 }
17225
17226 app->onAppCmd = processCommand;
17227 app->onInputEvent = processInput;
17228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017229 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017230 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017231 struct android_poll_source *source;
17232 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017233 if (source) {
17234 source->process(app, source);
17235 }
17236
17237 if (app->destroyRequested != 0) {
17238 VkTestFramework::Finish();
17239 return;
17240 }
17241 }
17242
17243 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017244 // Use the following key to send arguments to gtest, i.e.
17245 // --es args "--gtest_filter=-VkLayerTest.foo"
17246 const char key[] = "args";
17247 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017249 std::string filter = "";
17250 if (args.size() > 0) {
17251 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17252 filter += args[0];
17253 } else {
17254 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17255 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017257 int argc = 2;
17258 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17259 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017261 // Route output to files until we can override the gtest output
17262 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17263 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017265 ::testing::InitGoogleTest(&argc, argv);
17266 VkTestFramework::InitArgs(&argc, argv);
17267 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017269 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017271 if (result != 0) {
17272 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17273 } else {
17274 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17275 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017277 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017279 fclose(stdout);
17280 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017282 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017284 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017285 }
17286 }
17287}
17288#endif
17289
Tony Barbour300a6082015-04-07 13:44:53 -060017290int main(int argc, char **argv) {
17291 int result;
17292
Cody Northrop8e54a402016-03-08 22:25:52 -070017293#ifdef ANDROID
17294 int vulkanSupport = InitVulkan();
17295 if (vulkanSupport == 0)
17296 return 1;
17297#endif
17298
Tony Barbour300a6082015-04-07 13:44:53 -060017299 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017300 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017301
17302 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17303
17304 result = RUN_ALL_TESTS();
17305
Tony Barbour6918cd52015-04-09 12:58:51 -060017306 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017307 return result;
17308}